Menu

Data Types in Java
📰

Data Types in Java

DEV Community: java·Subash·16 days ago
#XGNnSWQW
#devtojava#devto#dev#types#primitive
Reading 0:00
15s threshold

What is a Data Type?

A data type tells Java what kind of value a variable can store, such as numbers, decimal values, characters, or text.

Every variable in Java must have a data type before we can use it.

Example:

int age = 25 ; String name = "John" ; double salary = 25000.50 ;

Enter fullscreen mode

Exit fullscreen mode

Types of Data Types in Java

Java data types are divided into two categories:

Primitive Data Types

Non-Primitive Data Types

1. Primitive Data Types

Primitive data types are the basic data types available in Java. They store simple values directly.

Java provides eight primitive data types.

Integer Types:

Data Type Size Description

byte 8 bits Small whole numbers

short 16 bits Short-range integers

int 32 bits Commonly used for integers

long 64 bits Large whole numbers

Floating-Point Types:

Data Type Size Description

float 32 bits Decimal values

double 64 bits More precise decimal values

Other Types:

Data Type Size Description

char 16 bits Stores a single…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.