Detailed Java Concepts
Exception Handling, Threading, IO,
Swing, Generics, Collections,
Wrappers, OOP
1. Exception Handling
• Types: Checked (IOException), Unchecked (NullPointerException)
• User-Defined: Extend Exception class
• throw: Used to throw an exception explicitly
• throws: Declares exceptions that a method can throw
• try-catch-finally: Basic exception handling block
• Multiple catch blocks and nested try-catch
User-Defined Exception Example
• class MyException extends Exception
• Constructor: public MyException(String msg) { super(msg); }
• Usage: throw new MyException("error")
• Catching: try { ... } catch(MyException e) { ... }
2. Threading Concepts
• Concurrency: Multiple tasks run 'apparently' at the same time
• Parallelism: True simultaneous execution on multiple cores
• Thread states: New, Runnable, Running, Blocked, Terminated
Thread Creation Methods
• Extend Thread class: override run(), call start()
• Implement Runnable: pass object to Thread class
• ExecutorService for better control over thread pool
3. Java IO Streams
• Byte Streams: InputStream, OutputStream
• Character Streams: Reader, Writer
• Common Classes: FileReader, FileWriter, BufferedReader, PrintWriter
• Serialization: ObjectOutputStream, ObjectInputStream
4. Java Swing
• Components: JFrame, JButton, JLabel, JTextField
• Layouts: BorderLayout, FlowLayout, GridLayout
• Events: ActionListener, MouseListener, KeyListener
• javax.swing package used for GUI development
5. Generics
• Purpose: Type safety, code reusability
• Generic Class: class Box<T> { T value; }
• Generic Method: <T> void print(T data)
• Bounded Types: <T extends Number>
6. Java Collections
• List (ArrayList, LinkedList): Ordered, allows duplicates
• Set (HashSet, TreeSet): No duplicates
• Map (HashMap, TreeMap): Key-value pairs
• Queue (PriorityQueue, LinkedList): FIFO
7. Wrapper Classes and Collections
• Convert primitives to objects: int -> Integer
• Autoboxing & Unboxing
• Wrapped Collections: Collections.unmodifiableList(list)
8. OOP Features
• Encapsulation: Hiding data using access modifiers
• Abstraction: Hiding implementation via interfaces/abstract classes
• Inheritance: 'is-a' relationship, extends keyword
• Polymorphism: Compile-time (overloading), Runtime (overriding)
• Modularity and Message Passing