0% found this document useful (0 votes)
2 views3 pages

Java Thread Exception Swing Notes

The document covers various aspects of Java programming, including thread synchronization, thread priority, and inter-thread communication. It also discusses the thread lifecycle, exception handling, applet lifecycle, Java Streams, key events, adapter classes, layout managers, and the advantages of using Swing. Additionally, it lists common Swing components and their functionalities.

Uploaded by

palm131719
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)
2 views3 pages

Java Thread Exception Swing Notes

The document covers various aspects of Java programming, including thread synchronization, thread priority, and inter-thread communication. It also discusses the thread lifecycle, exception handling, applet lifecycle, Java Streams, key events, adapter classes, layout managers, and the advantages of using Swing. Additionally, it lists common Swing components and their functionalities.

Uploaded by

palm131719
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

1.

Synchronization of Multiple Threads in Java

Synchronization ensures only one thread accesses critical sections using synchronized keyword.

Example:

class Counter {

int count = 0;

synchronized void increment() { count++; }

2. Setting Thread Priority & Inter-thread Communication

Priority: setPriority(int)

Thread.MIN_PRIORITY = 1, NORM_PRIORITY = 5, MAX_PRIORITY = 10

Inter-thread communication: wait(), notify(), notifyAll()

Example:

class Shared {

synchronized void print(int n) { wait(); }

synchronized void complete() { notify(); }

3. Thread Lifecycle

States: New, Runnable, Running, Blocked, Terminated

4. Exception & Built-in Classes

Checked: IOException, SQLException


Unchecked: ArithmeticException, NullPointerException

Example:

try { int a = 5/0; } catch(ArithmeticException e) {}

5. Applet Lifecycle

init(), start(), paint(), stop(), destroy()

6. Java Streams & I/O

Byte streams: InputStream, OutputStream

Character streams: Reader, Writer

Example:

FileReader fr = new FileReader("[Link]");

7. Key Events

KEY_PRESSED, KEY_RELEASED, KEY_TYPED

Handled with KeyListener or KeyAdapter

8. Adapter Classes

Provide default implementations for listener interfaces

Example:

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {


[Link](0);

});

9. Layout Managers

FlowLayout, BorderLayout, GridLayout, CardLayout, GridBagLayout

10. Why Swing is Preferred

- Lightweight

- More features

- MVC architecture

- Platform-independent

11. Significance of Layout Managers

Automates layout, responsive UI

Types: FlowLayout, BorderLayout, GridLayout, GridBagLayout

12. Swing Components

JButton, JLabel, JTextField, JTextArea, JComboBox, JList, JTable, JPanel, JFrame

You might also like