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