Core Java
Java Operators
Types of operators
- Arithmetic Operators
- Assignment Operators
1. Arithmetic operators
Arithmetic operators are used to perform basic math operations such as
- Addition
- Substraction
- Multiplication
- Division
public class Addition{
public static void main(String[] args){
int a =2;
int b =2;
System.out.println(a+b);
>>the result will be 4
}
}
in java the plus(+) operator is used to add the numbers
class Main→ Java code lives inside classes.main()→ Entry point of every Java application.System.out.println()→ Prints to console.
2. Variables in Java
Variables store data. In Java, you must declare the type before using them.
int age = 21;
double price = 99.99;
String name = "Sanjay";
boolean active = true;
3. Primitive Data Types
Java has 8 primitive types:
- byte – small numbers
- short
- int
- long
- float
- double
- char
- boolean
These are stored directly in memory and are very fast.
4. Reference Types
Anything that is not a primitive is a reference type.
String title = "Java Developer";
int[] numbers = {1, 2, 3};
ArrayList list = new ArrayList<>();
Reference types store the address of the object, not the object itself.
5. Type Conversion
Java supports both implicit and explicit casting:
// Implicit (safe)
int a = 10;
double b = a;
// Explicit (manual)
double x = 9.7;
int y = (int) x; // y = 9
Final thoughts
Mastering syntax and data types is the first step toward writing clean, efficient Java code. Once you're comfortable with these, you’re ready to learn OOP, collections, and real-world Spring Boot projects.