0% found this document useful (0 votes)
5 views2 pages

Java AWT and Multithreading Notes

The document provides comprehensive notes on Multithreading in Java and the Abstract Window Toolkit (AWT). It covers key concepts such as thread creation, lifecycle, synchronization, and GUI components, along with examples. Additionally, it highlights the differences between AWT and Swing in terms of their features and characteristics.

Uploaded by

shuzosama511
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java AWT and Multithreading Notes

The document provides comprehensive notes on Multithreading in Java and the Abstract Window Toolkit (AWT). It covers key concepts such as thread creation, lifecycle, synchronization, and GUI components, along with examples. Additionally, it highlights the differences between AWT and Swing in terms of their features and characteristics.

Uploaded by

shuzosama511
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JAVA AWT & MULTITHREADING - COMPLETE

NOTES
1. MULTITHREADING IN JAVA

Definition: Multithreading is the process of executing multiple threads simultaneously to maximize


CPU utilization.
A Thread is a lightweight process that runs independently within a program.

Advantages:
• Better CPU utilization
• Faster execution
• Saves memory (threads share same space)
• Reduces response time

Creating Threads:
1. By implementing Runnable Interface
2. By extending Thread Class

Thread Methods:
start(), run(), sleep(), join(), isAlive(), currentThread(), setPriority(), getPriority()

Thread Life Cycle:


1. New → 2. Runnable → 3. Running → 4. Non-Runnable → 5. Terminated

Inter-thread Communication:
wait(), notify(), notifyAll() - used for communication between synchronized threads.

Thread Priority:
Range: 1 (MIN_PRIORITY) to 10 (MAX_PRIORITY), default = 5 (NORM_PRIORITY)

Synchronization:
Used to control access to shared resources.
Achieved using the 'synchronized' keyword.

Example (Short):
class MyThread extends Thread {
public void run() { [Link]("Running thread..."); }
public static void main(String[] args){ new MyThread().start(); }
}

2. JAVA AWT (Abstract Window Toolkit)

Definition: AWT is a part of Java used to create GUI (Graphical User Interface) applications.
Package: [Link]
Components: Frame, Button, Label, TextField, Checkbox, List, Choice, etc.

AWT Hierarchy:
Object → Component → Container → (Window / Panel) → Frame, Applet

Steps to Create AWT Program:


1. Import [Link] and [Link]
2. Create Frame
3. Add components
4. Set Layout
5. Set Size and Visibility

Important Components:
• Label - displays text
• Button - performs an action
• TextField - accepts text input
• Checkbox - toggle option
• Choice - dropdown list
• List - scrollable item list

Layouts:
FlowLayout, BorderLayout, GridLayout

Event Handling:
Uses Delegation Event Model
- Event Source: component generating event
- Event Object: holds event details
- Event Listener: interface that handles event

Example (Short):
import [Link].*;
import [Link].*;
public class ButtonExample extends Frame implements ActionListener {
Button b = new Button("Click"); Label l = new Label("Not Clicked");
ButtonExample(){ add(b); add(l); [Link](this); setLayout(new FlowLayout());
setSize(200,120); setVisible(true);}
public void actionPerformed(ActionEvent e){ [Link]("Clicked!"); }
public static void main(String[] args){ new ButtonExample(); }
}

Difference Between AWT and Swing:


| Feature | AWT | Swing |
|----------|------|--------|
| Type | Heavyweight | Lightweight |
| Look | Native OS | Custom Look |
| Package | [Link] | [Link] |

You might also like