Back to Top

Saturday 11 January 2014

JAVA: Data Types Conversion Chart

      In Java Programming Language, we must declare a variable name and type, before using it. The data type of a variable defines the the type of value it will contain. Java supports total 8 types of primitive data types. The name of this data types are all reserved as keywords.
Among which, 1) byte, 2) short, 3) int & 4) long can store integer values of different range.
5) float and 6) double can store floating numbers of different range.
7) boolean  can store only true/false. It is used as flag, to perform boolean operation.
8) char can store a single 16-bit Unicode character of range from '\u0000' (0) to '\uffff' (65,535).
Apart from these, Java also provides a String data type which is defined as a Class (java.lang.String). It can contains alpha numeric values.





byte

  • Type: Integer (8-bit signed two's complement integer).
  • Range:  from -128 [-2^(8-1)] to 127 [(2^(8-1))-1].
  • Memory: 1 byte
  • Default Value : 0
  • Example: byte b = 0;

short

  • Type: Integer (16-bit signed two's complement integer).
  • Range:  from -32768 [-2^(16-1)] to 32767 [(2^(16-1))-1].
  • Memory: 2 bytes
  • Default Value : 0
  • Example: short s  = 0;
int

  • Type: Integer (32-bit signed two's complement integer).
  • Range:  from -2147483648 [-2^(32-1)] to 2147483647 [(2^(32-1))-1].
  • Memory: 4 bytes
  • Default Value : 0
  • Example: int i = 0;

long

  • Type: Integer (64-bit signed two's complement integer).
  • Range:  from -9223372036854775808 [-2^(64-1)] to 9223372036854775807 [(2^(64-1))-1].
  • Memory: 8 bytes
  • Default Value : 0L
  • Example: long l = 0L;

float

  • Type: Float (Single precision 32-bit IEEE 754 floating point).
  • Range:  from 1.4E-45F to 3.4028235E+38F.
  • Memory: 4 bytes
  • Default Value : 0.0f
  • Example: float f = 0f;

double

  • Type: Float (Single precision 64-bit IEEE 754 floating point).
  • Range:  from 4.9E-324D to 1.7976931348623157E+308D.
  • Memory: 8 bytes
  • Default Value : 0.0d
  • Example: double d = 0d;

boolean

  • Type: boolean (boolean flag - true / false).
  • Range:  NA.
  • Memory: virtual machine dependent
  • Default Value : false
  • Example: boolean b = false;

char

  • Type: Character (a single 16-bit Unicode character).
  • Range:  from '\u0000' (0) to '\uffff' (65535).
  • Memory: 2 bytes
  • Default Value : '\u0000'
  • Example: char c = '\u0000';

String

  • Type: String Character (a class can store alpha numeric value).
  • Range:  NA
  • Memory: NA
  • Default Value : null
  • Example: String s = "Hello World";



Anijit Sarkar

156 Responses to “ JAVA: Data Types Conversion Chart ”

Post a Comment

Popular Posts

All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar