Java Data Types

Data types represent which data should be stored in a variable. In the previous chapter, we have worked with some data types like int, String, etc. In this chapter, we will learn Java Data Types in detail.

IMPORTANT: Java is a statically typed language. This means while declaring a variable you must specify which type of data you want to store.

Java Data Types

Java Data Types can be divided mainly into two categories;

Primitive Data Types – are the most basic data types in Java. It has no additional methods, which means fundamental data types. Primitive data types can be divided roughly into 8 types.

Output

80
30000
500000
20000000000
5.4
120.56
true
A
Hello

Java Non-primitive Data Types

Non-primitive data types are always referred to some built-in objects. We are not familiar with Java objects yet. So before learning about Java non-primitive data types, we will familiar with Java objects.

Objects are concepts of Object-oriented programming features in Java. We will learn Java OOP (Object-oriented programming) and non-primitive data types with their method in the next subsequent chapters.

NOTE: In the above example, we have declared a string variable just like other primitive data types. But String is actually a non-primitive data type. But the exception is String is declared as non-primitive variables. But string has many methods to work with. We will learn everything about string in a later chapter.

What is next?

So far, we have learned many numeric data types like byte, short, int, long, float, double, etc. What can we do using these kinds of data? Well, simply we can perform mathematical operations. Right?

But to perform mathematical operations we need to learn how mathematical operators work in Java programming. So in the next chapter, we will study Java Operators in detail.