←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Diagrams

Diagrams

Visual representations for Unit 3

Figure 3.1: State Transition Diagram — The Lifecycle of a Thread in Java

Figure 3.1: State Transition Diagram — The Lifecycle of a Thread in Java
1. NEW (Born)Thread t = new MyThread();
→ t.start() →
2. RUNNABLEReady in queue waiting for CPU
→ Scheduler picks →
3. RUNNINGExecuting run() on CPU
→ run() finishes →
5. TERMINATEDDead (Cannot restart)
Explanation
  • A new thread becomes runnable after start and may then wait, block or resume.
  • It terminates when its run method finishes or leaves through an uncaught exception.
Detailed Notes →Quick Revision →

Figure 3.2: Two Ways of Creating Threads in Java

Figure 3.2: Two Ways of Creating Threads in Java
Method 1: Extending Thread Class
  • class MyThread extends Thread
  • Override public void run()
  • Instantiate: MyThread t = new MyThread();
  • Start thread: t.start();
Method 2: Implementing Runnable Interface
  • class MyTask implements Runnable
  • Implement public void run()
  • Pass to Thread: Thread t = new Thread(new MyTask());
  • Start thread: t.start();
Explanation
  • A task can implement Runnable or a class can extend Thread.
  • Calling start on a Thread schedules its execution separately from the caller.
Detailed Notes →Quick Revision →

Figure 3.3: The Exception Hierarchy in Java (java.lang.Throwable)

Figure 3.3: The Exception Hierarchy in Java (java.lang.Throwable)
Throwable (Root Class in java.lang)
1. Exception (Recoverable by Program)
• Checked: IOException, SQLException
• Unchecked (RuntimeException): ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException
2. Error (Fatal JVM / Hardware Failures)
Cannot be recovered by code (e.g., OutOfMemoryError, StackOverflowError)
Explanation
  • Throwable is the common parent of Error and Exception.
  • RuntimeException and its subclasses are unchecked exceptions.
Detailed Notes →Quick Revision →

Figure 3.4: Execution Flow of try - catch - finally Block

Figure 3.4: Execution Flow of try - catch - finally Block
1. try { ... }Monitors risky code that may cause an exception
→ If Exception Occurs →
2. catch (Exception e)Catches & handles the exception object
→ Always Runs →
3. finally { ... }Executes 100% of the time (Closes files/DB)
Explanation
  • The try block runs first and a matching catch handles an exception.
  • The finally block normally runs as control leaves the statement.
Detailed Notes →Quick Revision →

Figure 3.5: The AWT Class Hierarchy of Window Fundamentals (java.awt)

Figure 3.5: The AWT Class Hierarchy of Window Fundamentals (java.awt)
Object → Component (Superclass of all GUI elements: Button, Label, Checkbox, TextComponent, Container)
Container → Window → Frame / Dialog
• Window: Top-level window with no borders/title bar.
• Frame: Full standalone window with Title Bar, Borders, Minimize/Maximize/Close buttons & Menu Bar!
Container → Panel → Applet
• Panel: Borderless sub-container used to group components inside a Frame.
• Applet: Browser-embedded panel.
Explanation
  • Components that contain other components belong to the Container branch.
  • Window and Frame build on that hierarchy to supply top-level windows.
Detailed Notes →Quick Revision →

Figure 3.6: The 4 Standard AWT Layout Managers in Your Syllabus

Figure 3.6: The 4 Standard AWT Layout Managers in Your Syllabus
1. FlowLayout
Arranges components left-to-right in rows like words in a paragraph (Default for Panel/Applet)
2. BorderLayout
Divides container into 5 zones: NORTH, SOUTH, EAST, WEST, CENTER (Default for Frame)
3. GridLayout
Divides container into a rectangular matrix of equal-sized cells (Rows × Columns)
4. CardLayout
Stacks components one behind another like a deck of playing cards (Only 1 visible at a time)
Explanation
  • Flow wraps components and Grid gives them equal cells.
  • Border uses named regions and Card displays one panel from a set at a time.
Detailed Notes →Quick Revision →

Figure 3.7: The 5 Regions of BorderLayout

Figure 3.7: The 5 Regions of BorderLayout
TopBorderLayout.NORTH
Spans full width at the top (Ideal for Toolbars / Headers)
MidWEST | CENTER | EAST
WEST (Left Sidebar)  |  CENTER (Main Content Area)  |  EAST (Right Sidebar)
BotBorderLayout.SOUTH
Spans full width at the bottom (Ideal for Status Bar / Action Buttons)
Explanation
  • North and south span the top and bottom, with west and east at the sides.
  • The centre uses the remaining space as the container changes size.
Detailed Notes →Quick Revision →