FullStack Extra10 Java
FullStack Extra10 Java
In-Depth Theory
■ In-Depth Concepts:
1. Basics:
- Strongly typed, compiled language
- Write Once, Run Anywhere
- Entry point: public static void main(String[] args)
2. Data Types:
- Primitive: int, float, double, char, boolean
- Non-primitive: String, Arrays, Objects
3. Control Flow:
- if, if-else, switch, for, while, do-while
4. OOP Features:
- Classes, Objects, Inheritance, Polymorphism, Encapsulation, Abstraction
5. Access Modifiers:
- public, private, protected, default (package-private)
6. Important Keywords:
- static, final, this, super, new, return, instanceof
7. Exception Handling:
- try-catch-finally
- throw vs throws
- Checked vs Unchecked exceptions
8. Collections:
- List, Set, Map
- ArrayList, HashMap, HashSet
9. Java Tools:
- javac for compilation
- java for execution
- JDK, JRE, JVM
Code Examples
1. Hello World:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
3. ArrayList Example:
import java.util.*;
ArrayList<String> names = new ArrayList<>();
names.add("Alice");
System.out.println(names.get(0));
4. Try-Catch:
try {
int a = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
}
Practice Assignment
4. Use a HashMap to store employee ID and name pairs, then display them.
5. Bonus:
- Create a program with a base class Animal and derived classes Dog and Cat
- Implement try-catch for NullPointerException