What it actually comes down to. Declaring a variable means that you create a variable object.

STEP:

  1. add a type to the variable

in this case we want to add up integers, so the type int will be our choice:

package Initialising;

public class declare {
	
	void start() { 
		int a; 
		int b;
	}

	public static void main(String[] args) {
		new declare().start();
	}
}

 

At this point:

we have declared variable and b.

=> NEXT STEP IS TO INITIALISE THE VARIABLES

 

 

 

EXTRA INFORMATIONN..

So, now we got 2 objects of type int. These variables got no value, so if you want to print the value it gives you an error:

Checking the code, eclipse gives you indeed an error message. You can check what is wrong if you click the error sign on the left (1). This will show the error (2).

declare variable java error

So, eclipse rightly states that the variable has no value yet.

(and you can’t print something that has no value, right?)

Therefore we have to give the variable a value

in java-terms this is called: initialising the variable.