In Java, variables are used to store data values that can be manipulated by the program. There are several data types in Java, including:
Primitive data types:
byte: 8-bit integer
short: 16-bit integer
int: 32-bit integer
long: 64-bit integer
float: 32-bit floating-point number
double: 64-bit floating-point number
boolean: true/false value
char: single character
Non-primitive data types:
String: a sequence of characters
Arrays: a collection of similar data types
Classes: user-defined data types
To declare a variable in Java, you need to specify the data type and give it a name. For example:
int age = 27;
boolean isStudent = true;
double height = 1.75;
String name = "InfiniLearn";
In this example, we have declared four variables: age, isStudent, height, and name. The data types of the variables are int, boolean, double, and String, respectively. In Java, variable names are case-sensitive and must begin with a letter, underscore, or dollar sign.
No comments:
Post a Comment