Java Data type

A data type in a programming language is a set of data with values having predefined characteristics.

There are two types of data available in Java Programming Language:
>> Primitive Data Types
>> Object or  Reference Data Types

>> Primitive Data Types
Primitive types are the most basic data types available within the Java language; these include boolean, byte, char, short, int, long, float and double. These types serve as the building blocks of data manipulation in Java. Such types serve only one purpose containing pure, simple values of a kind. Because these data types are defined into the Java type system by default, they come with a number of operations predefined. You can not define a new operation for such primitive types. In the Java type system, there are three further categories of primitives:

Numeric primitives: short, int, long, float and double. These primitive data types hold only numeric data. Operations associated with such data types are those of simple arithmetic (addition, subtraction, etc.) or of comparisons (is greater than, is equal to, etc.)

Textual primitives: byte and char. These primitive data types hold characters (that can be Unicode alphabets or even numbers). Operations associated with such types are those of textual manipulation (comparing two words, joining characters to make words, etc.). However, byte and char can also support arithmetic operations.

Boolean and null primitives: boolean and null.

All the primitive types have a fixed size. Thus, the primitive types are limited to a range of values. Such as, a smaller primitive type byte can contain less values than a bigger one long.
Category : Integer
Type : byte
Size : 8 bits
Min Value : -128
Max Value : 127
Precision : from +127 to -128
Example : byte b= 65;
Category : Integer
Type : char
Size : 16 bits
Min Value : 0
Max Value : 216-1
Precision : Unicode characters (All)
Example : char c = 'A';
Category : Integer
Type : short
Size : 16 bits
Min Value : -215
Max Value : 215-1
Precision : From +32,767 to -32,768
Example : short s = 65;
Category : Integer
Type : int
Size :  32 bits
Min Value : -231
Max Value : 231-1
Precision : From +2,147,483,647 to -2,147,483,648
Example : int i = 65;
Category : Integer
Type : long
Size :  64 bits
Min Value : -263
Max Value : 263-1
Precision : From +9,223,372,036,854,775,807 to -9,223,372,036,854,775,808
Example : long l = 65L;
Category : Floating point
Type : float
Size :  32 bits
Min Value : 2-149
Max Value : (2-2-23)·2127
Precision : From 3.402,823,5 E+38 to 1.4 E-45
Example : float f = 65f;
Category : Floating point
Type : double
Size : 64 bits
Min Value : 2-1074
Max Value : (2-2-52)·21023
Precision : From 1.797,693,134,862,315,7 E+308 to 4.9 E-324
Example : double d = 65.55;
Category : Other
Type : boolean
Size : 1 bit
Precision : false, true
Example : boolean b = true;
Category : Other
Type : void
What is Integer in Java?
An integer is a whole number no fractional number that can be positive, negative, or zero. 
Example of integers are: -3, 3, 10, 15, 99

What is byte data type in Java?
a group of binary digits or bits (usually eight) operated on as a unit.
a byte considered as a unit of memory size.
The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters.

What is char data type in Java?
The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' or 0 and a maximum value of '\uffff' or 65,535 inclusive.

What is short data type in Java?
The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.

What is int data type in Java?
By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1. Use the Integer class to use int data type as an unsigned integer.

What is long data type in Java? 
The long data type is a 64-bit two's complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. Use this data type when you need a range of values wider than those provided by int. 

What is float data type in Java? 
The float data type is a single-precision 32-bit IEEE 754 floating point. As with the recommendations for byte and short, use a float instead of double if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. 

What is double data type in Java?
The double data type is a double-precision 64-bit IEEE 754 floating point.  For decimal values, this data type is generally the default choice. This data type should never be used for precise values, such as currency.

What is boolean data type in Java?
The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true or false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.

What is void in Java?
Used at method declaration and definition to specify that the method does not return any type, the method returns void.

<<  < Previous Lesson < Java Tutorial > Next Lesson >  >>

Regularly visit this site to get new information about Java Programming Language. Today, it is a robust and most powerful programming language in the Universe.