Java has 8 basic data types, also known as primitive data types. They are divided into 4 groups:

1. Integers: Used to store whole numbers, without decimal points.

  • byte: Takes up 1 byte of memory, stores integers from -128 to 127.
  • short: Takes up 2 bytes of memory, stores integers from -32,768 to 32,767.
  • int: Takes up 4 bytes of memory, stores integers from -2,147,483,648 to 2,147,483,647. This is the most commonly used integer data type.
  • long: Takes up 8 bytes of memory, stores integers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

2. Floating-Point Numbers: Used to store numbers with decimal points.

  • float: Takes up 4 bytes of memory, stores single-precision floating-point numbers.
  • double: Takes up 8 bytes of memory, stores double-precision floating-point numbers. This is the most commonly used floating-point data type.

3. Characters:

  • char: Takes up 2 bytes of memory, stores a single Unicode character.

4. Boolean:

  • boolean: Can only hold two values: true or false.

Summary of basic data types in Java:

Data TypeSize (bytes)Range of ValuesDefault Value
byte1-128 to 1270
short2-32,768 to 32,7670
int4-2,147,483,648 to 2,147,483,6470
long8-9,223,372,036,854,775,808 to 9,223,372,036,854,775,8070L
float4±3.4028235E+380.0f
double8±1.7976931348623157E+3080.0d
char2'\u0000' to '\uffff' (0 to 65,535)'\u0000'
boolean1 bittrue or falsefalse
  • When declaring a variable with the long data type, you need to add the letter L at the end of the value. For example: long myLong = 10000000L;
  • When declaring a variable with the float data type, you need to add the letter f at the end of the value. For example: float myFloat = 3.14f;

Understanding these basic data types is an important first step in learning Java programming