Java Programming - Exam-Focused Quick Revision Notes (Units I to V)
UNIT I: Java Basics & OOP Concepts
Target Questions:
• Explain OOP principles with examples
• Write a Java program using constructor
Key Concepts:
• Java = Platform Independent + Object-Oriented
• JVM: Runs bytecode, JRE: Environment to run Java programs, JDK: Tools + JRE
Java Program Structure:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
OOP Pillars:
• Encapsulation: Hiding data using classes
• Inheritance: extends keyword
• Polymorphism: Overloading (same method, diff args), Overriding (same method, diff class)
• Abstraction: Hiding details using interfaces/abstract classes
Constructor Example:
class Student {
int id; String name;
Student(int i, String n) { id = i; name = n; }
void display() { System.out.println(id + " " + name); }
}
Command Line Args:
public class CmdArg {
public static void main(String[] args) {
System.out.println("Arg: " + args[0]);
}
}
1
UNIT II: Inheritance & Exception Handling
Target Questions:
• Types of inheritance in Java
• Try-catch example with custom exception
Inheritance Types:
• Single, Multilevel, Hierarchical
Super and Override Example:
class Animal {
void sound() { System.out.println("Animal sound"); }
}
class Dog extends Animal {
void sound() { super.sound(); System.out.println("Dog barks"); }
}
Try-Catch Example:
try {
int x = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: " + e);
}
Custom Exception:
class MyException extends Exception {
MyException(String msg) { super(msg); }
}
UNIT III: Applets, Threads, and Packages
Target Questions:
• Write an applet code
• Explain multithreading with Thread class
Applet Example:
import java.applet.Applet;
import java.awt.Graphics;
2
public class HelloApplet extends Applet {
public void paint(Graphics g) {
g.drawString("Hello Applet", 50, 50);
}
}
Multithreading:
class MyThread extends Thread {
public void run() {
System.out.println("Thread running");
}
}
Packages:
package mypkg;
public class A {
public void show() {
System.out.println("Package class");
}
}
UNIT IV: GUI (AWT/Swing) & Event Handling
Target Questions:
• AWT vs Swing difference
• Write a Swing program with button click
AWT Example:
Frame f = new Frame("My Form");
Button b = new Button("Click");
f.add(b);
f.setSize(300, 200);
f.setVisible(true);
Swing Example:
JFrame f = new JFrame("Swing");
JButton b = new JButton("Click");
f.add(b);
3
f.setSize(300, 200);
f.setVisible(true);
Event Handling:
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Clicked");
}
});
UNIT V: JDBC & Networking
Target Questions:
• JDBC steps with insert code
• TCP Server-Client program in Java
JDBC Connection Setup:
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pass);
Insert Record JDBC:
PreparedStatement pst = con.prepareStatement("INSERT INTO table VALUES
(?, ?)");
pst.setInt(1, 101);
pst.setString(2, "Buddy");
pst.executeUpdate();
Networking - Server:
ServerSocket ss = new ServerSocket(5000);
Socket s = ss.accept();
Networking - Client:
Socket s = new Socket("localhost", 5000);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
4
Next: Mock Model Paper with full answers formatted for exam