📚 COMPLETE EXAM SOLUTIONS - ALL
SUBJECTS
🔷 ADVANCE OBJECT TECHNOLOGY (AOT)
2-Mark Questions
1. Define DHTML.
Dynamic HTML (DHTML) is a combination of HTML, CSS, JavaScript, and DOM that allows for
the creation of interactive and animated web pages without requiring server-side scripting.
Key Features:
● Real-time content modification
● Event handling without page reload
2. What is innerHTML?
innerHTML is a JavaScript property used to set or return the HTML content inside a specific
element.
Example:
[Link]("demo").innerHTML = "Hello World";
3. Differentiate DOM vs SAX.
Feature DOM Parser SAX Parser
Type Tree-based Event-based
Memory High (loads entire XML) Low (sequential reading)
Access Random access Sequential only
Speed Slower Faster
Modification Supports Does not support
4. What is CDATA in XML?
CDATA (Character Data) is a section in an XML document where text is ignored and not
parsed by the XML parser.
Syntax:
<![CDATA[This text can contain <, >, & symbols]]>
5. Define JavaBean.
A JavaBean is a reusable software component written in Java that adheres to specific
conventions:
● Properties are private
● Public getter/setter methods
● Implements the Serializable interface
● Contains a no-argument constructor
6. What is Introspection in JavaBeans?
Introspection is the process of analyzing a bean's properties, methods, and events at runtime
using the BeanInfo interface and the Reflection API.
7. Differentiate AWT vs Swing.
Feature AWT Swing
Platform Platform-dependent Platform-independent
Components Heavy-weight Light-weight
Look & Feel Native OS Pluggable
Package [Link].* [Link].*
8. What is Servlet Chaining?
Servlet Chaining is a process where the output of one servlet is passed as the input to another
servlet.
Example: Servlet1 → Servlet2 → Client
9. Define JSP Implicit Objects.
JSP Implicit Objects are pre-created Java objects available in JSP pages without requiring
explicit declaration. These include:
● request, response, out, session, application, config, pageContext, page, exception
10. What is the errorPage directive in JSP?
The errorPage directive specifies the target JSP page that will handle exceptions thrown by
the current page.
Syntax:
<%@ page errorPage="[Link]" %>
11. Define RMI.
RMI (Remote Method Invocation) is an API that allows Java objects to invoke methods on
objects running in different Java Virtual Machines (remote hosts).
12. What is MVC architecture?
MVC (Model-View-Controller) is a fundamental software design pattern:
● Model: Handles business logic and data.
● View: Manages the presentation layer.
● Controller: Processes and routes user requests.
13. What is Session Tracking?
Session Tracking is a mechanism used to maintain a user's state across multiple HTTP
requests. It is commonly achieved using:
● Cookies, URL Rewriting, Hidden Form Fields, and HttpSession.
14. Define the Applet lifecycle.
The Applet Lifecycle consists of five core methods:
1. init() → Start initialization
2. start() → Begin execution
3. paint() → Display content
4. stop() → Pause execution
5. destroy() → Clean up resources
8-Mark Questions
1. Explain JavaScript objects and variable scoping with an example.
JavaScript Objects:
Objects in JavaScript are collections of key-value pairs.
Example:
// Object Literal
var person = {
name: "John",
age: 30,
greet: function() {
return "Hello " + [Link];
}
};
// Constructor Function
function Car(brand, model) {
[Link] = brand;
[Link] = model;
}
var myCar = new Car("Toyota", "Camry");
Variable Scoping:
1. Global Scope: Variables declared outside any function are globally accessible.
var globalVar = "I am global";
function test() {
[Link](globalVar); // Accessible
}
2. Function Scope: Variables declared inside a function are accessible only within that
function.
function myFunc() {
var localVar = "I am local";
[Link](localVar); // Accessible
}
[Link](localVar); // Error: Not accessible outside
3. Block Scope (let/const): Variables scoped to the nearest enclosing block.
if (true) {
let blockVar = "I am block scoped";
const PI = 3.14;
}
[Link](blockVar); // Error: Not accessible
Key Takeaways:
● var provides Function scope.
● let/const provide Block scope.
● Variables without a declaration keyword default to Global scope.
2. Write a short note on XML DTD and Entities.
Document Type Definition (DTD):
A DTD defines the document structure with a list of legal elements and attributes.
Types:
1. Internal DTD: Declared inside the XML file.
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
]>
2. External DTD: Links to an external .dtd file.
<!DOCTYPE note SYSTEM "[Link]">
DTD Components:
● ELEMENT: Defines an XML element.
● ATTLIST: Defines attributes for elements.
● ENTITY: Defines shortcuts to special characters/text.
● NOTATION: Declares the format of unparsed external data.
XML Entities:
Entities are shortcuts used to represent special characters or reusable text blocks.
Types:
1. Predefined Entities:
< → <
> → >
& → &
" → "
' → '
2. User-defined Entities:
<!ENTITY author "John Doe">
<!ENTITY copyright "Copyright &author; 2024">
<document>©right;</document>
3. External Entities:
<!ENTITY chapter1 SYSTEM "[Link]">
3. Explain Servlet security issues.
Servlet Security Challenges:
1. Authentication Issues:
● Weak password policies.
● Session hijacking.
● Insecure credential storage.
2. Authorization Problems:
● Improper access controls.
● Privilege escalation.
● Missing role-based validation.
3. Common Vulnerabilities:
a) SQL Injection:
// Vulnerable Code
String query = "SELECT * FROM users WHERE username='" + username + "'";
// Secure Code
PreparedStatement ps = [Link]("SELECT * FROM users WHERE username=?");
[Link](1, username);
b) Cross-Site Scripting (XSS):
// Vulnerable
[Link]([Link]("name"));
// Secure
String name = StringEscapeUtils.escapeHtml4([Link]("name"));
[Link](name);
c) Session Fixation:
// Secure: Regenerate session ID after login
HttpSession oldSession = [Link](false);
if (oldSession != null) [Link]();
HttpSession newSession = [Link](true);
Security Best Practices:
● Enforce HTTPS for all data transmission.
● Implement strict input validation and sanitization.
● Use PreparedStatement to query databases.
● Implement CSRF tokens.
● Conduct regular security audits.
4. Explain any four Swing components with code.
1. JFrame (Main Window):
import [Link].*;
public class FrameExample {
public static void main(String[] args) {
JFrame frame = new JFrame("My Application");
[Link](400, 300);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](true);
}
}
2. JButton (Clickable Button):
JButton btn = new JButton("Click Me");
[Link](100, 100, 100, 40);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](null, "Button Clicked!");
}
});
[Link](btn);
3. JTextField (Input Field):
JTextField textField = new JTextField();
[Link](50, 50, 150, 30);
[Link](textField);
// Get text
String text = [Link]();
4. JLabel (Display Text/Image):
JLabel label = new JLabel("Enter Name:");
[Link](50, 20, 100, 30);
[Link](label);
// Image Label
ImageIcon icon = new ImageIcon("[Link]");
JLabel imgLabel = new JLabel(icon);
5. Difference between Servlet and JSP.
Aspect Servlet JSP
Type Java class Text-based document
MVC Role Controller View
Code Structure HTML embedded in Java Java embedded in HTML
Modification Requires manual Auto-recompilation by the
recompilation server
Package [Link].* Converted to a servlet
internally
Performance Faster (already compiled) Slower initially (translation
phase)
Syntax Standard Java syntax Tag-based + scriptlets
Best for Complex business logic Presentation and UI
Servlet Code Example:
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
[Link]("text/html");
PrintWriter out = [Link]();
[Link]("<html><body>");
[Link]("<h1>Hello World</h1>");
[Link]("</body></html>");
}
JSP Code Example:
<html>
<body>
<h1>Hello World</h1>
<%
String name = [Link]("name");
[Link]("Welcome " + name);
%>
</body>
</html>
6. Explain JSP Scripting Elements with syntax.
1. Scriptlet Tag (<% %>):
Contains Java code that is executed every time the JSP is requested.
<%
String name = "John";
int age = 25;
[Link]("Name: " + name);
%>
2. Expression Tag (<%= %>):
Evaluates a Java expression and prints the output directly (does not require a semicolon).
<p>Current Time: <%= new [Link]() %></p>
<p>Sum: <%= 5 + 10 %></p>
3. Declaration Tag (<%! %>):
Declares variables and methods at the class level (outside the _jspService method).
<%!
int counter = 0;
public int getSquare(int n) {
return n * n;
}
%>
<p>Square of 5: <%= getSquare(5) %></p>
4. Directive Tag (<%@ %>):
Provides page-level instructions to the JSP container.
<%@ page language="java" contentType="text/html" %>
<%@ include file="[Link]" %>
<%@ taglib uri="[Link] prefix="c" %>
5. Comment Tag (<%-- --%>):
JSP-specific comments that do not appear in the generated HTML source.
<%-- This is a server-side JSP comment --%>
<!-- This is a client-side HTML comment -->
16-Mark Questions
Unit-I: Explain Applet lifecycle with diagram.
Introduction:
An Applet is a special type of Java program that runs within a web browser or an applet viewer.
The browser's JVM manages its lifecycle through five key methods inherited from
[Link].
Applet Lifecycle Stages:
1. Initialization Phase - init():
● Characteristics: Called only once, first method invoked, used for one-time setup.
public void init() {
setBackground([Link]);
message = "Applet Initialized";
}
2. Start Phase - start():
● When Called: After init(), when the user returns to the page, or after stop(). Used to
resume tasks like threads or animations.
public void start() {
thread = new Thread(this);
[Link]();
}
3. Paint Phase - paint(Graphics g):
● Triggers: After start(), when the window is resized/uncovered, or when repaint() is called.
public void paint(Graphics g) {
[Link]("Hello Applet", 20, 30);
[Link](10, 10, 100, 50);
}
4. Stop Phase - stop():
● When Called: When the user navigates away from the page, or the browser is minimized.
Used to suspend heavy processes.
public void stop() {
if(thread != null) {
[Link]();
thread = null;
}
}
5. Destroy Phase - destroy():
● When Called: Once, when the applet is completely removed from memory.
public void destroy() {
// Final cleanup of resources
}
Lifecycle Flow:
1. Browser loads page → init()
2. Applet begins → start()
3. Applet displays → paint()
4. User leaves page → stop()
5. User returns → start() → paint()
6. Browser closes → destroy()
Note: Modern web development has largely moved away from Java Applets in
favor of HTML5, CSS3, and JavaScript frameworks.
Unit-I: Explain DOM vs SAX parser in detail.
Introduction:
XML parsers interpret XML documents to extract their structure and data. The two primary
parsing approaches in Java are DOM (Document Object Model) and SAX (Simple API for
XML).
1. DOM PARSER (Document Object Model)
● Architecture: XML Document → DOM Parser → Memory-Resident Tree Structure →
Application Access.
● How it Works: It reads the entire XML file and maps it to a tree of Node objects in RAM.
● Features: Random access, supports read/write modifications, supports XPath.
Advantages:
● Navigate forwards and backwards easily.
● You can modify, add, or delete nodes directly.
● Maintains full document hierarchy visually.
Disadvantages:
● High memory footprint (bad for massive files).
● Slower initialization time due to complete tree construction.
2. SAX PARSER (Simple API for XML)
● Architecture: XML Document → SAX Parser → Sequential Events → Event Handlers →
Application.
● How it Works: It reads the file sequentially from top to bottom, triggering callback
methods (startElement, characters, endElement) without storing the document in
memory.
● Features: Event-driven, streaming, forward-only read access.
Advantages:
● Extremely low memory usage.
● Fast and efficient, easily handles gigabyte-sized files.
● Real-time processing.
Disadvantages:
● Read-only (cannot modify the XML structure).
● Sequential only (no random access or backward navigation).
● More complex state management required in code.
Comprehensive Comparison:
Feature DOM Parser SAX Parser
Parsing Style Tree-based Event-based
Memory Profile High Low
File Size Suitability Small to medium (< 10MB) Large files (GBs)
Navigation Forward & Backward Forward only
Modification Read and Write Read-only
Speed Slower startup Faster (streams on the fly)
XPath Support Yes No
Package [Link].* [Link].*
Unit-II: Compare AWT vs Swing. Explain any six Swing components with a
diagram.
PART A: AWT VS SWING COMPARISON
Architecture Differences:
● AWT: Maps Java components directly to native OS widgets (heavy-weight). Appearance
changes across OS.
● Swing: Renders its own components using Java 2D graphics (light-weight). Looks
identical everywhere.
Feature AWT Swing
Component Weight Heavy-weight (Native OS Light-weight (Pure Java
dependent) rendered)
Platform Platform-dependent UI Platform-independent UI
Customization Very Limited Extensive (Borders, tooltips,
pluggable Look-and-Feel)
MVC Architecture No Yes
Performance Slightly faster UI rendering Slightly heavier memory usage
Namespaces Button, TextField JButton, JTextField
PART B: SIX SWING COMPONENTS EXPLAINED
1. JFrame (Main Window Container)
The top-level window container that holds all other Swing components. Includes a title bar,
borders, and close/minimize buttons.
● Key Methods: setSize(), setDefaultCloseOperation(), setVisible().
2. JButton (Clickable Button)
A component used to trigger action events. Supports text, icons, and keyboard mnemonics.
● Key Methods: addActionListener(), setIcon(), setEnabled().
3. JTextField (Text Input Field)
A single-line input field that allows the user to type text. Can be set to read-only.
● Key Methods: getText(), setText(), setEditable().
4. JLabel (Display Component)
A read-only component used to display short text strings, images (icons), or both. Supports
basic HTML rendering.
● Key Methods: setText(), setIcon(), setHorizontalAlignment().
5. JComboBox (Dropdown List)
Provides a drop-down menu allowing users to select an item from a list. Can optionally be
made editable to allow custom input.
● Key Methods: addItem(), getSelectedItem(), setSelectedIndex().
6. JTable (Tabular Data Display)
A highly flexible component used to display and edit complex 2D tabular data (rows and
columns). Backed by a TableModel.
● Key Methods: getValueAt(), setValueAt(), getSelectedRow().
Unit-II: What are JavaBeans? Explain its properties types and advantages.
Introduction:
JavaBeans are specialized Java classes used to encapsulate multiple objects into a single
reusable component. They are designed for visual manipulation in IDE builders.
Core Rules for a JavaBean:
1. Implements [Link].
2. Has a public no-argument constructor.
3. Class attributes must be private.
4. Must provide public get() and set() accessor methods.
TYPES OF PROPERTIES IN JAVABEANS:
1. Simple Properties:
Standard properties representing a single value with a basic getter and setter.
● Example: getName(), setName(String name)
2. Boolean Properties:
Properties representing true/false. Uses is instead of get.
● Example: isActive(), setActive(boolean state)
3. Indexed Properties:
Properties that handle arrays or collections, allowing access via an index.
● Example: getStudents(int index), setStudents(int index, String student)
4. Bound Properties:
Properties that notify registered listeners (PropertyChangeSupport) whenever their value is
changed. Excellent for UI data binding.
● Mechanism: Triggers a PropertyChangeEvent.
5. Constrained Properties:
Similar to bound properties, but changes to this property can be actively vetoed or rejected by
listeners (VetoableChangeSupport).
● Mechanism: Throws a PropertyVetoException if the new value is rejected.
ADVANTAGES OF JAVABEANS:
1. High Reusability: Written once and shared across multiple enterprise or GUI projects as
standard components.
2. Platform Independence: 100% pure Java; runs perfectly on any JVM without requiring
native library hooks.
3. Introspection Support: Through the Introspector class, tools can automatically
dynamically discover the properties, events, and methods a Bean exposes at runtime.
4. Event Handling: Adheres to the standard Java delegation event model, making it easy to
create reactive, event-driven architectures.
5. Persistence: Built-in design constraint to implement Serializable guarantees that beans
can save their state (to databases, files, or network streams) effortlessly.
6. Visual Development: Easily integrated into IDEs (like Eclipse or NetBeans GUI Builders)
allowing developers to tweak properties via visual property sheets rather than writing
boilerplate setup code.