Home » Home » Data Types in Java

There are two data types available in Java:

  • Primitive Data Types
  • Reference/Object Data Types

a) Primitive Data Types :

There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a key word Let us now look into detail about the eight primitive data types.

Primitive Data Types:

Data TypeMemory SizeDefault ValueDeclarationRange
byte8 bits0byte a = 9;-128 to 127
short16 bits0short b = 89; -32768 to 32767
int 32 bits0int c = 24;-2147483648 to
2147483647
long64 bits0long d = 985465;-9223372036854775808 to
9223372036854775807
float32 bits0.0ffloat e = 87.36f;+/- 1.4023×10-45 to
3.4028×10+38
double64 bits0.0double f = 85.454;+/-4.9406×10-324 to
1.7977×10308
char 16 bits‘ u0000 ‘char g = ‘c’ ;0 to 65535
booleanJVM Dependentfalseboolean h = true ;

b) Reference Data Types:

  • Reference variables are created using defined constructors of the classes. They are used to access objects. These variable are declared to be of a specific type that cannot be changed For example, Employee, Puppy etc.
  • Class objects, and various type of array variables come unde reference data type.
  • Default value of any reference variable is null.
  • A reference variable can be used to refer to any object of the declared type or any compatible type.
  • Example: Animal animal = new Animal(“giraffe”);

Java Literals:

A literal is a source code representation of a fixed value. They are represented directly in the code without any computation.

Literals can be assigned to any primitive type variable.

For example:

byte a = 68;

char a = ‘A’

Escape Sequences :

Definition : A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler. The following table shows the Java escape sequences: Escape Sequences .

Related Posts

Leave a Reply

%d bloggers like this: