Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Integer Data Types

Integer data types are most common data types in Java programming. Integer data types represent whole numbers like 2, 345, -200 etc. Integer data types include whole numbers and it can be positive values, negative values and 0. Java has four integer data types as given below.


Byte

Byte is smallest integer data type Java supports. Range of byte data type is -128 to 127. Byte data type consumes 8 bits of memory.

Byte data type can be declared as follows.

byte <variable_name>;

Where variable_name is name of the identifier. You can also simultaneously declare and assign value to byte variable like given below.

byte b = 20;


Short

Next bigger integer type is short. Range of short variable is -32, 768 to 32,767. You can declare short variable as follows.

short <variable_name>;

Where variable_name is name of the identifier.

Short variables occupy 16 bits or two bytes of memory.


Int

Next bigger integer data type is int, which can hold values from -2,147,483,648 to 2,147,483,647.

You can declare int variable as follows.

int <variable_name>;

Where variable_name is name of the identifier.  Int data type occupies 32 bits or four bytes of memory.


Long

The biggest integer data type in Java is Long. Long data type is used to store very big numbers and it takes 64 bits of memory.

Long variables can be declared as given below.

long <variable_name>;
or
long l = <value>;
No votes yet
Share this
Anonymous's picture

iit should be better

iit should be better

Post new comment

7 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.