Data Types in Java

  • Data type is used for declaring variable.
  • Data type tells about the size and value type which is stored in the variable.
  • Data types  hold different kind of information.

Types of Data Type



TypeSizeRange
byte1 byte-128 to 127
short2 byte-32768 to 32767
int4 byte-2147483648 to 2147483647
long8 byte-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

char

  • The char data type is a single 16-bit Unicode character.
  • It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

boolean

The boolean data type has only two possible values: true and false.

Classes

  • Class is reference data type in Java.
  • All the objects & methods are declared inside the class.
Syntax:

class Test
{
     Variable declaration;
     Method declaration:
}

Interfaces

  • Interface is also a kind of class.
  • An interface does not implement any code because it defines only abstract method and final variable.
Syntax:

interface Test
{
     variable declaration;
     method declaration;
}

Arrays

  • Array is collection of similar data type.
  • Array can be declared in any data type.
Syntax:
int a[];
char b[] = new char b[];