ADVANCED JAVA (BIS402)
Comprehensive VTU Master Question Bank & Complete 10-Mark Solutions
Syllabus Framework: Visvesvaraya Technological University (VTU) Standard Answer Keys
Coverage: Model Paper, June/July 2024, Dec 2024/Jan 2025, and Dec 2025/Jan 2026 Question Papers
MODULE 1: COLLECTIONS FRAMEWORK
Q1. Explain the legacy classes of Java's Collection Framework in detail. (Repeated 4 Times: Model Q1a,
June/July 2024 Q1b, Dec 2024/Jan 2025 Q2c, Dec 2025/Jan 2026 Q2c) [10 Marks]
Introduction to Legacy Classes
Before the release of Java 2 (JDK 1.2) and the introduction of a structured Collections Framework, Java used ad-
hoc classes and interfaces to group and manipulate objects. These are known as Legacy Classes. When JDK 1.2
was introduced, these legacy classes were re-engineered and retrofitted to implement the standard collection
interfaces, ensuring backward compatibility while seamlessly integrating into the modern hierarchy.
Core Legacy Classes and Interfaces
1. Enumeration Interface: An interface that provides methods to iterate through a series of elements sequentially.
It defines two methods: hasMoreElements() and nextElement(). It is a precursor to the modern
Iterator interface, but it is read-only and does not allow element removal during traversal.
2. Vector Class: A dynamic array implementation that is highly similar to ArrayList, but with one critical
distinction: Vector is fully synchronized. This makes it thread-safe for concurrent operations, but introduces a
substantial performance overhead due to locking mechanisms. It automatically grows its capacity by 100%
when its capacity limits are breached.
3. Stack Class: A direct subclass of Vector that models a strict Last-In, First-Out (LIFO) stack data structure. It
adds specialized operations: push() (add to top), pop() (remove/return from top), peek() (view top without
removal), empty() (check if stack is empty), and search() (finds an item's 1-based index).
4. Hashtable Class: A concrete implementation of a hash-map structure. Like HashMap, it maps key-value pairs
using a hashing algorithm. Unlike HashMap, Hashtable is synchronized (thread-safe) and completely forbids
null keys or values.
5. Properties Class: A specialized subclass of Hashtable used primarily to manage configuration files. It
restricts keys and values strictly to strings and allows persistent storage/retrieval via store() and load()
methods.
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 1
Comprehensive Code Demonstration
import [Link].*;
public class LegacyClassesDemo {
public static void main(String[] args) {
// 1. Vector and Enumeration Demonstration
Vector<String> vector = new Vector<>();
[Link]("VTU");
[Link]("Belagavi");
[Link]("Java");
[Link]("--- Vector Elements using Enumeration ---");
Enumeration<String> enumeration = [Link]();
while([Link]()) {
[Link]("Element: " + [Link]());
}
// 2. Stack Demonstration
Stack<Integer> stack = new Stack<>();
[Link](101);
[Link](202);
[Link](303);
[Link]("
--- Stack Operations ---");
[Link]("Top Element (Peek): " + [Link]());
[Link]("Popped Element: " + [Link]());
[Link]("Stack empty status: " + [Link]());
// 3. Hashtable Demonstration
Hashtable<Integer, String> hashtable = new Hashtable<>();
[Link](1, "Data Structures");
[Link](2, "Advanced Java");
[Link]("
--- Hashtable Elements ---");
for([Link]<Integer, String> entry : [Link]()) {
[Link]("Key: " + [Link]() + ", Value: " + [Link]());
}
}
}
Q2. What is the Java Collection Framework? Explain the core methods defined by the Collection
Interface. (Repeated 3 Times: Model Q2b, June/July 2024 Q1a, Dec 2024/Jan 2025 Q2a) [10 Marks]
The Java Collection Framework (JCF) is a unified, highly optimized architecture designed to represent and
manipulate groups of objects. It drastically reduces programming effort by providing high-performance, built-in
implementations of fundamental data structures (lists, sets, maps, queues) and common manipulation algorithms
(sorting, searching, filtering).
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 2
Core Methods of the Collection Interface ([Link])
Method Signature Functional Description
Ensures that this collection contains the specified element; returns
boolean add(E obj)
true if changed.
boolean addAll(Collection<? extends Appends all elements within the specified collection to the invoking
E> c) collection.
Completely flushes and removes all elements from the invoking
void clear()
collection.
Returns true if the invoking collection contains the specified target
boolean contains(Object obj)
object.
Returns true if the invoking collection contains all elements of the
boolean containsAll(Collection<?> c)
passed collection.
boolean isEmpty() Evaluates whether the collection contains zero elements.
Returns an iterator instance capable of sequentially traversing the
Iterator<E> iterator()
collection.
Removes a single instance of the target object if present; returns true
boolean remove(Object obj)
on success.
Removes all elements belonging to the passed collection from the
boolean removeAll(Collection<?> c)
invoking collection.
Returns the total count of elements currently resident within the
int size()
collection.
Converts the collection into a standard, flat array of raw Object
Object[] toArray()
references.
MODULE 2: STRING HANDLING & STRINGBUFFER
Q3. Explain the methods of the StringBuffer class with precise examples. (Repeated 3 Times: Model
Q4b, Dec 2024/Jan 2025 Q4a, Dec 2025/Jan 2026 Q4a) [10 Marks]
The StringBuffer class represents a mutable, thread-safe sequence of characters. Unlike standard Java
Strings, which are completely immutable, modifications made to a StringBuffer directly modify its internal
memory buffer without allocating new distinct string objects. This makes it highly efficient for iterative text
manipulation tasks.
Detailed Explanation of Key Methods
• append(): Concatenates the string representation of any data type (int, float, char, String, etc.) to the end of the
existing sequence.
Syntax: StringBuffer append(String str)
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 3
• insert(): Inserts data at a specified offset/index position. It shifts all subsequent characters to the right, growing
the buffer if needed.
Syntax: StringBuffer insert(int offset, String str)
• reverse(): Directly reverses the exact sequential order of characters within the invoking buffer.
Syntax: StringBuffer reverse()
• replace(): Replaces a distinct substring defined by a start index (inclusive) and an end index (exclusive) with a
target replacement string.
Syntax: StringBuffer replace(int start, int end, String str)
VTU-Standard Implementation Code
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("VTU");
// 1. Demonstrate append()
[Link](" Exam");
[Link]("After append: " + sb); // Output: VTU Exam
// 2. Demonstrate insert()
[Link](4, "Java ");
[Link]("After insert: " + sb); // Output: VTU Java Exam
// 3. Demonstrate replace()
[Link](4, 8, "AdvJava");
[Link]("After replace: " + sb); // Output: VTU AdvJava Exam
// 4. Demonstrate reverse()
[Link]();
[Link]("After reverse: " + sb); // Output: maxE avaJvdA UTV
}
}
MODULE 3: SWING COMPONENTS & EVENT HANDLING
Q4. Write a fully functional Java program to demonstrate a simple Swing application. (Repeated 3
Times: June/July 2024 Q6b, Dec 2024/Jan 2025 Q1a, Dec 2025/Jan 2026 Q6a) [10 Marks]
A basic Swing application consists of a top-level container frame (JFrame) that holds individual components (like
buttons, text entries, and labels). Components interact with users through Event Listeners using delegation event
infrastructure.
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 4
Robust Interactive Swing Program Architecture
import [Link].*;
import [Link].*;
import [Link].*;
public class SimpleSwingApp {
public static void main(String[] args) {
// Run Swing components on the Event Dispatch Thread (EDT) for thread safety
[Link](new Runnable() {
public void run() {
// 1. Instantiate the frame container
JFrame frame = new JFrame("VTU Interactive Swing Application");
[Link](400, 200);
[Link](JFrame.EXIT_ON_CLOSE);
// 2. Configure Layout Manager
[Link](new FlowLayout());
// 3. Instantiate basic components
JLabel label = new JLabel("Click the button to submit data:");
JTextField textField = new JTextField(15);
JButton button = new JButton("Submit");
JLabel responseLabel = new JLabel("");
// 4. Register Action Listener via anonymous inner class
[Link](new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String input = [Link]().trim();
if([Link]()) {
[Link]("Error: Input cannot be empty!");
} else {
[Link]("Submitted successfully: " + input);
}
}
});
// 5. Append components to content pane
[Link](label);
[Link](textField);
[Link](button);
[Link](responseLabel);
// 6. Center and visualize frame
[Link](null);
[Link](true);
}
});
}
}
MODULE 4: SERVLETS & JSP
Q5. Explain the complete operational Life Cycle of a Java Servlet in detail. (Repeated 4 Times: Model
Q8b, June/July 2024 Q7a, Dec 2024/Jan 2025 Q7b, Dec 2025/Jan 2026 Q7a) [10 Marks]
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 5
The servlet life cycle is managed exclusively by the web/servlet container (e.g., Apache Tomcat). It tracks the
evolution of a servlet from instantiation to full terminal garbage collection through a sequence of strict operational
checkpoints managed via callback methods.
The Four Operational Epochs
1. Servlet Class Loading & Instantiation: The container locates the compiled servlet class file upon server
startup or dynamically when the initial client request maps to it. The container invokes the default, no-argument
constructor to create the object instance.
2. Initialization Phase (init() method): Immediately following instantiation, the container invokes the public
void init(ServletConfig config) method. This executes exactly once during the entire runtime
existence of the servlet. It isolates tasks like initializing database connection pools or reading [Link] context
configurations.
3. Request Servicing Phase (service() method): For every discrete client HTTP request, the container spins
a lightweight thread and calls the servlet's public void service(ServletRequest req,
ServletResponse res) method. This automatically inspects the incoming request header method type
(GET, POST, etc.) and routes it dynamically to specialized processing routines like doGet() or doPost().
4. Destruction Phase (destroy() method): Before pulling down a servlet instance due to manual shutdown or
server resource reallocation, the container triggers the public void destroy() method exactly once. This
provides a safe place to release resources, serialize internal states, and close active database handles.
Lifecycle Schematic Flow Code
import [Link].*;
import [Link];
public class LifecycleDemoServlet implements Servlet {
// Epoch 2: Initialization
public void init(ServletConfig config) throws ServletException {
[Link]("Lifecycle Log: init() called. Resources allocated.");
}
// Epoch 3: Service incoming threads
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException {
[Link]("Lifecycle Log: service() called. Processing client thread.");
}
// Epoch 4: Terminal Destruction
public void destroy() {
[Link]("Lifecycle Log: destroy() called. Cleaning up handles.");
}
public ServletConfig getServletConfig() { return null; }
public String getServletInfo() { return "VTU Lifecycle Demo"; }
}
Q6. Comprehensive analysis of JavaServer Pages (JSP) Tags and Elements. (Repeated 4 Times: Model
Q8a, June/July 2024 Q7c, Dec 2024/Jan 2025 Q8a, Dec 2025/Jan 2026 Q8a) [10 Marks]
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 6
JSP elements facilitate the embedding of dynamic Java logical control directly inside flat, standard HTML text
markups. These markers are compiled down to automated servlets behind the scenes by the web container engine.
Taxonomy of Core JSP Elements
• Scriptlet Tags (<% ... %>): Embeds procedural Java source blocks directly inside the implicit target
processing method (_jspService()). Every statement inside a scriptlet must end with a standard semicolon.
Example: <% int pageHits = 5; pageHits++; %>
• Expression Tags (<%= ... %>): Evaluates a single internal expression, flattens the outcome directly into a
String datatype, and flushes it straight into the client response output stream. Do not use trailing semicolons
here.
Example: <p>Current Total Hits: <%= pageHits %></p>
• Declaration Tags (<%! ... %>): Declares instance variables, properties, or complete standalone helper
methods outside the scope of the _jspService() loop. These persist globally across all concurrent client
accesses.
Example: <%! public int computeCube(int x) { return x*x*x; } %>
• Directive Tags (<%@ ... %>): Delivers macro-level configuration commands to the compilation engine during
lifecycle translation. Common forms include page, include, and taglib.
Example: <%@ page import="[Link]" %>
MODULE 5: JDBC & ADVANCED DATABASE CONCEPTS
Q7. Systematically explain the four types of JDBC Architecture Drivers. (Repeated 4 Times: Model Q10a,
June/July 2024 Q10b, Dec 2024/Jan 2025 Q9a, Dec 2025/Jan 2026 Q9b) [10 Marks]
A JDBC driver provides a concrete implementation of the interfaces defined in the [Link] package, acting as an
abstraction bridge between raw Java code and database instances.
Driver Type Classifications
1. Type 1: JDBC-ODBC Bridge Driver: Translates native incoming Java API method invocations directly into
universal Microsoft ODBC runtime function calls. It depends heavily on native binary installations across target
execution environments. It is slow, fragile, and has been completely deprecated and purged since JDK 8.
2. Type 2: Native-API Driver (Partially Java): Converts incoming JDBC code calls into proprietary database-
specific native C/C++ client client library binaries (e.g., Oracle OCI layer). It provides better performance than
Type 1, but requires database client binaries to be explicitly compiled and installed on every client deployment
target.
3. Type 3: Network-Protocol Driver (Fully Java): Ships standard database instructions through a vendor-neutral
network middle-tier proxy server. The middle-tier middleware application server then converts these instructions
into targeted socket variations. It offers high flexibility and does not require native client installations, but adds a
multi-tier network layer overhead.
4. Type 4: Thin Driver (Fully Java / Pure Java): Implements the targeted database engine's low-level proprietary
network communication protocol directly at the Java driver socket level. It bypasses intermediaries entirely,
making it highly portable, cross-platform, and the industry standard for high-throughput database interactions.
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 7
Q8. Detail the precise procedural steps involved in the JDBC process with corresponding code
snippets. (Repeated 3 Times: June/July 2024 Q9a, Dec 2024/Jan 2025 Q9b, Dec 2025/Jan 2026 Q10a) [10 Marks]
The Standard Step-by-Step JDBC Workflow
1. Import the Required Package API: Include the standard SQL communication interfaces inside your class
layout header via import [Link].*;.
2. Load and Register the Driver Instance: Initialize the driver implementation class file into active JVM memory
using [Link]("driver_class_name"). Modern JDBC versions handle this registration step
automatically.
3. Establish the Database Connection: Call the [Link]() factory mechanism,
passing a target database connection URL alongside valid access credentials.
4. Create an Operational Statement Object: Generate a reusable query payload engine instance by calling
[Link]() or prepareStatement().
5. Execute the SQL Query Payload: Execute the database instruction. Use executeQuery() for read
operations (which returns a ResultSet) or executeUpdate() for data mutations (DML statements like
INSERT/UPDATE).
6. Process the ResultSet Data Stream: Iterate through the cursor rows within a while([Link]()) block,
pulling column values by index or label name.
7. Close and Release Active Communication Resources: Explicitly close all active ResultSet, Statement,
and Connection handles within a finally block or via try-with-resources to prevent memory leaks.
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 8
Full Integration Code Framework
import [Link].*;
public class JdbcWorkflowDemo {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/vtu_db";
String user = "root";
String pass = "password";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Step 2: Register Driver
[Link]("[Link]");
// Step 3: Open Connection
conn = [Link](url, user, pass);
// Step 4: Create Statement
stmt = [Link]();
// Step 5 & 6: Execute and Process Query
rs = [Link]("SELECT USN, Name, Marks FROM Student");
while([Link]()) {
[Link]("USN: " + [Link]("USN") +
", Name: " + [Link]("Name") +
", Marks: " + [Link]("Marks"));
}
} catch (ClassNotFoundException | SQLException e) {
[Link]();
} finally {
// Step 7: Clean-up and Resource Release
try { if (rs != null) [Link](); } catch(SQLException se) {}
try { if (stmt != null) [Link](); } catch(SQLException se) {}
try { if (conn != null) [Link](); } catch(SQLException se) {}
}
}
}
Advanced Java (BIS402) - Complete Exam Blueprint & Solutions 9