Advanced_Java_Programming_Guide
Advanced_Java_Programming_Guide
1
1. Stub & Skeleton Conclusion: JFrame f = new JFrame();
2. Remote Reference Layer Focus on these high-probability questions with both f.setLayout(new FlowLayout());
3. Transport Layer theoretical and code-based preparation. Practice f.add(new JButton("One"));
Server Interface: writing, compiling, and debugging these examples. f.setSize(200, 200);
public interface Calc extends Remote { Advanced Java Programming: Exam f.setVisible(true);
int add(int a, int b) throws RemoteException; Preparation Guide Q4. Write short notes on (Any Two):
} 2D Shapes in Swing: Use Graphics2D
Server Implementation: Additional Section: PYQ Analysis & Predicted class to draw shapes like rectangles, ovals.
Questions for 2025
public class CalcImpl extends UnicastRemoteObject MouseEvent and MouseListener:
implements Calc { GUI Programming and Event Handling
Handle mouse input with methods like
public int add(int a, int b) { return a + b; } Q1. Why do we use Panels while creating GUI
mouseClicked, mousePressed, etc.
} applications in Java? Explain the components of
Client: the event handling model in Java. Session Tracking: Maintain user state
Answer: using cookies, URL rewriting, or HttpSession.
Calc stub = (Calc)
Naming.lookup("rmi://localhost:5000/calc"); Panels act as containers to group related
JavaBeans & Properties
System.out.println(stub.add(5, 3)); UI components, making layout management easier.
Q5. What is a JavaBean? Explain different types
Event handling model in Java follows of properties in JavaBeans with examples.
Q10. What are marshalling and unmarshalling of the delegation model, where event sources (e.g., Answer:
arguments in RMI? Differentiate between buttons) send events to listeners (e.g., JavaBeans are reusable software components that
CORBA and RMI. ActionListener). follow specific conventions:
Answer:
o Event Source: Generates the
Marshalling: Converting object into event
Public no-arg constructor
byte stream. o Event Object: Encapsulates
Getter and setter methods
Unmarshalling: Reconstructing object event details Serializable
from byte stream. o Event Listener: Receives and Property Types:
CORBA: Language-independent handles the event Simple: Single value
RMI: Java-specific Q2. What are adapter classes? What is the Indexed: Arrays/collections
benefit of using adapter classes in Java while
Bound: Notifies listeners
creating events in GUI programs? Explain with
JavaBeans and Components
an example. Constrained: Can veto property changes
Q11. What is a JavaBean? Explain different Q6. Explain the component architecture of
Answer:
types of properties in JavaBeans with examples. JavaBeans. Write a simple JavaBean class with
Answer: Adapter classes provide default
appropriate properties, methods, and event
JavaBeans are reusable components with implementations of listener interfaces so you can
handling.
getter/setter methods, no-arg constructors, and override only the methods you need.
Answer:
serializability. Example:
Architecture includes:
Properties:
import java.awt.event.*;
Bean class
import javax.swing.*;
o Simple: Single value (e.g.,
Events
name)
o Indexed: Arrays/lists (e.g.,
public class AdapterDemo extends JFrame { Event listeners
AdapterDemo() {
scores[]) BeanInfo (optional)
addWindowListener(new WindowAdapter() {
o Bound: Notifies changes public void windowClosing(WindowEvent
public class EmployeeBean implements Serializable
o Constrained: Can veto e) {
{
changes private String name;
dispose();
Example: public String getName() { return name; }
}
public class StudentBean implements Serializable { public void setName(String name) { this.name =
});
private String name; name; }
setSize(200, 200);
public String getName() { return name; } }
setVisible(true);
public void setName(String name) { this.name = }
name; } Servlets, JSP, and Web Technologies
public static void main(String[] args) {
} Q7. What are the differences between servlets
new AdapterDemo();
Q12. Explain the component architecture of and Java applications? Explain different
}
JavaBeans. Write a simple JavaBean class with methods used for handling cookies in Java.
}
appropriate properties, methods, and event Answer:
Q3. Why do we need to use Layout managers
handling. while creating GUI applications in Java? Explain Servlets run on web servers; applications
Answer: different types of Layout managers with are standalone.
Architecture involves: examples. Cookie handling:
Bean class Answer: o Cookie ck = new
Events (PropertyChangeListener) Layout managers manage component arrangement Cookie("user", "John");
BeanInfo for customization
in containers: o res.addCookie(ck);
(Use PropertyChangeSupport to implement bound FlowLayout: Left to right o Cookie[] cks =
properties.) BorderLayout: 5 regions (North, South, req.getCookies();
East, West, Center) Q8. Differentiate between declaration and
expression as used in JSP. Also, create a JSP
GridLayout: Grid-based layout
2
page that contains three textboxes for any three Marshalling: Convert object to byte Ran Topic Question Probabili
numbers and a button to display the greatest. stream k Area (Paraphrased) ty
Answer:
Unmarshalling: Convert byte stream to
Declaration (<%! ... %>): Declares object
JavaBean definition,
methods or variables property types,
CORBA: Language-independent 2 JavaBeans
architecture, code
High
Expression (<%= ... %>): Outputs value
RMI: Java-specific example
JSP Example:
Q12. What is RMI? Explain its components.
<%@ page language="java" %> Servlet vs. app,
Write a client-server application in RMI to find
<html> cookies, JSP
the simple interest (P=500, R=8%, T=3). Servlets/JS Very
<body> 3 declarations vs.
Answer: P High
<%! int max(int a, int b, int c) { expressions, JSP
return (a > b && a > c) ? a : (b > c ? b : c); RMI Components: Interface, coding
} %> Implementation, Stub/Skeleton, Registry
Interface: ResultSet types, data
<form method="post">
public interface Bank extends Remote { access, interfaces,
<input name="n1"> 4 JDBC High
float interest(float p, float r, float t) throws CRUD/programming
<input name="n2">
RemoteException; with scenario
<input name="n3">
<input type="submit"> }
Marshalling/unmarshal
</form> Implementation:
RMI/COR ling, RMI vs. CORBA,
<% public class BankImpl extends 5 High
BA RMI architecture,
if(request.getParameter("n1") != null) { UnicastRemoteObject implements Bank {
program
int a = public float interest(float p, float r, float t) { return
Integer.parseInt(request.getParameter("n1")); (p*r*t)/100; } Variables/constants,
int b = } Core Java string methods,
6 Medium
Integer.parseInt(request.getParameter("n2")); Client: Concepts exception handling,
int c = Bank b = (Bank) basic logic
Integer.parseInt(request.getParameter("n3")); Naming.lookup("rmi://localhost:5000/bank");
%> System.out.println(b.interest(500, 8, 3));
Preparation Tips:
<p>Greatest: <%= max(a, b, c) %></p>
Additional Frequently Repeated/Expected Prioritize: GUI/event handling,
<%
Questions servlets/JSP, JDBC.
}
%> Q13. Java Variables and Constants: Explain with Practice Coding: GUI forms, queries,
</body> examples. RMI programs.
</html> final int MAX = 100; // constant Theory + Code: Combine both in
int age = 25; // variable answers.
Q14. String Methods in Java: Demonstrate
Database Connectivity (JDBC) Short Notes: Revise frequent subtopics
Q9. How can data be accessed through ResultSet common string manipulations.
(e.g., MouseListener).
String s = "Hello World";
object? Explain forward-only, scroll-insensitive,
s.length(); Update Yourself: Follow trends and
and scroll-sensitive ResultSet.
s.toUpperCase(); PYQs from recent years.
Answer:
s.substring(0, 5); These questions and patterns provide a highly
Use rs.next(), rs.getString(), etc. to access data.
Q15. Exception Handling Mechanism: Explain focused preparation roadmap for your Advanced
Forward-only: Move forward only. Java Programming exam in 2025.
with an example.
Scroll-insensitive: Scroll but no DB try { Advanced Java Programming: Exam
change detection. int a = 10 / 0; Preparation Guide
Scroll-sensitive: Detects DB changes. } catch (ArithmeticException e) {
Q10. Write a program to display records of System.out.println("Divide by zero"); Expanded List of High-Probability and
students with 'distinction' and major 'Data } finally { Recurring Advanced Java Questions (2025)
Science' from College DB. System.out.println("Always executed"); A. Core Java & OOP Concepts
Connection con = } Q1. Describe Java as an object-oriented
DriverManager.getConnection(...); Q16. Write a program to find the largest of three programming language. What are the key
PreparedStatement ps = numbers using Java. features of Java?
con.prepareStatement("SELECT * FROM Students int a = 5, b = 10, c = 7; Answer:
WHERE Level='Distinction' AND Major='Data int max = (a > b && a > c) ? a : (b > c ? b : c); Java is an object-oriented language supporting
Science'"); System.out.println("Largest: " + max); features like:
ResultSet rs = ps.executeQuery(); Encapsulation: Hiding data using
while(rs.next()) { Summary Table: Most Probable Questions private access and providing access via methods
System.out.println(rs.getString("Name")); (2025) Inheritance: Creating new classes from
} existing ones
Ran Topic Question Probabili
k Area (Paraphrased) ty Polymorphism: Same interface,
Distributed Programming (RMI, CORBA)
different behaviors (method overloading and
Q11. What are marshalling and unmarshalling of Panels, event model,
GUI/Event Very overriding)
arguments in RMI? Differentiate between 1 adapter classes, layout
CORBA and RMI.
Handling
managers
High Abstraction: Hiding complex
Answer: implementation details
3
Q2. Explain different access specifiers in Java. start(): Creates new thread and calls run() Avoids thread contention but complex to
Answer: design
public: Accessible everywhere C. String Handling & Collections Q26. Garbage Collection & JVM Tuning
private: Accessible within the same class Q11. String class and 5 methods Use JVM flags like -Xms, -Xmx
String s = "Hello";
protected: Accessible within package or Types: Serial, Parallel, G1, ZGC
s.length();
subclass Q27. Java Mail API
s.charAt(1);
(default): Package-private s.equals("hello");
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.example.com");
Q3. Discuss all the three usages of the final s.indexOf("l");
Session session =
keyword. What is the use of this and super s.substring(1, 3);
Session.getDefaultInstance(props);
keyword? Q12. Reverse words in a sentence
Q28. JavaFX vs Swing, HBox/VBox
Answer: String input = "Java is fun";
final variable: Value cannot be changed String[] words = input.split(" "); JavaFX is newer, supports FXML, CSS
final method: Cannot be overridden for(int i = words.length - 1; i >= 0; i--) { HBox: Horizontal layout
4
Advanced Java Programming: Exam ExecutorService ex = Q26. Java SecurityManager
Preparation Guide Executors.newFixedThreadPool(2); Used to restrict file, network, or class access
ex.submit(() -> System.out.println("Task")); Q27. Digital Signatures & Certificates
Further Expanded High-Probability Advanced Ensure authenticity and integrity of data
Java Questions for 2025 4. Collections Framework
1. Core Java & Object-Oriented Programming Q12. List vs Set vs Map 10. Java 8 and Beyond Features
Q1. Explain the concept of packages in Java. List: Ordered, duplicates allowed Q28. Lambda and Functional Interface
Runnable r = () -> System.out.println("Run");
How do you create and use packages? Set: Unordered, no duplicates
Answer: Q29. Stream API
Packages group related classes and interfaces,
Map: Key-value pairs list.stream().filter(x -> x >
Q13. HashMap vs TreeMap 10).forEach(System.out::println);
prevent name conflicts, and control access.
package mypack; HashMap: Unordered, fast Q30. Optional Class
public class MyClass {} TreeMap: Sorted, slower Optional<String> name = Optional.of("John");
// Usage Q14. Sort list with Comparator name.ifPresent(System.out::println);
import mypack.MyClass; Collections.sort(list, (a, b) -> a.age - b.age);
Q2. What are wrapper classes in Java? Explain 11. Miscellaneous Practical Questions
autoboxing and unboxing with examples. 5. Java I/O and Serialization Q31. Method Overriding and Polymorphism
Integer i = 10; // Autoboxing Q15. Byte vs Character Streams class A { void show() {} }
class B extends A { void show() {} }
int x = i; // Unboxing Byte: Binary data
Q3. Explain the difference between shallow copy Q32. try-catch-finally
(InputStream/OutputStream)
and deep copy in Java. How can you implement try {} catch(Exception e) {} finally {}
cloning?
Char: Text (Reader/Writer) Q33. Producer-Consumer (wait/notify)
Q16. Serialization and transient keyword
Shallow Copy: Copies references class A implements Serializable {
(Use synchronized block with wait and notify)
Q34. HashSet and TreeSet
Deep Copy: Copies actual objects transient int a; Set<String> set = new HashSet<>();
class Person implements Cloneable { } Set<String> sorted = new TreeSet<>();
public Object clone() throws Q17. Serialize and deserialize an object Q35. Even-Odd threads
CloneNotSupportedException { ObjectOutputStream out = new Alternate printing using synchronized + wait/notify.
return super.clone(); ObjectOutputStream(new
} FileOutputStream("obj.dat")); Summary Table: Additional High-Probability
} out.writeObject(obj); Topics and Questions
Q4. Role of static keyword, static block, static
methods 6. Java Networking Topic Area Sample Questions & Concepts
static { Q18. Socket concept and TCP client-server Packages, wrapper classes,
System.out.println("Static block"); ServerSocket ss = new ServerSocket(5000); Core Java & OOP cloning, static keyword, abstract
} Socket s = ss.accept(); vs interface
static void greet() { Q19. TCP vs UDP
System.out.println("Hello"); TCP: Reliable, connection-based Exception Checked vs unchecked, try-with-
} Handling resources, assertions
UDP: Fast, connectionless
Synchronization, synchronized
2. Exception Handling & Assertions Multithreading &
7. Advanced GUI Programming method/block, thread lifecycle,
Q5. Difference between checked and unchecked Concurrency
Q20. MVC in Swing Executor
exceptions
Checked: IOException, SQLException
Model: Data logic List/Set/Map differences,
Unchecked: NullPointerException,
View: GUI components
Collections
HashMap vs TreeMap, sorting
Framework
ArithmeticException Controller: Event handling logic with Comparator
Q6. Try-with-resources Q21. Swing Calculator
I/O & Byte vs char streams,
try (BufferedReader br = new BufferedReader(new (Already included earlier)
Serialization serialization, transient variables
FileReader("file.txt"))) { Q22. Event Delegation Model
System.out.println(br.readLine()); Uses listeners to handle events from Networking Sockets, TCP vs UDP
} sources MVC in Swing, event
Q7. What are assertions in Java? Advanced GUI delegation, calculator GUI
Used for debugging: 8. Advanced Servlets and JSP program
assert x > 0 : "x must be positive"; Q23. Session Management: Cookies, URL
Rewriting, HttpSession Session management, JSP
Servlets & JSP
3. Multithreading & Concurrency HttpSession session = request.getSession(); directives, file upload via JSP
Q8. Synchronization in Java session.setAttribute("user", "John");
Security Manager, digital
synchronized void print() {} Q24. JSP Directives: page, include, taglib Security
signatures, certificates
Q9. Synchronized method vs block <%@ page contentType="text/html" %>
Method: Locks whole method <%@ include file="header.jsp" %>
Java 8+ Features
Lambda expressions, streams,
Optional class
Block: Locks only specific part
Q25. File Upload in JSP
Use Apache Commons FileUpload API.
Q10. Thread Lifecycle Diagram: Polymorphism, exception
New → Runnable → Running → 9. Security in Java
Practical Coding handling, producer-consumer,
Waiting/Blocked → Dead HashSet/TreeSet, threads
Q11. Executors Framework
5
Ensures changes are visible to all
Final Preparation Advice threads, preventing caching. JDBC & Database
Expand scope to include Java 8+ and Q9. wait() vs sleep() Q24. JDBC Batch Processing
ps.addBatch();
security. wait(): Releases lock, used in sync block
ps.executeBatch();
Code common patterns: MVC, sleep(): Keeps lock, pauses thread Q25. Connection Pooling
producer-consumer, GUI forms. Q10. Deadlock Example
Reuses DB connections. Improves
Review servlets, JSP, JDBC, RMI synchronized(obj1) {
performance.
theory and examples. synchronized(obj2) {}
Stay updated on new APIs: JavaFX, }
JavaBeans & Component Model
Java Mail. Prevent by consistent lock ordering or Q26. Introspector
Solve past papers/mock tests to grasp using tryLock()
Analyzes bean properties/methods for
phrasing and frequency. use in IDEs
This exhaustive guide ensures comprehensive Java Collections & Generics
Q27. Bound vs Constrained Properties
Q11. ArrayList vs LinkedList
coverage of high-probability Advanced Java Bound: Notifies listeners
Programming topics for 2025 exams. ArrayList: Fast access, slow inserts
Constrained: Allows vetoing
Advanced Java Programming: Exam LinkedList: Slow access, fast
Preparation Guide inserts/deletes
RMI & Distributed Computing
Q12. Type Erasure
Q28. rmic Compiler
Unique Advanced Java Programming Questions Generic info removed at runtime. Cannot
(Not Duplicates) Generates stub/skeleton classes for
use instanceof with generic types.
Core Java & OOP remote interfaces
Q13. ConcurrentHashMap vs HashMap
Q1. Explain the concept of method hiding in Q29. Dynamic Class Loading in RMI
Thread-safe, segmented locking vs not
Java. How does it differ from method Loads classes at runtime via codebase
thread-safe
overriding? URL
Method hiding is when a subclass defines Java I/O and Serialization
a static method with the same signature as a static Modern Java Features
Q14. FileInputStream vs BufferedInputStream
method in the parent class. Overriding deals with Q30. Default Methods in Interfaces
BufferedInputStream reduces I/O calls
instance methods and polymorphism. Allow interface evolution without
using a buffer
Q2. What is the diamond problem in multiple breaking implementations
Q15. Custom Serialization
inheritance? How does Java address this issue? Q31. Method References
private void writeObject(ObjectOutputStream out)
Java avoids this problem by not throws IOException {}
list.forEach(System.out::println);
supporting multiple inheritance with classes. Q32. CompletableFuture
Instead, it uses interfaces and requires explicit CompletableFuture.runAsync(() -> {...});
Networking
resolution if default methods conflict. Q16. URL vs URI
Q3. Describe the role of the transient keyword in Security
Java.
URI: Identifier Q33. Restrict File Access
Prevents a field from being serialized.
URL: Locator with protocol System.setSecurityManager(new
Q17. UDP Socket Program SecurityManager());
Useful for sensitive data.
DatagramSocket ds = new DatagramSocket(); Q34. AccessController
Q4. How does Java achieve platform
ds.send(packet); AccessController.doPrivileged(() -> {...});
independence?
Java source code → compiled to Advanced GUI (Swing/JavaFX) Miscellaneous
bytecode → runs on JVM → independent of OS. Q18. GlassPane in Swing Q35. JNDI
Exception Handling
Overlay for custom painting (e.g., modal Used to look up services by name (e.g.,
effects) LDAP, EJB)
Q5. What is a chained exception in Java?
Q19. Custom Swing Component Q36. Internationalization
try {
throw new NullPointerException("Original"); Extend JComponent, override ResourceBundle rb =
paintComponent(Graphics g) ResourceBundle.getBundle("Messages",
} catch (Exception e) {
Locale.FRANCE);
throw new RuntimeException("Wrapper", e);
} Servlets & JSP (Advanced) Q37. Observer Pattern
Q20. Servlet Chaining Observable obs = new Observable();
Q6. Error vs Exception
obs.addObserver(observer);
Error: JVM-related (e.g., Use RequestDispatcher.forward() or
Q38. Reflection in Java
OutOfMemoryError) chaining filters
Class<?> c = Class.forName("MyClass");
Exception: Application-level (e.g.,
Q21. Filters in Servlets
Method m = c.getMethod("method");
filter.doFilter(req, res, chain);
IOException) m.invoke(obj);
Log requests, modify headers, etc.
Multithreading & Concurrency Q22. include vs forward How to Use This List
Q7. What is thread starvation? include: Adds content Revision: Quickly revise lesser-seen
Occurs when low-priority threads never forward: Passes control topics.
get CPU. Use fair locks or thread priorities. Q23. Prevent Session Fixation Mock Exams: Practice under exam time
Q8. volatile keyword session.invalidate() and start new session limits.
after login
6
Interview Prep: Great for testing depth
in advanced areas.
Let me know if you'd like more from a specific topic
or difficulty level!