Core Java SQL Oracle PHP Examples JSP JDBC MORE

Java Datatype


In Java, every variable and every expression has some Type.

Each And Every datatype Is clearly defined and every assignment should be checked by compiler For type compatibility.So, we can conclude that the Java language Is strongly typed language.

Java Is not considered as a pure Object Oriented Programming language because several book feature is not satisfied by java like.

Example: Operator Overloading Multiple Inheritance etc.

Byte

The byte data type have:

  1. Size : 1 Byte (8 bit)
  2. Max value : +127
  3. Min Value : -128
  4. Range is -128 to +127.
  5. The default value for byte is 0.

Example

class Byte {
public static void main(String[] args) {
byte a;
a = 124;
System.out.println(a);
}
}

Output : 124

Stream

1. Character Stream

2.Byte Stream

-If you handle data in term of stream either from the file are from are from the network

-File Support from and network support from are byte

Short

The Short is must rarely use data type in java.

The byte data type have:

  1. Size: 2 Byte (16 bit)
  2. Max value : +32767
  3. Min Value: 32768
  4. The range is -32768 to +32767.
  5. The default value for short is 0.

Example

class Short {
public static void main(String[] args) {
short a;
a = -250;
System.out.println(a);
}
}

Output : -250

Int

It is the most common data type in Java.

The byte data type have:

  1. Size: 4 Byte (32 bit)
  2. Max value : +2147483647
  3. Min Value: 2147483648
  4. Range is -231 to 231-1 or -2147483648 to +2147483647
  5. The default value for int is 0.

Example

class int {
public static void main(String[] args) {
int a = 500050;
System.out.println( a );
}
}

Output : 500050

long

Some time int data type range is may not sufficient for hold big value so on that case we should go for long type.

  1. Size : 8 Byte (64 bit)
  2. Max value : 263-1
  3. Min Value : -263
  4. Range is -263 to 263-1 The default value for long is 0.

Example

class long {
public static void main(String[] args) {
long a = 4356784L;
System.out.println(a);
}
}

Output : 4356784

float

Example

class float {
public static void main(String[] args) {
float a = 50.7f;
System.out.println(a);
}
}

Output : 50.7

double

Example

class double {
public static void main(String[] args) {
double a = 78.9;
System.out.println(a);
}
}

Output : 78.9