Basic Data Types

Basic Data Types


Posted in : Core Java Posted on : September 28, 2010 at 12:39 PM Comments : [ 0 ]

This section contains the details about data types in java

Basic Data Types

When variables declared, system reserved some space to store value .

In Java there are two data types :

1.Primitive Data types.

2.Refrence Data types.

Primitive Data Type

Java support 8 primitive data types, they are predefined and all of these have predefined keywords. Eight data types are as follows :

byte

  • Byte is a 8 bit data type
  • It's range is -128 to 127.
  • It's default value is zero.
  • It is the smallest java integer type. Byte is four times smaller than an int.
  • Example : byte x = 90, byte y =- 60.

short

  • Short is 16 bit signed type.
  • It's range is 32,768 to 32,767.
  • Default value is 0.
  • Short is 2 times smaller than an int.
  • Example :short s= 20000 , short r = -30000

int

  • Int is a 32-bit data type.
  • It's range is from 2,147,483,648 to 2,147,483,647.
  • For integral value int is generally used.
  • Default value is 0.
  • Example : int a = 200000, int b = -300000.

long

  • Long is 64 bit data type.
  • It's range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
  • Long is used where we need to store a wider range data than int.
  • It's default value is 0L.
  • Example : int a = 100000L, int b = -200000L.

double

  • Double is used ,when fractional precision calculation is required.
  • It is 64 bit double precision data type.
  • It's default value is Default value is 0.0d.
  • Example : double d = 123.4.

float

  • float is 32 bit single precision type.
  • It is used when fractional precision calculation is required.
  • Default value is 0.0f.
  • Example : float f1 = 234.5f.

Boolean

  • When we need to represent one bit of information, we use Boolean data type.
  • It takes two values true and false.
  • It is generally used where we need to track true/false conditions.
  • Default value is false.
  • Example : Boolean one = true.

char

  • char is 16 bit type and used to represent Unicode characters.
  • Range of char is 0 to 65,536.
  • Example . char letter ='A' .

Reference Data Types :

  • Reference data types or objects are created using class constructors. It's type can't be changed after declaration.
  • 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 : Mainclass mc = new Mainclass("Ankit") .
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics