Java Applet, GUI, JDBC, RMI & Networking - Study Guide
1. What is Applet?
Applet is a Java program that runs in a web browser. It's a subclass of java.applet.Applet or javax.swing.JApplet.
2. Life Cycle of an Applet:
- init(): Called once for initialization
- start(): Called after init and when applet becomes active
- paint(Graphics g): For drawing
- stop(): When applet becomes inactive
- destroy(): Final cleanup
3. How to initialize an applet?
Override the init() method in your Applet class to set up resources and UI components.
4. Steps in Applet Programming:
1. Extend Applet class
2. Override lifecycle methods
3. Compile the Java file
4. Use <applet> tag or AppletViewer to run
5. DocumentBase() and getCodeBase():
- getDocumentBase(): URL of the HTML document
- getCodeBase(): URL of the applets .class file
6. What is JApplet?
JApplet is the Swing-based Applet that provides advanced GUI features over traditional AWT-based Applet.
7. Event Handling?
Mechanism to respond to user interactions like mouse clicks or key presses, using listener interfaces.
8. Events, Sources, Classes, Listeners:
- Event: Encapsulates user interaction
- Source: Component generating event
- Event Classes: ActionEvent, MouseEvent
- Listeners: Interfaces like ActionListener, MouseListener
9. Delegation Model:
Follows the Observer pattern, where an event source delegates processing to registered listener objects.
Java Applet, GUI, JDBC, RMI & Networking - Study Guide
10. Mouse Event Example:
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.out.println("Clicked at: " + e.getX() + ", " + e.getY());
}
});
12. Short Notes:
- Inner Class: Defined within another class, useful for event handling
- Adapter Class: Default implementation of listener interfaces like MouseAdapter
13. AWT Hierarchy:
Component > Container > Panel, Window > Frame, Dialog. AWT includes Label, Button, TextField etc.
14. Two User Interfaces:
- AWT: Heavyweight, platform dependent
- Swing: Lightweight, platform independent
15. Two Text Components:
- TextField: Single-line input
- TextArea: Multi-line input
16. Layout Manager & Types:
- FlowLayout
- BorderLayout
- GridLayout
- GridBagLayout
17. Designing GUI in Java:
Use Swing components (e.g., JFrame, JButton) arranged using layout managers.
18. Containers & Components:
- Containers hold components (e.g., JPanel)
- Components are GUI elements (e.g., JButton)
19. Add Menu Example:
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Open");
Java Applet, GUI, JDBC, RMI & Networking - Study Guide
menu.add(item);
bar.add(menu);
frame.setJMenuBar(bar);
20. Extending GUI via Swing:
Swing provides rich controls like JTable, JTree, and allows customization with look-and-feel.
21. AWT vs Swing:
AWT: Heavyweight, limited controls
Swing: Lightweight, rich UI components
22. Collections:
- List, Set, Queue, Map: Framework to handle groups of objects.
23. Set, Sequence, Map:
- Set: Unique elements
- Sequence: Ordered elements
- Map: Key-value pairs
24. ArrayList vs Vector:
- ArrayList: Not synchronized, faster
- Vector: Synchronized, thread-safe
26. JDBC Concept:
Java API to connect and run queries with databases.
27. JDBC Driver Types:
Type 1: JDBC-ODBC Bridge
Type 2: Native API
Type 3: Network Protocol
Type 4: Thin Driver
28. JDBC Packages:
- java.sql
- javax.sql
29. JDBC Process:
1. Load Driver
2. Connect
Java Applet, GUI, JDBC, RMI & Networking - Study Guide
3. Create Statement
4. Execute
5. Process ResultSet
6. Close
30. Non-Conventional DB Connect:
Use suitable JDBC bridge/driver (e.g., MongoDB JDBC bridge).
31. CallableStatement:
CallableStatement cs = con.prepareCall("{call procedureName(?, ?)}");
32. SQL with JDBC:
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
33. Display Table Program:
while(rs.next()) {
System.out.println(rs.getString("name"));
}
35. RMI Registry:
Used to bind and lookup remote objects using a name string.
36. RMI Architecture:
Client Stub Skeleton Remote Object Registry
37. RMI Programming Model:
1. Define Interface
2. Implement
3. Compile with rmic
4. Register with RMI Registry
5. Client lookup
38. Naming & Directory Services:
Naming.rebind() to register, Naming.lookup() to retrieve remote object
39. Distributed Application with RMI:
Allows method invocation across JVMs over network.
Java Applet, GUI, JDBC, RMI & Networking - Study Guide
40. RMI Client-Server:
Server binds remote object, client looks up and invokes
42. TCP/IP Sockets:
Use Socket (client) and ServerSocket (server) for communication
43. Servlet Life Cycle:
- init()
- service()
- destroy()
44. java.net Package:
Classes for networking: URL, Socket, InetAddress
45. Stream Socket:
Socket: client-side class
ServerSocket: server-side
45. Servlet Short Note:
Java program running on server to handle HTTP requests.
46. Socket Program Example:
Socket s = new Socket("localhost", 8080);
OutputStream os = s.getOutputStream();
47. Connection-Oriented Steps:
1. Establish connection
2. Transfer data
3. Close connection
48. Datagram:
UDP based connectionless protocol using DatagramSocket, DatagramPacket
49. InetAddress Class:
InetAddress ip = InetAddress.getByName("google.com");