Java
Java
1. Introduction to Java
2. Basic Syntax
3. Data Types
4. Variables
int x = 5; // Variable
final int MAX = 100; // Constant
5. Control Flow
// If-Else
int age = 18;
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
// For Loop
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
6. Arrays
7. Functions (Methods)
• Functions are defined inside classes and can be static or instance methods.
8. Object-Oriented Programming
class Animal {
String name;
void eat() {
System.out.println(name + " is eating.");
}
}
9. Exception Handling
try {
int result = 10 / 0; // Will throw an exception
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero.");
} finally {
System.out.println("Execution complete.");
}
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;