web analytics

Java data types

Data type specifies the type of data a variable will hold e.g. whole number, number with fractions, text. Following are example of variables declaration with java data types:

int myNumber = 5; // an Integer or whole number
float myFloatintPointNumber = 86625.111554; // Floating point number
char myLetter = 'D'; // Single charater
boolean myBoolean = true; // a true/ false value
String myText = "Hello"; // String / text value

Types of Data types in java

There are two types of data types in java:

1. Primitive data types

Primitive data types are the basic types of data types. These are used as basic building blocks for data manipulation. Following table shows the primitive data types and their size in java:

Data Type Size
boolean 1 bit
char 2 byte
byte 1 byte
short 2 byte
int 4 byte
long 8 byte
float 4 byte
double 8 byte

2. Non primitive data types

Non primitive data types are complex data types. Variables of non-primitive datatypes are composed of primitive data types. Classes, interfaces are arrays are examples of non-primitive data types.