ADVANCED JAVA (BIS402)
All Repeated Questions with Answers
Exam Preparation Guide
Generated: June 22, 2026
TABLE OF CONTENTS
Module Topic Repetitions
Module 1 Collections Framework - ArrayList & LinkedList 2 times
Module 2 ■ 4 times
StringBuffer Methods (append, insert, reverse, replace)
Module 2 String Constructors & Comparison 3 times
Module 2 Duplicate Character Removal 2 times
Module 3 Swing Features & Components 3 times
Module 3 Simple Swing Application 2 times
Module 4 Servlet Life Cycle ■ 4 times
Module 4 JSP Tags & Types 3 times
Module 4 Cookie Handling 3 times
Module 5 JDBC Drivers ■ 4 times
Module 5 JDBC Process Steps 3 times
Module 5 Transaction Processing 2 times
MODULE 1: COLLECTIONS FRAMEWORK
Q1: ArrayList & LinkedList Operations (Repeated 2 times)
Question: Create a class STUDENT with two private members: USN, Name using LinkedList class in Java.
Write a program to add at least 3 objects of above STUDENT class and display the data.
Answer:
import [Link].*; class Student { private String USN; private String Name;
public Student(String USN, String Name) { [Link] = USN; [Link] = Name;
} public void display() { [Link]("USN: " + USN + ", Name: " +
Name); } } public class StudentDemo { public static void main(String[] args)
{ LinkedList<Student> list = new LinkedList<>(); [Link](new
Student("USN001", "Raj Kumar")); [Link](new Student("USN002", "Priya
Singh")); [Link](new Student("USN003", "Amit Patel")); for(Student s :
list) { [Link](); } } }
Q2: Collection Framework Methods (Repeated 4 times)
Question: What is Collection Framework? Explain the methods defined by Collection interface (Collection,
List, Sorted Set, Queue).
Answer:
Collection Framework: A unified architecture for representing and manipulating collections of objects.
Methods of Collection Interface:
• add(E e) - Adds element to collection
• remove(Object o) - Removes element from collection
• contains(Object o) - Returns true if collection contains element
• size() - Returns number of elements
• isEmpty() - Returns true if collection is empty
• iterator() - Returns iterator over collection
• clear() - Removes all elements from collection
Main Interfaces:
• List: Ordered, allows duplicates (ArrayList, LinkedList, Vector)
• Set: Unordered, no duplicates (HashSet, TreeSet, LinkedHashSet)
• Queue: FIFO order (PriorityQueue, Deque)
Q3: Legacy Classes (Repeated 3 times)
Question: Explain any four legacy classes of Java's Collection Framework.
Answer:
Legacy Classes (Pre-Java 5):
1. Vector: Synchronized, growable array. Similar to ArrayList but thread-safe.
- Methods: add(), remove(), get(), size(), capacity()
2. Hashtable: Synchronized key-value pairs. Thread-safe version of HashMap.
- Methods: put(), get(), remove(), keys(), elements()
3. Stack: LIFO (Last-In-First-Out) data structure. Extends Vector.
- Methods: push(), pop(), peek(), empty(), search()
4. Properties: Hashtable subclass for reading configuration properties.
- Methods: load(), getProperty(), setProperty()
Note: These classes are synchronized and slower than modern alternatives. Use
[Link]() instead.
MODULE 2: STRING HANDLING
■ Q4: StringBuffer Methods (MOST REPEATED - 4 times)
Question: Explain StringBuffer methods - append(), insert(), reverse(), replace()
Answer:
public class StringBufferDemo { public static void main(String[] args) { //
1. append() - adds at end StringBuffer sb1 = new StringBuffer("Hello");
[Link](" World"); [Link]("append(): " + sb1); // Output:
Hello World // 2. insert() - inserts at specific index StringBuffer sb2 =
new StringBuffer("Hello"); [Link](5, " Java");
[Link]("insert(): " + sb2); // Output: Hello Java // 3.
reverse() - reverses the string StringBuffer sb3 = new StringBuffer("Java");
[Link](); [Link]("reverse(): " + sb3); // Output: avaJ //
4. replace() - replaces characters in range StringBuffer sb4 = new
StringBuffer("Hello World"); [Link](0, 5, "Hi");
[Link]("replace(): " + sb4); // Output: Hi World } }
Q5: String Constructors (Repeated 3 times)
Question: What is String in Java? Write a program demonstrating six constructors of String class.
Answer:
public class StringConstructors { public static void main(String[] args) {
// 1. Empty constructor String s1 = new String(); // "" // 2. From string
literal String s2 = new String("Hello"); // 3. From character array char[]
chars = {'J','a','v','a'}; String s3 = new String(chars); // 4. From byte
array byte[] bytes = {65,66,67}; String s4 = new String(bytes); // "ABC" //
5. From char array (substring) String s5 = new String(chars, 0, 2); // "Ja"
// 6. From StringBuffer StringBuffer sb = new StringBuffer("Buffered");
String s6 = new String(sb); } }
Q6: String Comparison (Repeated 3 times)
Question: Differentiate between equals() and == with respect to string comparison.
Answer:
== operator: Compares object reference (memory address), not content.
String s1 = "Hello";
String s2 = "Hello";
String s3 = new String("Hello");
s1 == s2 // true (same reference in String pool)
s1 == s3 // false (different objects)
equals() method: Compares actual content/value of strings.
[Link](s2) // true (same value)
[Link](s3) // true (same value)
equalsIgnoreCase(): Compares content ignoring case.
"Hello".equalsIgnoreCase("hello") // true
Q7: Duplicate Character Removal (Repeated 2 times)
Question: Write a program to remove duplicate characters from a string and display it.
Answer:
public class RemoveDuplicates { public static String removeDuplicates(String
str) { StringBuilder result = new StringBuilder(); boolean[] seen = new
boolean[256]; for(char c : [Link]()) { if(!seen[c]) {
[Link](c); seen[c] = true; } } return [Link](); } public
static void main(String[] args) { String input = "programming";
[Link]("Original: " + input); [Link]("After removing
duplicates: " + removeDuplicates(input)); // Output: progamin } }
MODULE 3: SWING & GUI
Q8: Swing Features (Repeated 3 times)
Question: Explain the key features of Swing with a sample program.
Answer:
Swing Features:
• Platform Independent: Works on all OS
• Lightweight: Components are written in Java
• Rich Components: JButton, JLabel, JTextField, JTable, etc.
• Pluggable Look and Feel: Can change appearance
• MVC Architecture: Separation of Model, View, Controller
• Event Handling: Supports various event listeners
• Double Buffering: Reduces flickering in animations
import [Link].*; import [Link].*; public class SwingDemo
extends JFrame { public SwingDemo() { setTitle("Swing Application");
setSize(300, 150); setDefaultCloseOperation(EXIT_ON_CLOSE); JLabel label =
new JLabel("Click Button"); JButton btn = new JButton("Click Me");
[Link](e -> [Link]("Button Clicked!")); add(label);
add(btn); setVisible(true); } public static void main(String[] args) { new
SwingDemo(); } }
Q9: Simple Swing Application (Repeated 2 times)
Question: Write a program to create a simple swing application using buttons.
(Refer to Q8 above for code example)
Q10: Swing vs AWT (Repeated 2 times)
Question: Compare Java AWT and Swing. What are differences?
Answer:
Feature AWT Swing
Type Heavyweight Lightweight
Components Limited Rich set
Platform Platform dependent Platform independent
Look & Feel Native look Pluggable
Performance Faster Slower (more features)
MVC No Yes
Double Buffering No Yes
MODULE 4: SERVLETS & JSP
■ Q11: Servlet Life Cycle (MOST REPEATED - 4 times)
Question: Explain the life cycle of Servlets with a neat diagram.
Answer:
Servlet Life Cycle - 3 Phases:
1. INITIALIZATION PHASE:
• Container loads the servlet class
• Creates servlet instance using no-arg constructor
• Calls init() method (called once per servlet)
• Servlet is now in memory and ready to handle requests
2. SERVICE PHASE (Request-Response):
• For each client request, container creates separate thread
• Calls service() method (dispatches to doGet/doPost)
• doGet() - handles HTTP GET requests
• doPost() - handles HTTP POST requests
• Sends response back to client
3. DESTRUCTION PHASE:
• Container calls destroy() method
• Servlet instance is garbage collected
• Resources are released
Flow: init() → service() → destroy()
Q12: Core Interfaces (Repeated 3 times)
Question: List and explain core interfaces in [Link] package.
Answer:
Core Interfaces:
1. Servlet Interface:
• Main interface for all servlets
• Methods: init(), service(), destroy(), getServletConfig(), getServletInfo()
2. ServletRequest:
• Encapsulates information from client request
• Methods: getParameter(), getParameterNames(), getAttribute(), getInputStream()
3. ServletResponse:
• Encapsulates response to client
• Methods: getWriter(), getOutputStream(), setContentType(), sendRedirect()
4. ServletConfig:
• Contains servlet configuration information
• Methods: getServletName(), getInitParameter(), getInitParameterNames()
5. ServletContext:
• Represents web application
• Methods: getAttribute(), setAttribute(), getInitParameter(), log()
Q13: JSP Tags (Repeated 3 times)
Question: Explain different JSP tags with examples.
Answer:
JSP Tag Types:
1. Directive Tags: <%@ ... %>
<%@ page import="[Link].*" %>
<%@ include file="[Link]" %>
2. Declaration Tags: <%! ... %>
<%! int count = 0; %>
<%! public void myMethod() { } %>
3. Scriptlet Tags: <% ... %>
<% String name = [Link]("name"); %>
<% [Link]("Hello: " + name); %>
4. Expression Tags: <%= ... %>
Current time: <%= new [Link]() %>
5. Action Tags:
<jsp:useBean id="user" class="User" />
<jsp:setProperty name="user" property="*" />
<jsp:getProperty name="user" property="name" />
Q14: Cookie Handling (Repeated 3 times)
Question: What are cookies? Write a program to create cookie with name 'User name' and value 'xyz'.
Answer:
public class CookieServlet extends HttpServlet { protected void
doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException { [Link]("text/html");
PrintWriter out = [Link](); // Create cookie Cookie cookie = new
Cookie("User_name", "xyz"); [Link](24 * 60 * 60); // 24 hours
[Link](cookie); [Link]("<html><body>");
[Link]("<h2>Cookies Set</h2>"); // Retrieve and display cookies
Cookie[] cookies = [Link](); if(cookies != null) { for(Cookie c
: cookies) { [Link]([Link]() + " = " + [Link]()); } }
[Link]("</body></html>"); } }
MODULE 5: JDBC
■ Q15: JDBC Drivers (MOST REPEATED - 4 times)
Question: Explain the four types of JDBC drivers.
Answer:
Four Types of JDBC Drivers:
Type 1 - JDBC-ODBC Bridge:
• Translates JDBC calls to ODBC calls
• Uses native code
• Slow performance, platform dependent
• Example: [Link]
• Not recommended for web applications
Type 2 - Native API Driver (Partial Java):
• Uses native database libraries
• Better performance than Type 1
• Platform dependent
• Example: [Link]
Type 3 - Network Protocol Driver (Pure Java):
• Uses database independent protocol
• Middleware server required
• Can connect to multiple databases
• Example: Informix IDS, Sybase
Type 4 - Database Native Protocol Driver (Pure Java):
• Directly communicates with database
• No middleware required
• Best performance, platform independent
• Example: MySQL ([Link]), PostgreSQL
• Most commonly used
■ Q16: JDBC Process Steps (MOST REPEATED - 3 times)
Question: Explain different steps involved in JDBC process with code snippet.
Answer:
import [Link].*; public class JDBCDemo { public static void main(String[]
args) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs
= null; try { // Step 1: Load Driver [Link]("[Link]");
[Link]("Driver Loaded"); // Step 2: Create Connection String url
= "jdbc:mysql://localhost:3306/testdb"; String user = "root"; String
password = "password"; conn = [Link](url, user,
password); [Link]("Connection Established"); // Step 3: Create
Statement String sql = "SELECT * FROM student WHERE USN=?"; pstmt =
[Link](sql); [Link](1, "USN001"); // Step 4: Execute
Query rs = [Link](); // Step 5: Process Result while([Link]())
{ [Link]("USN: " + [Link](1)); [Link]("Name: "
+ [Link](2)); } } catch(ClassNotFoundException e) {
[Link]("Driver error: " + e); } catch(SQLException e) {
[Link]("Database error: " + e); } finally { // Step 6: Close
Resources try { if(rs != null) [Link](); if(pstmt != null) [Link]();
if(conn != null) [Link](); [Link]("Resources Closed"); }
catch(SQLException e) { [Link](); } } } }
Q17: Transaction Processing (Repeated 2 times)
Question: Explain transaction processing in JDBC with example.
Answer:
public class TransactionDemo { public static void main(String[] args) {
Connection conn = null; try { conn = [Link](
"jdbc:mysql://localhost:3306/bank", "root", "password"); // Disable
auto-commit for transaction [Link](false);
[Link]("Transaction Started"); Statement stmt =
[Link](); // Multiple operations (all or nothing)
[Link]("UPDATE accounts SET balance = " + "balance - 1000 WHERE
accno = 101"); [Link]("UPDATE accounts SET balance = " +
"balance + 1000 WHERE accno = 102"); // Commit if no error [Link]();
[Link]("Transaction Committed"); } catch(SQLException e) { try {
// Rollback on any error [Link](); [Link]("Transaction
Rolled Back"); } catch(SQLException ex) { [Link](); } } } }
Q18: Connection Pooling (Repeated 2 times)
Question: Explain connection pooling with neat diagram and code snippets.
Answer:
Connection Pooling: Technique of maintaining pre-created database connections in a pool that can be
reused, improving performance.
Advantages:
• Reduces overhead of creating/closing connections
• Improves application performance
• Handles multiple concurrent user requests
• Better resource utilization
• Prevents connection leaks
How it works:
1. Container creates a pool of connections at startup
2. When client needs connection, it's borrowed from pool
3. After use, connection is returned to pool
4. Other clients can now use this connection
5. Reduces creation/destruction overhead
Using DBCP (Apache Commons DBCP):
BasicDataSource dataSource = new BasicDataSource();
[Link]("[Link]");
[Link]("jdbc:mysql://localhost:3306/testdb");
[Link]("root");
[Link]("password");
[Link](10);
[Link](50);
Connection conn = [Link]();
SUMMARY OF MOST REPEATED QUESTIONS
Rank Question Topic Module Repetitions
1■ StringBuffer Methods (append, insert, reverse, replace) Module 2 4 times
2■ JDBC Drivers (Type 1,2,3,4) Module 5 4 times
3■ Servlet Life Cycle Module 4 4 times
4 Collection Framework Methods Module 1 4 times
5 String Constructors Module 2 3 times
6 String Comparison (==, equals) Module 2 3 times
7 JSP Tags Module 4 3 times
8 Core Interfaces Module 4 3 times
9 Cookie Handling Module 4 3 times
10 Swing Features Module 3 3 times
11 JDBC Process Steps Module 5 3 times
12 Legacy Classes Module 1 3 times
Study Recommendations:
✓ Focus on the topics marked with ■ (Most Repeated - 4 times) ✓ Practice all code programs at least 2-3
times ✓ Understand the concept, don't just memorize ✓ Create your own variations of the programs ✓ Make
flashcards for important method definitions ✓ Practice writing code without looking at solutions ✓ Time
yourself while writing answers