We know java is Object Oriented language, but it built on top of basic variables (primitives) [ School Text explanation of variables :D ] , provides us with named storage that our programs can manipulate, Each variable in Java has a specific type. We need to declare variables before using in code. Below Example

data type variable = value
data type variable = value,  variable1 = value1 ... variableN = valueN

Here "data type" means int, short or something similar using in Java, also we can declare more than one variable of the specified type using comma

int x, y, z;         // Declares three ints, x, y, and z.
int x = 8, y = 9;  // Example of initialisation
byte A = 22;         // initialises a byte type variable A.
double phi = 3.14159; // declares and assigns a value of phi.
char b = 'm';        // the char variable b is initialised with value 'm'

Some of variables or primitives used in Java

  • byte : number, 1 byte
  • short : number, 2 bytes
  • int : number, 4 bytes
  • long : number, 8 bytes
  • float : float number, 4 bytes
  • double : float number, 8 bytes
  • char : a character, 2 bytes
  • boolean : true or false, 1 byte

In Java we need to declare variables which using in the code