Java Basic Data Types

In this tutorial, we will discuss about the basic data types in java. First we look one more time about the Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables.

There are two data types available in Java:
Java Basic Data Types
Primitive Data Types:

There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a key word. Let us now look into detail about the eight primitive data types.
byte:

short:

int:

long:

float:

double:

boolean:

char:
Reference Data Types:
Literals:
A literal represents a value that stored into a variable directly in the program.
boolean result = false;
char gender = 'M';
short s = 10000;
int i = -1256;
In the preceding statements, the right hand side values are called literals because these values are being stored into the variables shown at the left hand side. As the data type of the variable changes, the type of the literal also changes. So we have different types of literals. These are as follows:

Data Type Default Value Default size
boolean false 1 bit
char '\u0000' 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte

Why char uses 2 byte in java and what is \u0000 ?
because java uses unicode system rather than ASCII code system. \u0000 is the lowest range of unicode system.To get detail about Unicode see below.



<<Previous <<   || Index ||   >>Next >>

Labels: