Updates
  • Starting New Weekday Batch for Full Stack Java Development on 15 September 2025 @ 02:00 PM to 04:00 PM
  • Starting New Weekday Batch for MERN Stack Development on 29 September 2025 @ 04:00 PM to 06:00 PM
Join Course

Data Type


A data type is a classification of data which tells the compiler or interpreter how the developer proposes to use the data.

Most programming languages support various types of data, including integer, real, character, string, and boolean.

Classification of Data Types:

Data types in Java are divided into 2 categories:

• Primitive Data Types or Pre-defined Data Type or Built-In Data Type
• User-Defined Data Type or Non-Primitive Data Types

• Primitive Data Types or Pre-defined Data Type or Built-In Data Type

There are eight primitive datatypes supported by Java. Primitive datatypes are predefined by the language and named by a keyword.

Data Type Name Size Range Default-Value
byte 1-byte -2^7 to 2^7-1 0
short 2-byte -2^15 to 2^15-1 0
int 4-byte -2^31 to 2^31-1 0
long 8-byte -2^63 to 2^63-1 0
float 4-byte 1.4E-45 to 3.4028235E38 0.0f | 0.0F
double 8-byte 4.9E-324 to 1.7976931348623157E308 0.0
boolean 1-bit no-range false
char 2-byte 0 to 65535 blank-space

Size in data type:

Memory allocation to a variable implies the size of memory allocated to the variable when the variable is declared along with data type. However, in the above, no memory allocation has been made to the data type.

            
package com.jtcindia.org;

/* Size of Data Type */

public class Jtc{

   public void dataType2() {
	System.out.println("---dataType2() in Jtc2 class---");
	   byte b11=127;
	   byte b22=-128;
	//byte b33=128; --> 128 is not in the range of byte
	//byte b44=-129;--> -129 is not in the range of byte
	int i11=2147483647;
	int i12=-2147483648;
     //int i13=2147483648; --> 2147483648 is not in the range of int
     //long l14=2147483649; --> by default 2147483649 is int type data and 2147483649 is not in the range 		// of int.
	long l12=2147483648l;
	//float f11=11.11; --> 11.11 is a double type value 11.11f is a float type data. 
	float f12=11.11f;
	double d11=11.12;
	double d12=11.13d;
	System.out.println(b11);
	System.out.println(b22);
	System.out.println(i11);
	System.out.println(i12);
	System.out.println(l12);
	System.out.println(f12);
	System.out.println(d12);
	System.out.println(d12);
	}
	
	public static void main(String[] args) {
		Jtc jtc=new Jtc();
		jtc.dataType2();

	}

}

            
        
    ---dataType2() in Jtc2 class---
    127
    -128
    2147483647
    -2147483648
    2147483648
    11.11
    11.13
    11.13
            

Range:

Out of 8 primitive data types, 7 primitive data types work with numbers, these are -byte, short, int, long, float, double, char. These 7 primitive data types contain their range, that is the maximum value and minimum value.

            
package com.jtcindia.org;

/* Data Type Minimum and Maximum value */

public class Jtc {

public void dataType3() {
System.out.println("Byte Range : " + Byte.MIN_VALUE + " to " +  Byte.MAX_VALUE);
System.out.println("Short Range : " + Short.MIN_VALUE + " to " + Short.MAX_VALUE);
System.out.println("int Range : " + Integer.MIN_VALUE + " to " + Integer.MAX_VALUE);
System.out.println("Long Range : " + Long.MIN_VALUE + " to " + Long.MAX_VALUE);
System.out.println("Float Range : " + Float.MIN_VALUE + " to " + Float.MAX_VALUE);
System.out.println("Double Range : " + Double.MIN_VALUE + " to " + Double.MAX_VALUE);
		
}

	public static void main(String[] args) {
		Jtc jtc = new Jtc();
		jtc.dataType3();

	}

}

            
        
    Byte Range : -128 to 127
    Short Range : -32768 to 32767
    int Range : -2147483648 to 2147483647
    Long Range : -9223372036854775808 to 9223372036854775807
    Float Range : 1.4E-45 to 3.4028235E38
    Double Range : 4.9E-324 to 1.7976931348623157E308
            

Default value:

When we declare a Class Level Variable but not an initializing it then JVM initialize variables along with the default value is called Default value of the variable.

            
package com.jtcindia.org;

/* Default value of each Data Type */

public class Jtc {

	byte b1;
	short s1;
	int i1;
	long l1;
	float f1;
	double d1;
	boolean b11;
	char c1;

	public void dataType1() {
		System.out.println(" ---dataType1() in Jtc1 class---");
		System.out.println(b1);
		System.out.println(s1);
		System.out.println(i1);
		System.out.println(l1);
		System.out.println(f1);
		System.out.println(d1);
		System.out.println(c1);
		System.out.println(b11);
	}

	public static void main(String[] args) {
		Jtc jtc = new Jtc();
		jtc.dataType1();

	}

}
            
        
            ---dataType1() in Jtc1 class---
    0
    0
    0
    0
    0.0
    0.0

    false
            

• User-Defined Data Type or Non-Primitive Data Types

User defined data types are those data types which are developed by programmers or developers by making use of appropriate features of the language. This implies that related variables of user defined data types allows us to store multiple values either of same type or different type or both.

User-defined data types are of the following kinds:

• Class
• Interface
• Enum
• Annotation [we will discuss in further tutorials]

• Class:

In Java, class is a user-defined data-type in which we can write the following different members. Class is a blueprint or a set of instructions to build a specific type of object.

Different members that can be written in a class are:

• Variables
• Block
• Method
• Constant
• Enum
• Interface
• Inner Class

syntax

class <class_name>{
  field;
  method;
}

Example

class Jtc{
  field;
  method;
}

• Interface:

In order to declare an interface, we need to use the keyword “interface”. Interface is fully abstract and an interface can contain only two types of members but from java 8 onwards we can define default method and static method also.

• Public abstract method
• Public static final variable
• Default method
• Static Method

syntax

interface < interface _name>{
  //declare field;
  //declared method;
}

            
interface Jtc{  
   	int a = 10; // public static final int a = 10
   	void m1(); // public abstract void m1() 
default void m2() { 
	System.out.println(“m1() in Jtc Interface”);
}
 	static void m3(){
		System.out.println(“m3() in Jtc Interface”);
} 
  }

            
        

• Enum:

An enum is a special data type that enables a variable to have a value among a set of predefined constants, that means a variable must be equal to one of the values that have been predefined for it. The names of enum fields are in uppercase letters.

In Java, you define an enum by using the enum keyword.

Example:

            
enum Day {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
    THURSDAY, FRIDAY, SATURDAY 
}


package com.jtcindia.org;

enum Days {
	SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}

public class Jtc{

	public static void main(String[] args) {
		Days day = Days.SUNDAY;
		System.out.println(day);

	}

}
            
        
    SUNDAY
            

In the above we are writing a class enum example and declaring one another class- enum Days because Days is constant, it means we cannot change anywhere and we can access easily.