Java Master Guide
1. Introduction to Java
- Java is a high-level, object-oriented, platform-independent programming language.
- WORA: Write Once, Run Anywhere (due to JVM).
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Rohith Ji!");
}
}
2. Variables & Data Types
- int, float, char, double, boolean, String
int age = 21;
String name = "Rohith";
boolean isKing = true;
3. Operators & Control Flow
- Arithmetic, Relational, Logical
- if-else, switch-case
if(age > 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
4. Loops
- for, while, do-while
for(int i = 1; i <= 5; i++) {
System.out.println(i);
}
5. Arrays & Strings
int[] arr = {1, 2, 3};
String str = "Rohith";
System.out.println(str.length());
6. Methods
public static int add(int a, int b) {
return a + b;
}
7. OOP Concepts
- Class, Object, Inheritance, Polymorphism, Encapsulation, Abstraction
class Animal {
void sound() {
System.out.println("Animal sound");
}
}
class Dog extends Animal {
void sound() {
System.out.println("Bark");
}
}
8. Exception Handling
try {
int x = 10 / 0;
} catch(Exception e) {
System.out.println("Error: " + e);
}
9. Collections
- ArrayList, HashMap
ArrayList<String> list = new ArrayList<>();
list.add("Java");
HashMap<String, Integer> map = new HashMap<>();
map.put("Rohith", 1);
10. File Handling
FileWriter writer = new FileWriter("data.txt");
writer.write("Hello, Rohith!");
writer.close();