Java Data Types
Data Types In Java
In Java, data types are used to classify the types of data that variables can hold. Java has two categories of data types: Primitive data types and Non-primitive data types
Primitive Data Types:
Primitive data types represent single values and are not objects. They have fixed sizes and are directly stored in memory. There are eight primitive data types in Java
- boolean data type
- byte data type
- char data type
- short data type
- int data type
- long data type
- float data type
- double data type
- byte: 8-bit signed integer (from -128 to 127)
- short: 16-bit signed integer (from -32,768 to 32,767)
- int: 32-bit signed integer (from -2,147,483,648 to 2,147,483,647)
- long: 64-bit signed integer (from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
- float: 32-bit floating-point number (single precision)
- double: 64-bit floating-point number (double precision)
- boolean: Represents true or false
- char: Represents a single 16-bit Unicode character
Non-primitive Data Types:
These data types are non-primitive and are derived from the primitive types. They refer to objects.
- String: Represents a sequence of characters.
- Arrays: A collection of similar types of elements.
- Classes: User-defined types.
Here's an example that demonstrates the use of all primitive data types in Java :