What is Java?
An object-oriented programming language.
Known for its portability (write once, run anywhere).
2. Setting Up the Environment
Installing JDK (Java Development Kit)
Configuring an IDE (e.g., Eclipse, IntelliJ IDEA)
3. Basic Syntax
3.1. Structure of a Java Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Explanation:
public class HelloWorld : Declares a public class.
public static void main(String[] args) : Entry point of the program.
System.out.println(...) : Prints text to the console.
, 3.2. Variables and Data Types
Primitive Types:
int, double, char, boolean
int age = 30;
double salary = 50000.50;
char initial = 'M';
boolean isJavaFun = true;
3.3. Operators
Arithmetic Operators: +, -, *, /, %
Comparison Operators: ==, !=, >, <, >=, <=
4. Control Flow
4.1. Conditional Statements
if (age >= 18) {
System.out.println("You are an adult.");
} else {
System.out.println("You are a minor.");
}
4.2. Loops
For Loop:
for (int i = 0; i < 5; i++) {
System.out.println(i);
}