Java - Variable - Declaration

Let's see how to use variables in JAVA in a simple tutorial.

Let's see an example of variable declarations in JAVA:

public class Main {


/**

* @param args

*/

public static void main(String[] args) {

byte aByte;

short aShort;

int anInt;

long  aLong;

float aFloat;

double aDouble;

char aChar;

boolean aBoolean;


aByte = 123;

aShort = 12345;

anInt = 1234567890;

aLong = 1000000000000000000L;

aFloat = 9.12345678912345678912345678945123F;

aDouble = 0.3333333333333333333333333333333333333333334;

aChar = 65;

aBoolean = true;


System.out.println("aByte = " + aByte);

System.out.println("aShort = " + aShort);

System.out.println("anInt = " + anInt);

System.out.println("aLong = " + aLong);

System.out.println("aFloat = " + aFloat);

System.out.println("aDouble = " + aDouble);

System.out.println("aChar = " + aChar);

System.out.println("aBoolean = " + aBoolean);


}


}
Result:
 
aByte = 123
aShort = 12345
anInt = 1234567890
aLong = 1000000000000000000
aFloat = 9.123457
aDouble = 0.3333333333333333
aChar = A
aBoolean = true
 
Note the aChar value: A.
Indeed, in the ASCII table 65 (in decimal) is equal to the A character.
Note also the L at the end of the long variable value.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.