Data Types in Java

Published: (February 10, 2026 at 02:28 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Data types specify the different sizes and values that can be stored in a variable. Java is a statically‑typed language, so every variable must be declared with its type before it is used.

Primitive Data Types

  • byte – 8‑bit signed integer. Range: -128 to 127.
  • short – 16‑bit signed integer. Range: -32,768 to 32,767.
  • int – 32‑bit signed integer. Range: -2,147,483,648 to 2,147,483,647.
  • long – 64‑bit signed integer. Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
  • float – 32‑bit single‑precision floating‑point number.
  • double – 64‑bit double‑precision floating‑point number.
  • boolean – Represents true or false.
  • char – 16‑bit Unicode character.
int a = 10;
float f = 3.14f;
boolean flag = true;
char letter = 'A';

Non‑Primitive (Reference) Data Types

  • Classes – Templates for creating objects.
  • Interfaces – Contracts that define methods for classes.
  • Arrays – Collections of elements of the same data type.
  • String – Represents a sequence of characters.
String name = "aaa";
int[] numbers = {1, 2, 3, 4};

Primitive vs Non‑Primitive Data Types

AspectPrimitive TypesNon‑Primitive Types
MemoryStored on the stackStored on the heap
SpeedFaster access and manipulationSlower due to reference handling
Exampleint a = 10;String name = "aaa";

Both categories are essential: primitives provide efficient, low‑level data handling, while non‑primitives enable more complex structures and behavior.

0 views
Back to Blog

Related posts

Read more »

O que são generics?

Generics são uma funcionalidade introduzida no Java 5 que permite criar classes, interfaces e métodos que trabalham com diferentes tipos de dados. Eles eliminam...

Constructor in java

What is Constructors? A constructor is a special method in Java that is automatically executed when an object of a class is created. It is mainly used to initi...

Java_Local&Global_Variable

Local Variable - Declared inside a method, constructor, or block {}. - Accessible only within that method or block. - Must be initialized before use. - Lifetim...

New article

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as we...