About types, variables, and operators in Java
This is an article about types, variables, and operators in Java.
In this article, we will learn about basic data types, variables, and operators in Java programming in preparation for an information processing article.
Data Types
It is largely divided into primitive data types and reference data types.
Basic data type
- Integer type: byte, short, int, long
- Real number: float, double
- Character type: char
- Logical type: boolean
Reference Data Type
- Class
- Interface
- Array
Variables
A variable represents a memory space that stores data.
In Java, when declaring a variable, you must specify the data type of that variable.
The data type of a variable determines the type and size of data that the variable can store.
For example, to store integers, use the βintβ data type, and to store characters, use the βcharβ data type.
int age = 20;
char gender = 'F';
Operators
Java provides various operators to manipulate data.
- Arithmetic operators: +, -, *, /, %, etc.
- Comparison operators: ==, !=, >, <, >=, <=, etc.
Logical operators: &&, Β , ! etc. - Assignment operators: =, +=, -=, *=, /=, %=, etc.
For example, to calculate the sum of two numbers, use the β+β arithmetic operator, and to compare two values for equality, use the β==β comparison operator.
int sum = 10 + 20; // Arithmetic operators
boolean isEqual = (sum == 30); // comparison operator
Conclusion
We learned about data types, variables, and operators in Java.
These are fundamental components of Java programming, so you should have a solid understanding of them.