Primitive Data Types

The Java programming language requires you to declare all variables before using them.  You can declare the variables by specifying their names and data types.

For example, to declare a variable called “age” of numeric data type and the initial value of 1, you the syntax is:

int age=1;

Java supports not only int, but seven other primitive data types, defined by the programming language itself. These data types include boolean, byte, short, int, long, float, double, and char data types. Let’s understand each of these in a little more detail:

Byte is an 8-bit data type that requires little storage space, with a minimum value of -128 and a maximum value of 127. It provides four times more space than an int data type. Large arrays generally use a byte data type instead of int data type. Short is a 16-bit data type that has a minimum value of -32,768 and a maximum value of 32,767. When compared to an integer, this data type is twice as small and is also used to save space in an array. The default value of the Short data type is 0. Int is a 32 bit data type having a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647. Almost all programming languages use this data type to store numbers. Just like Short, its default value is also 0.

Continue reading Primitive Data Types