Java Data Types (Primitive)

In Java, there are eight primitive data types that represent the basic types of values that can be stored in a variable. These data types are:

  1. byte - A byte is an 8-bit signed integer. It has a minimum value of -128 and a maximum value of 127.

  2. short - A short is a 16-bit signed integer. It has a minimum value of -32,768 and a maximum value of 32,767.

  3. int - An int is a 32-bit signed integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647.

  4. long - A long is a 64-bit signed integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807.

  5. float - A float is a 32-bit floating-point number. It has a precision of 6-7 digits.

  6. double - A double is a 64-bit floating-point number. It has a precision of 15-16 digits.

  7. char - A char is a 16-bit Unicode character. It can represent any character in the Unicode standard.

  8. boolean - A boolean represents a true or false value.

Here's an example of declaring and initializing variables using some of these primitive data types:

byte age = 25;
short year = 2022;
int salary = 50000;
long totalSalary = 500000;
float pi = 3.14f;
double e = 2.71828;
char initial = 'J';
boolean isMarried = false;
Sou‮ww:ecr‬w.theitroad.com

These primitive data types are used to represent simple values in Java programs. In addition to these primitive data types, Java also has reference data types, such as objects and arrays, which are used to represent more complex data structures.