Curriculum
In Java, data types are used to define the type of data that a variable can hold. There are two types of data types in Java: primitive and non-primitive.
Java has eight primitive data types, which are:
byte age = 20;
short temperature = -10;
int salary = 50000;
long distance = 1000000L;
float pi = 3.14f;
double weight = 70.5;
boolean isStudent = true;
char grade = 'A';
Rules for using primitive data types:
10
, 20.5
, etc.).Non-primitive data types are also known as reference types. These data types are created using class definitions or interfaces. Some examples of non-primitive data types are:
String name = "John";
int[] numbers = {1, 2, 3, 4, 5};
Scanner scanner = new Scanner(System.in);
Rules for using non-primitive data types:
new
keyword.In summary, in Java, data types are used to define the type of data that a variable can hold. There are primitive and non-primitive data types, each with its own rules for usage.