W3Schools Java Data Types: A Complete Guide To Java Variables And Primitives

Robert Jul 13, 2026

Data types are a fundamental aspect of programming in any language, including Java. They define the kind of data a variable can hold and the operations that can be performed on that data. By understanding Java's data types, you can effectively use the language to solve complex problems.

30 Days of Java – Day 2 | Variables & Data Types Explained for Beginners and students
30 Days of Java – Day 2 | Variables & Data Types Explained for Beginners and students

This article explores Java's data types, their purposes, and their usage. Let's dive into the world of Java data types.

Data types in java
Data types in java

Primitive Data Types

Java provides eight primitive data types, which are not objects; they are the smallest units of data. They are categorized into two groups: integer-type and floating-point-type.

Data Types in Java
Data Types in Java

Let's discuss these primitive data types and their subclasses with examples.

Integer-Types

Java Data Types Explained
Java Data Types Explained

Integer types store whole numbers without decimal points. Java provides four integer types with different sizes and therefore, different ranges.

TypeSizeRange
byte1 byte−128 to 127
short2 bytes−32768 to 32767
int4 bytes−2^31 to 2^31 − 1
long8 bytes−2^63 to 2^63 − 1

For instance, to define an integer variable named 'myInteger', we use:

Java Data Types Made Easy for Beginners
Java Data Types Made Easy for Beginners

int myInteger = 10;

Floating-Point Types

Floating-point types store numbers with decimal points. Java provides two floating-point types.

TypeSizeRange
float4 bytes±3.4×10^38
double8 bytes±1.8×10^(308)
Java Data Type, Primitive and Non-Primitive Data type, Java Variables
Java Data Type, Primitive and Non-Primitive Data type, Java Variables

To define a double variable, we use:

double myDouble = 10.5;

Non-Primitive (Object) Data Types

Basic Data Types in Java with Example | Java Primitive and Non-Primitive Data Types with Syntax - BTech Geeks
Basic Data Types in Java with Example | Java Primitive and Non-Primitive Data Types with Syntax - BTech Geeks
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
Data Types In Java With Examples
Data Types In Java With Examples
Java Variables: The Building Blocks of Programming
Java Variables: The Building Blocks of Programming
Java Data Types Explained | Primitive vs Non-Primitive (With Memory Concept)
Java Data Types Explained | Primitive vs Non-Primitive (With Memory Concept)
three types of variable type in an organization
three types of variable type in an organization
Java Cheat Sheet for GTU Students | Quick Revision Notes & OOP Concepts
Java Cheat Sheet for GTU Students | Quick Revision Notes & OOP Concepts
Java Data Types Cheat Sheet 💻🔥 | Beginner Friendly
Java Data Types Cheat Sheet 💻🔥 | Beginner Friendly
Data Types in programming languages
Data Types in programming languages
a diagram that shows the different types of data types and how they are used to describe them
a diagram that shows the different types of data types and how they are used to describe them
Home
Home
Data Types in Java - Learn about primitive & non-primitive Java Data Types
Data Types in Java - Learn about primitive & non-primitive Java Data Types
Java Variables Explained | Local, Static & Instance Variables in Java
Java Variables Explained | Local, Static & Instance Variables in Java
Data Types in Java Explained | Primitive & Non-Primitive Java Data Types
Data Types in Java Explained | Primitive & Non-Primitive Java Data Types
a poster with different types of writing and numbers on it, including the words'jwa beginner notes '
a poster with different types of writing and numbers on it, including the words'jwa beginner notes '
Java Cheatsheet
Java Cheatsheet
Data Types in Java with Examples - Scientech Easy
Data Types in Java with Examples - Scientech Easy
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
Java Basics in 15 Minutes ☕ | Beginner-Friendly Java Crash Course
Java Basics in 15 Minutes ☕ | Beginner-Friendly Java Crash Course
Java Basics: JVM, JDK, JRE, Variables & Data Types for Beginners
Java Basics: JVM, JDK, JRE, Variables & Data Types for Beginners

Along with primitive data types, Java also provides non-primitive data types, which include classes, interfaces, and arrays. We'll focus on arrays in this article.

Arrays

An array in Java is an object that allows to store multiple values of the same data type in a single variable. Arrays are defined using the "new" keyword followed by the data type and the array bracket.

For instance, to define an integer array with five elements, you can use:

int[] myIntArray = new int[5];

Java also allows initializing arrays directly with the values at the time of declaration:

int[] myIntArray = {1, 2, 3, 4, 5};

Arrays provide a efficient way to handle a collection of data.

Mastering Java data types will give you a strong foundation for writing effective and efficient code. Keep practicing and exploring to improve your understanding and skills.