Java - Data Types

Java is a statically typed programming language, which means that every variable and expression has a specific data type, and the type is known at compile time. In this tutorial, we will go over the different data types available in Java and how to use them.

Primitive Data Types:

Java has eight primitive data types, which are the basic building blocks for all other types in the language. These data types are:

  • byte: a 8-bit signed integer, with a range from -128 to 127.
  • short: a 16-bit signed integer, with a range from -32,768 to 32,767.
  • int: a 32-bit signed integer, with a range from -2,147,483,648 to 2,147,483,647.
  • long: a 64-bit signed integer, with a range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
  • float: a 32-bit floating-point number, with a range from approximately 1.4E-45 to 3.4E38 and up to 7 decimal digits of precision.
  • double: a 64-bit floating-point number, with a range from approximately 4.9E-324 to 1.8E308 and up to 16 decimal digits of precision.
  • char: a single 16-bit Unicode character, with a range from '\u0000' to '\uffff'.
  • boolean: a true or false value, with two possible values: true and false.

Non-Primitive Data Types:

Java also has non-primitive data types, which are derived from the primitive data types. These data types are:

  • String: a sequence of characters.
  • Array: a collection of values of the same data type.
  • Class: a blueprint for creating objects.
  • Interface: a collection of abstract methods that can be implemented by a class.
  • Enum: a special type of class that represents a set of constant values.