How to Name and Describe a Variable in Java

This is how to name and describe a variable in java.

First here is the whole program code, a very simple one.

public class definevariable

{

public static void main(String[] args)

{

int i;

i = 27;

System.out.println(i);

}

}

First, the part that says:

public class definevariable

defines the name of he class.  The name definevariable should be the name that it is saved under plus ‘.java’.

Second, the part that says:

public static void main(String[] args)

tells you that you are creating a method.

Third, the part that says:

int i;

i = 27;

defines what kind of variable ‘i’ is, which in this case, is an integer(int).  The ‘i = 27′ puts the value 27 into i.

Finally the part that says:

System.out.println(i);

tells the computer to print the value of ‘i’.

There are other ways to define variables including long, byte, bit, float, double, and boolean.*

*I will explain these in another article.

comments powered by Disqus
Loading