Java Variables

Java Variables

Java Variables

Java Variables. Variable  is a place or space (memory) to store Data. Well unlike PHP  or Python, you need to declare the correct  type of Variable in JAVA that you want to store  inside the memory.

Any wrongly declare variable type will give you a “type missmatch ” error message.such as  unable to  convert current type  variable.

There are 8 type of Primitive Variable in JAVA , we will step into it one by one.

Refer the table below for the Type of Java Variables.

 

No Type Declaration Min Max Default
1 Byte byte -128 128 0
2 Short short -32,768 32,767 0
3 Integer int -2,147,483,648 2,147,483,647 0
4 Long long -2^63 2^63 -1 0
5 Float float 0.0f
6 Double double 0.0d
7 Boolean boolean False True False
8 Character char 0 65,535

Byte

byte byteVariable = 100;
System.out.println("Byte Value: " + byteVariable);

 

Short

short shortVariable = 9999;
System.out.println("Short Value: " + shortVariable);
		

 

Integer

int integerVariable = 999999;
System.out.println("Int Value: " + integerVariable);

 

Long

long longVariable = 100000000L;
System.out.println("Long Value: " + longVariable);

 

Float

float floatVariable = 99.9f;
System.out.println("Float Value: " + floatVariable);

 

Double

double doubleVariable = 99.99;
System.out.println("Double Value: " + doubleVariable);

 

Boolean

boolean booleanVariable = true;
System.out.println("Boolean Value: " + booleanVariable);


 

Character

char charVariable = 'z';
System.out.println("Char Value: " + charVariable);


Learn more at Oracle here
Check how to create a responsive Navabar here

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × three =