Data Types In Java


Java supports 8 primitive data types under four categories.

1. Integers         byte ------------ 8 bits     or      1 byte

Short------------ 16 bits or    2 bytes

Int -------------- 32 bits or 4 bytes

Long ------------ 64 bits or 8 bytes

2. Real numbers    float ------------- 32 bits or 4 bytes

Double ----------- 64 bits or 8 bytes

3. Character          char ------------------ 16 bits or    2 bytes

4. Boolean values   Boolean ------------- 1 bit (true /false)

Here true/false are known as Tuples.

Note:  Tuples are predefined constants which represent only one value.



Consider the following program

Class Demo B


Byte b;

Short s;

Int i;

Long l;

Float f;

Double d;

Char c;

Boolean flag;

Public static void main (string arg[])


Demo B     d = new Demo B ();

System. Out. Prinln (“b-----”+d. b);

System. Out. Prinln (“s-----”+d. s);

System. Out. Prinln (“i-----”+d. i);

System. Out. Prinln (“l-----”+d. l);

System. Out. Prinln (“f-----”+d. f);

System. Out. Prinln (“d-----”+d. d);

System. Out. Prinln (“c-----”+d. c);

System. Out. Prinln (“Flag-----”+d.flag);



When the compile and execute the program we get the following output.


s----- 0


f----- 0.0

d ---- 0.0


Flag --- false

These values are the default values.

Note:  after loading all the non-static elements into the object, then the JVM initializes all the uninitialized variables with their default values. Default values of variables of primitive data types are shown in the output of the above program.

· The default value of char is ‘ ‘ (space)

· Character has to be represented with quotation marks

· Almost we can assign only one character to a char variable



Char c =‘s’, x= '6’ etc...


Data Types Java Homework Help

Get professional help with Java programming assignment, Matlab programming and java homework solutions from USA online java experts at affordable price