Try it here
JAVA Data Type

Data types in Java


Primitive data types : JAVA

There are majorly two types of languages. First one is Statically typed language where each variable and expression type is already known at compile time.Once a variable is declared to be of a certain data type, it cannot hold values of other data types.Example: C,C++, Java. Other, Dynamically typed languages: These languages can receive different data types over the time. Ruby, Python

Java has two categories of data:

  • Primitive data (e.g., number, character)
  • Object data (programmer created types)

Primitive data are only single values; they have no special capabilities.
The eight primitive data types in Java are:

  • boolean, the type whose values are either true or false
  • char, the character type whose values are 16-bit Unicode characters
  • the arithmetic types:
    • the integral types:
      • byte
      • short
      • int
      • long
    • the floating-point types:
      • float
      • double

Values of class type are references. Strings are references to an instance of class String.

Primitive data types in Java
TypeDefaultSizeExample Literals
booleanfalse1 bittrue, false
byte08 bits(none)
charu000016 bits 'a', 'u0041', '101', ', \\'', ' ', 'ß'
short016 bits(none)
int032 bits-2, -1, 0, 1, 2
long064 bits-2L, -1L, 0L, 1L, 2L
float0.032 bits 1.23e100f, -1.23e-100f, .3f, 3.14F
double0.064 bits 1.23456e300d, -1.23456e-300d, 1e1d


Values of type boolean are not converted implicitly or explicitly (with casts) to any other type. But the programmer can easily write conversion code:

final int i = b?1:0;
final double d = b?1.0:0.0;
final boolean b = i>0?true:false;


The 16-bit Unicode character set underlies both the Java source program and char data type. So, not only are Java programs written in Unicode characters, but Java programs can manipulate Unicode data.


Range of numeric data types in Java
byte8 bits-128 .. 127
short16 bits-32,768 .. 32,767
int32 bits-2,147,483,648 .. 2,147,483,647
long64 bits-9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807
float32 bits 3.40282347 x 1038, 1.40239846 x 10-45
double64 bits 1.7976931348623157 x 10308, 4.9406564584124654 x 10-324

Writer profile pic

Uk01 on Jan 20, 2015 at 12:01 am

If you like and would like to contribute, you can write your article here or mail your article to . See your article appearing on the main page and help others to learn.

Post Comment

Comments( 0)


Forgot Password

Please enter your email address below and we will send you information to change your password.