Data Types in Java

 

In Java, data types define the type of data a variable can hold. They are mainly divided into two categories:


1. Primitive Data Types

These are the most basic data types in Java:

TypeDescriptionSizeExample
intInteger numbers4 bytesint age = 25;
floatDecimal numbers (single precision)4 bytesfloat temp = 36.5f;
doubleDecimal numbers (double precision)8 bytesdouble price = 99.99;
charSingle character2 byteschar grade = 'A';
booleanTrue or false1 bitboolean isJavaFun = true;
byteVery small integers1 bytebyte x = 100;
shortSmall integers2 bytesshort y = 10000;
longLarge integers8 byteslong z = 100000L;

2. Non-Primitive (Reference) Data Types

These are objects or classes that store references (memory addresses) to the actual data.

  • String – a sequence of characters: String name = "John";

  • Arrays – stores multiple values of the same type.

  • Classes, Interfaces, Enums – user-defined types used in object-oriented programming.


Understanding data types is a foundation for writing correct and efficient Java programs. It helps ensure that the right kind of data is stored and manipulated properly. If you’re starting out or looking to sharpen your skills, consider enrolling in the Best Java Training in Kochi to get hands-on experience with practical examples and real-world projects.

Comments