Table of Contents
Data Types in Java
Data types refer to the different sizes and values that can be stored in the variable. Two types of data type are in Java programming:
- Primitive data types: The primitive data types consist of int, float, boolean, byte, short, long, char and double.
- Non-primitive data types: The non-primitive data types include arrays, interfaces and class etc.
Java Primitive Data Types
There are following primitive data types available in Java programming language.
- Byte data type
- Boolean data type
- Int data type
- Short data type
- Char data type
- Double data type
- Float data type
- Long data type
1. Byte Data Type
It is the first data type with least memory size allocation which can be used for numbers of small ranges.
- The memory size is allocated 1 byte.
- It can represent a total 256(28).
- Byte can represent from 0 to 127 on positive side (as zero is positive number per programming) and on the negative side it can represent the number -1 to 128.
- The default value for byte is zero (0).
- Example:- byte a1 = 10;
2. Boolean Data Type
The boolean data type is a one bit information. Only two possible values are of Boolean data type. Which are true and false.
- It has not something range of values of the variable.
- The values true or false are case-sensitive keywords.
- Example:- boolean a = false; boolean b=true;
3. Int Data Type
The int data type is a 32-bits signed type. Minimum value of int data type is – 2,147,483,648 and maximum value of int data type is 2,147,483,647 precision type.
- Its default value is 0.
- On the positive side 0 to 2,147,483,647 and on the negative side -1 to 2,147,483,647
- It can represent a total of 4,294,967,296
- Example:- int a = 100000;
- int b = -200000;
4. Short Data Type
The short data type is a 16-bit signed type. Its value-range lies between – 32,768 to 32,767. Minimum value of short is -32,768 and maximum value of short is 32,767.
- Its default value is 0.
- It can represent total 65536(216) numbers.
- Example:- short s = 10000;
5. Char Data Type
It has a single 16-bit Unicode character. Value-range of char data type lies between -127 to 128 .The char data type is used to store characters.
- It stores a single character such as a letter, number and punctuation mark or other symbol.
- Characters are a single letter enclosed in single quotes.
- Example:- char b = ‘A’; char a=’#’;
6. Double Data Type
double data type is a 64 bits signed type. Its value range is unlimited. The double data type is generally used for decimal (points) values just like float. The double data type does not use for precise values, such as currency.
- Its default value is 0.0d.
- Example:- double d1 = 122.39;
7. Float Data Type:-
The float data type has a single-precision 32-bits types and its value range is unlimited.
- Its default value is 0.0F.
- Example:- float f1 = 134.5f;
8. Long Data Type:-
It has a 64-bit two’s complement integer. Minimum value long data type is – 9,223,372,036,854,775,808 and maximum value of long data type is 9,223,372,036,854,775,807.
- Its default value is 0.
- Example:- long a = 100000L;
Non-Primitive Data Types:-
There are following non- primitive data types available in Java programming language.
1. Array: –
An array is the collection of homogeneous (or similar types) data type.
- An array is an object that holds a fixed number of values of homogeneous or similar data-type.
- The length of an array is assigned when the array is created and after creation, its length is fixed.
- Example:- int a[]=new int[6];
2. Class: –
Class is a “user defined data type” from which objects are created of class. In general, class declarations can include components. And it consists of data and methods in the form of a unit.
Modifiers: – A class can be public or default access.
Class name: – The name of class should begin with an initial capital letter.
Body: – The class body is enclosed by braces {}.
Example: –
public class car
{
Public:
char color;
double model;
Public void gear (); // behavior of a car
}
3. Interface: –
An interface is basically a kind of class. So an interface is a collection of “methods” without actual definitions and “variables”.
Thus it is the responsibility of the class that to define and implement the codes of these methods.
Example: –
interface item
{
Static final int code=101;
Static final string name =”fan”;
Void display ();
}
Add Your Heading Text Here
You May Like to Browers More


