Java 1
Java 1
a) What is an Interface?
An interface in Java is a reference type that can contain only abstract methods (method signatures) and
constants (static final fields). It defines a contract: any class that implements the interface must provide
concrete implementations for its methods. Interfaces allow multiple inheritance of type (a class can implement
many interfaces).
b) Define class.
A class is a blueprint for objects. It groups data (fields/attributes) and behavior (methods). You create
instances (objects) from a class using the new keyword.
c) What is Swing?
Swing is Java’s GUI toolkit (part of Java Foundation Classes). It provides components like JFrame, JButton,
JLabel to build desktop user interfaces. Swing components are lightweight and more flexible than the older
AWT.
FlowLayout: Arranges components in a directional flow, much like lines of text in a paragraph.
BorderLayout: Arranges components into five regions: North, South, East, West, and Center.
GridLayout: Arranges components in a rectangular grid, where all components are given the same size.
Answer: A superclass (or parent class) is a class whose features (fields and methods) are inherited by a
subclass (or child class).
It is the class being extended in an inheritance relationship. Inheritance allows subclasses to reuse code and
establish a hierarchical relationship between classes, promoting code reusability and organization in object-
oriented programming.
Answer: The Collection interface is the root interface in the Java Collections Framework hierarchy.
It is a member of the [Link] package and defines the common behaviors for all collection types, such as
storing groups of objects. It provides basic operations like add(), remove(), size(), and iterator(). Interfaces like
List, Set, and Queue all extend the Collection interface.
Answer: The primary types of layout managers in Java Swing/AWT are BorderLayout, FlowLayout, GridLayout,
GridBagLayout, and CardLayout.
BorderLayout: Arranges components in five regions: North, South, East, West, and Center.
FlowLayout: Arranges components in a directional flow, typically from left to right, wrapping to the next line if
needed.
GridLayout: Arranges components in a rectangular grid, where all cells are the same size.
GridBagLayout: A flexible layout manager that aligns components vertically and horizontally along a grid,
allowing components to span multiple cells.
CardLayout: Treats each component in the container as a card or slide, only one of which is visible at a time.
e) Define Resultset
Answer:
A ResultSet is a Java object that contains the results of executing a SQL query.
It is part of the [Link] package and provides methods to traverse the data (e.g., next(), previous()) and retrieve
the values from the current row (e.g., getString(), getInt()). The ResultSet object maintains a cursor pointing to
the current row of data.
a) What is J2EE?
Answer: True
The statement is true. Vector is a class in the Java Collections Framework that implements a dynamic array.
Unlike a standard array whose size is fixed upon declaration, a Vector can dynamically grow or shrink in size as
elements are added to or removed from it.
Answer: A final class is a class that cannot be subclassed or inherited by any other class.
The final keyword in Java is used to restrict a class from being extended. This is often done for security
reasons or to ensure that the implementation of the class remains unchanged and consistent. An example of a
final class in Java's standard library is the String class.
Answer: Key classes implementing the List interface include ArrayList, LinkedList, and Vector.
ArrayList: A resizable array implementation of the List interface.
LinkedList: A doubly linked list implementation.
Vector: A thread-safe, synchronized dynamic array.
Answer: Two common implicit objects in JSP are request and response.
request: An object representing the HTTP request from the client to the server.
response: An object representing the HTTP response the server sends back to the client.
Other implicit objects include session, application, out, pageContext, config, page, and exception.
a) Explain four features of java
Answer: Object-Oriented, Platform Independent, Simple, and Secure
Explanation:
Object-Oriented: Java supports core object-oriented programming (OOP) concepts such as inheritance,
encapsulation, and polymorphism.
Platform Independent: Java code is compiled into an intermediate bytecode format that can be executed on
any system equipped with a Java Virtual Machine (JVM), regardless of the underlying operating system or
hardware.
Simple: The syntax of Java is designed to be clear and relatively easy to learn, avoiding complex features found
in some other languages.
Secure: Java provides robust security features, including bytecode verification and a sandboxing environment,
to help protect systems from malicious code.
Answer
In Java, byte streams are used for handling the input and output of raw binary data, working with 8-bit bytes.
They are fundamental for reading and writing non-textual data like images, audio files, executable programs, or
any other binary file formats.
Answer: Method overloading is a feature that allows a class to have more than one method with the same
name but different parameters.
Explanation:
Method overloading is a form of static polymorphism in Java. The methods must differ in the number of
parameters, the data type of the parameters, or the order of the data types of the parameters. The return type
alone is not sufficient to differentiate overloaded methods. This allows methods to perform similar operations
on different types or quantities of data using a single, consistent name.
Answer
MVC (Model-View-Controller) is an architectural pattern that separates an application into three interconnected
components: the Model, the View, and the Controller. This separation of concerns enhances maintainability,
scalability, and reusability, particularly in Java web applications.
1. Model:
The Model represents the application's data and business logic. It encapsulates the core data structures, rules,
and operations that govern the application's state.
In Java, the Model typically consists of Plain Old Java Objects (POJOs) or JavaBeans that represent entities
like users, products, or orders. It interacts with data sources (e.g., databases) to retrieve, store, and manipulate
data.
The Model is independent of the user interface and does not directly interact with the View or Controller. It
notifies observers (e.g., the Controller) when its state changes.
2. View:
The View is responsible for presenting the data to the user and handling user interface elements. It displays
information from the Model in a user-friendly format.
In Java web applications, Views are often implemented using technologies like JavaServer Pages (JSP),
Thymeleaf, or FreeMarker. These technologies allow for dynamic generation of HTML based on data provided
by the Model.
The View is a passive component; it does not contain business logic and primarily focuses on rendering the
presentation layer. It can receive updates from the Controller to reflect changes in the Model.
3. Controller:
The Controller acts as an intermediary between the Model and the View, handling user input and coordinating
interactions between the other two components.
In Java, Controllers are typically implemented as Servlets or Spring MVC Controllers. They receive user
requests, process them, and determine the appropriate action to take.
The Controller interprets user input, updates the Model based on the input, and then selects the appropriate
View to display the updated information. It manages the flow of control within the application
Benefits in Java:
Separation of Concerns: Clearly distinguishes data and business logic (Model), presentation (View), and input
handling (Controller).
Modularity and Reusability: Components can be developed and tested independently, and the Model can be
reused with different Views.
Testability: Easier to unit test individual components due to their isolated responsibilities.
Maintainability: Changes in one component have minimal impact on others, simplifying maintenance and
updates.
Scalability: Facilitates the development of large and complex applications by breaking them down into
manageable parts.
Ans
In Java, an exception is an event that disrupts the normal flow of a program's instructions during execution.
When an exception occurs, the program's regular execution path is interrupted, and control is transferred to an
exception handling mechanism. Exceptions are a way to signal and manage unexpected or error conditions
that a program might encounter.
Checked exceptions in Java are a specific category of exceptions that the Java compiler enforces handling for.
These exceptions are subclasses of [Link] (but not [Link]). The key
characteristic of checked exceptions is that if a method can potentially throw one, the compiler requires the
programmer to either:
Handle the exception using a try-catch block, where the potential exception-throwing code is placed within the
try block, and the catch block specifies how to respond if the exception occurs.
Declare the exception using the throws keyword in the method signature, indicating that the method might
throw this exception and delegates the responsibility of handling it to the calling method.
Ans
The extends keyword in Java is used to establish an inheritance relationship between classes or interfaces. It
signifies that a class or interface is inheriting properties and behaviors from another class or interface.
1. Class Inheritance:
When a class extends another class, it becomes a subclass (or child class) and inherits all non-private
members (fields and methods) from the superclass (or parent class). This promotes code reusability and
allows for building hierarchical structures.
Example:
Java
void eat() {
[Link](name + " is eating.");
}
}
void bark() {
[Link](name + " is barking.");
}
}
Ans
A LinkedList in Java is a part of the Collections Framework and implements both the List and Deque interfaces.
It is a linear data structure where elements are not stored in contiguous memory locations. Instead, each
element (called a node) contains the data and a reference (or link) to the next node in the sequence. In the
case of a doubly linked list (which [Link] is), each node also contains a reference to the previous
node.
Key Characteristics:
Dynamic Size: Unlike arrays, linked lists can grow or shrink dynamically as elements are added or removed.
Non-contiguous Memory: Elements are not stored in adjacent memory locations, reducing the need for shifting
elements during insertions or deletions.
Efficient Insertions/Deletions: Adding or removing elements at the beginning or end is very efficient (O(1)).
Inserting or deleting in the middle requires traversing to the desired position, which can be O(n).
Inefficient Random Access: Accessing an element at a specific index requires traversing the list from the
beginning (or end for doubly linked lists), making random access less efficient than arrays (O(n)).
try: A block of code that is monitored for exceptions. If an exception occurs within the try block, it is caught by
an associated catch block.
catch: A block of code that handles a specific type of exception thrown by the try block. A single try block can
have multiple catch blocks.
finally: A block of code that is executed after the try block and catch block(s), regardless of whether an
exception was thrown or caught. It is typically used for cleanup operations like closing resources
BorderLayout: Arranges components in five regions: North, South, East, West, and Center.
FlowLayout: Arranges components in a directional flow, typically from left to right, wrapping to the next line
when the container is full.
GridLayout: Arranges components in a rectangular grid, where all cells are of the same size.
GridBagLayout: A flexible layout manager that aligns components by placing them within a grid of cells,
allowing components to span multiple cells.
Answer: JDBC (Java Database Connectivity) architecture consists of four main components.
Application Layer: The Java application that uses the JDBC API to interact with the database.
JDBC API: Provides the interfaces and classes for the application to connect to the database and execute SQL
queries.
JDBC Driver Manager: Manages the different types of database drivers. It loads the appropriate driver for the
specified database connection URL.
JDBC Driver: A software component that enables the JDBC Driver Manager to communicate with a specific
database vendor's protocol. Common types are Type 1 (JDBC-ODBC bridge), Type 2 (Native-API driver), Type 3
(Network-Protocol driver), and Type 4 (Thin driver/Pure Java driver).
Answer: The JSP (JavaServer Pages) life cycle is similar to the servlet life cycle and involves several stages
managed by the web container.
Translation: The web container translates the JSP page into a servlet source file (a Java file).
Compilation: The generated servlet source file is compiled into a servlet class file (.class file).
Loading: The container loads the servlet class file into memory.
Initialization (jspInit()): The container calls the jspInit() method once to initialize the servlet instance.
Request Processing (jspService()): The container calls the jspService() method for every client request. This
method generates the response.
Destruction (jspDestroy()): The container calls the jspDestroy() method once before the servlet instance is
destroyed.
Ans
Garbage Collection (GC) in Java is an automatic memory management process that identifies and reclaims
memory occupied by objects that are no longer reachable or used by the application. This process helps
prevent memory leaks and ensures efficient use of the heap memory.
Benefits of Garbage Collection:
Automatic Memory Management: Developers do not need to manually deallocate memory, reducing the risk of
memory leaks and improving developer productivity.
Reduced Memory Leaks: By automatically cleaning up unused objects, GC helps prevent the accumulation of
memory that is no longer needed, which can lead to application performance issues or crashes.
Improved Performance: Efficient memory management can contribute to better application performance by
ensuring that sufficient memory is available for active objects.
Ans
In Java, an interface defines a contract for classes to adhere to, specifying a set of methods that implementing
classes must provide. Interfaces achieve abstraction and support multiple inheritance of type.
Defining an Interface:
An interface is declared using the interface keyword. It can contain:
Abstract Methods: Methods without a body, which must be implemented by any class that implements the
interface. Prior to Java 8, all methods were implicitly public abstract.
Default Methods (Java 8+): Methods with an implementation, allowing interfaces to evolve without breaking
existing implementations. Declared with the default keyword.
Static Methods (Java 8+): Methods with an implementation that belong to the interface itself, not to
implementing classes. Declared with the static keyword.
Private Methods (Java 9+): Helper methods for default and static methods within the interface. Declared with
the private keyword.
Constants: public static final variables, which are implicitly declared as such.
Here's an example:
Java
Ans
Scripting elements in JavaServer Pages (JSP) provide the ability to embed Java code directly within HTML
content, allowing for the generation of dynamic web pages. These elements are processed by the JSP engine
during the translation of the JSP page into a servlet.
Here are two types of JSP scripting elements: scriptlet tag.
The scriptlet tag allows the embedding of Java code fragments within the JSP page. This code is executed as
part of the _jspService() method of the generated servlet. It is used for implementing logic, performing
calculations, or interacting with objects within the JSP.
Java
<%
int count = 0;
for (int i = 0; i < 5; i++) {
count += i;
}
[Link]("The sum is: " + count);
%>
expression tag.
The expression tag is used to evaluate a Java expression and print its result directly into the output HTML. The
result of the expression is converted to a string and sent to the client's browser. It provides a concise way to
display variable values or method return values.
Java
Ans
JDBC drivers enable Java applications to interact with various database systems. There are four main types of
JDBC drivers, each with distinct characteristics:
Type 1: JDBC-ODBC Bridge Driver
Mechanism: This driver translates JDBC calls into ODBC calls, which are then handled by the database's ODBC
driver.
Characteristics: It requires an ODBC driver to be installed on the client machine. This type is generally slower
due to the two-step translation process and is platform-dependent, typically limited to Windows. This driver
type is now largely deprecated in modern Java versions.
Type 2: Native-API Driver (Partially Java Driver)
Mechanism: This driver converts JDBC calls into native database-specific API calls. It relies on a native client
library provided by the database vendor.
Characteristics: It offers better performance than Type 1 but requires the native client library to be installed on
the client machine, making it platform-dependent.
Type 3: Network Protocol Driver (Middleware Driver)
Mechanism: This driver utilizes a middleware server to translate JDBC calls into a database-independent
network protocol. The middleware server then communicates with the specific database.
Characteristics: It is fully Java-based on the client side and offers platform independence. It can connect to
multiple database types through a single middleware server. However, it introduces an extra layer of complexity
due to the middleware server's maintenance and potential performance overhead.
Type 4: Pure Java Direct-to-Database Driver (Thin Driver)
Mechanism: This driver is entirely written in Java and directly converts JDBC calls into the database's native
network protocol. It communicates directly with the database server using network sockets.
Characteristics: It is the most commonly used type due to its pure Java implementation, offering excellent
performance, platform independence, and ease of deployment as it requires no client-side native libraries or
middleware.
Ans
Accessing and creating classes within packages is a fundamental concept in object-oriented programming,
particularly in languages like Java.
Theory:
Packages in Java serve as a mechanism to organize classes and interfaces into logical groups, preventing
naming conflicts and providing a level of access control. When you create a class within a package, you are
essentially placing it within a specific namespace. To use a class from one package in another package, you
must either import the class or use its fully qualified name.
Creating a Class in a Package:
Declare the package: The first statement in your Java source file (before any class declarations) must be the
package declaration, specifying the package name.
Define the class: Define your class as usual within the same file.
Example (Creating):
Consider a package named [Link] and a class MyClass within it.
Java
// [Link]
package [Link];
// [Link]
import [Link]; // Option 1: Importing the class
***What is overriding
Ans
Method overriding in Java is a feature of object-oriented programming that allows a subclass to provide a
specific implementation for a method that is already defined in its superclass. This enables a child class to
have its own unique behavior for an inherited method.
class Vehicle {
void move() {
[Link]("Vehicle is moving.");
}
}
Ans
Runtime polymorphism, also known as dynamic method dispatch, is a mechanism in Java where the method
call to an overridden method is resolved at runtime, not at compile time. This is achieved through method
overriding and upcasting.
Method Overriding: A subclass provides a specific implementation for a method that is already defined in its
superclass, maintaining the same method signature (name, return type, and parameters).
Upcasting: A reference variable of a superclass refers to an object of its subclass.
Example:
Consider a scenario with an Animal superclass and Dog and Cat subclasses. All classes have a makeSound()
method.
Java
class Animal {
public void makeSound() {
[Link]("The animal makes a sound.");
}
}
Ans
A wrapper class in Java is a class whose objects encapsulate primitive data types, allowing them to be treated
as objects. Primitive data types in Java (like int, char, boolean, double) are not objects, but there are situations
where they need to behave as objects, such as when working with Java Collections Framework (e.g., ArrayList,
HashMap), or when using generics. Wrapper classes provide this functionality by "wrapping" the primitive value
within an object.
Each primitive data type in Java has a corresponding wrapper class:
byte -> Byte, short -> Short, int -> Integer, long -> Long, float -> Float, double -> Double, char -> Character, and
boolean -> Boolean.
Example:
Java
public class WrapperClassExample {
public static void main(String[] args) {
// Primitive int
int primitiveInt = 10;
char ch = 'a';
[Link]("Is 'a' a letter? " + [Link](ch));
}
}
Ans
In Java web applications, particularly those built with Servlets and JSP, cookies and HTTP sessions are two
fundamental mechanisms for maintaining state between client requests in an otherwise stateless HTTP
protocol.
Cookies:
Cookies are small pieces of textual information that a web server sends to a client's web browser as part of an
HTTP response. The browser then stores these cookies and sends them back to the server with subsequent
requests to the same domain. Cookies are primarily used for:
Session Management: Storing a unique session ID to identify a user's session.
User Preferences: Remembering user-specific settings like language, theme, or login status.
Tracking: Analyzing user behavior on a website.
In Java Servlets, you interact with cookies using the [Link] class.
Java
// Creating a cookie
Cookie userCookie = new Cookie("username", "JohnDoe");
[Link](60 * 60 * 24); // Cookie expires in 24 hours
[Link](userCookie); // Adding the cookie to the response
// Retrieving cookies from a request
Cookie[] cookies = [Link]();
if (cookies != null) {
for (Cookie cookie : cookies) {
if ([Link]().equals("username")) {
String username = [Link]();
// ...
}
}
}
HTTP Session:
An HTTP session, represented by the [Link] interface in Java, provides a server-side
mechanism to store and manage client-specific data across multiple requests from the same user. Unlike
cookies, which are stored on the client, session data resides on the server. The server typically uses a session
ID (often stored in a cookie or URL rewriting) to associate incoming requests with the correct session object.
HTTP sessions are used for:
Storing Sensitive Data: User authentication details, shopping cart contents, or other data that should not be
exposed on the client.
Maintaining Application State: Tracking a user's progress through a multi-step process or storing temporary
data.
Java
***d) Define:
i) Treeset Answer: A Java TreeSet is a class that implements the Set interface and extends AbstractSet to store
unique elements in a sorted order. It uses a self-balancing binary search tree (typically a Red-Black tree)
internally for storage. .CM8kHf text{fill:var(--m3c11)}.CM8kHf{font-size:1.15em}.j86kh{display:inline-block;max-
width:100%}
ii) Hashmap Answer: A Java HashMap is a class that implements the Map interface and stores data in key-
value pairs. It uses hashing to store and retrieve elements, providing fast lookup times (average \(O(1)\)) but
does not guarantee any specific order of elements.
iii) Treemap Answer: A Java TreeMap is a class that implements the NavigableMap interface and extends
AbstractMap, storing data in key-value pairs sorted according to the natural ordering of its keys or by a custom
Comparator. It uses a Red-Black tree structure internally.
iv) Array List Answer: A Java ArrayList is a class that implements the List interface and stores a dynamically
resizable array of elements. It allows for fast random access of elements by index but can be slow for
insertions and deletions in the middle of the list.
v) Linked List Answer: A Java LinkedList is a class that implements both the List and Deque interfaces, storing
elements as a doubly linked list. It provides efficient insertions and deletions at any position (average \(O(1)\)
at ends, \(O(n)\) in middle), but slower random access to elements by index compared to an ArrayList.
Ans
In Java, the static keyword is a non-access modifier used for fields (variables) and methods. It signifies that the
field or method belongs to the class itself, rather than to any specific instance (object) of that class.
Static Fields (Class Variables):
A static field is a variable that belongs to the class, not to individual objects.
There is only one copy of a static field, shared by all instances of the class. If you change the value of a static
field through one object, the change will be visible to all other objects of that class.
Static fields are initialized when the class is loaded into memory, before any objects are created.
They are commonly used for constants (when combined with final), or for data that needs to be shared across
all instances, such as a counter for objects created.
Example:
Java
class Parent {
public final void displayMessage() {
[Link]("This is a final method in the Parent class.");
}
}
Ans
Exception handling in Java is a mechanism designed to manage runtime errors and other unexpected events
that can disrupt the normal flow of a program. It provides a structured way to detect, report, and recover from
these "exceptions," preventing the application from crashing and enhancing its robustness and reliability.
The core components of exception handling in Java are:
try block: This block encloses the code that might potentially throw an exception.
Java
try {
// Code that might throw an exception
}
catch block: This block immediately follows a try block and is executed if an exception of a specific type
occurs within the try block. It contains the code to handle the exception.
Java
catch (ExceptionType e) {
// Code to handle the exception
}
finally block: This optional block follows try-catch blocks and is guaranteed to execute, regardless of whether
an exception occurred or was caught. It is typically used for cleanup operations, such as closing resources
(files, network connections, etc.).
Java
finally {
// Code that always executes
}
throw keyword: Used to explicitly throw an exception from within a method.
Java
Ans
Session tracking in Java web applications refers to the techniques used to maintain the state of a user across
multiple HTTP requests. This is crucial because HTTP is a stateless protocol, meaning each request is treated
independently by the server, without any inherent knowledge of previous interactions from the same user.
Session tracking allows the server to recognize and remember a specific user throughout their interaction with
the application, providing a personalized and consistent experience.
There are four primary methods for session tracking in Java Servlets:
Cookies:
Mechanism: The server sends a small piece of data (a cookie) to the client's browser, which stores it. On
subsequent requests to the same domain, the browser automatically sends the cookie back to the server. This
cookie typically contains a session ID that the server uses to identify the user's session.
Implementation: In Java Servlets, you can create and manage cookies using the [Link]
class.
Limitations: Users can disable cookies in their browsers, and cookies have size limitations.
Hidden Form Fields:
Mechanism: Information, including a session ID, is embedded within hidden fields within HTML forms. When
the user submits a form, this hidden data is sent along with other form data to the server.
Implementation: You would dynamically generate HTML forms with hidden fields containing session-related
data.
Limitations: This method only works when users interact with forms, and it can become cumbersome for
applications with many pages or complex navigation.
URL Rewriting:
Mechanism: A unique session ID or other session-related data is appended to the URL of every link and form
action within the application. When the user clicks a link or submits a form, the modified URL is sent to the
server, carrying the session information.
Implementation: Servlets provide methods like [Link]() to automatically rewrite URLs with
session IDs.
Limitations: URLs become longer and less user-friendly, and users can potentially bookmark or share URLs
with embedded session IDs, which might pose a security risk.
HTTP Session (HttpSession):
Mechanism: This is the most common and robust method. The server creates an HttpSession object for each
new user session and assigns a unique session ID. This ID is typically sent to the client as a cookie (if
supported by the browser) or through URL rewriting. The HttpSession object stores user-specific data on the
server side.
Implementation: In Servlets, you can obtain the HttpSession object using [Link](). You can then
store and retrieve attributes (key-value pairs) within the session using methods like setAttribute() and
getAttribute().
Advantages: Provides a convenient and secure way to manage session data, automatically handles session ID
management, and offers features like session timeout.
In summary, session tracking in Java is essential for creating stateful web applications that can personalize
user experiences. While cookies, hidden form fields, and URL rewriting offer basic mechanisms, the
HttpSession object provides a powerful and widely adopted solution for managing user sessions and their
associated data on the server side.
Ans
A servlet is a Java class that runs on a web or application server to handle client requests and generate
dynamic responses. There are two main types: GenericServlet, which is protocol-independent and can be used
for any protocol, and HttpServlet, which is protocol-specific to HTTP and is the more commonly used type for
web applications.
GenericServlet
Purpose: A generic servlet is designed to be protocol-independent, making it a general-purpose server-side
component.
Implementation: It is created by extending the [Link] abstract class.
Key method: You must implement the service() method to handle requests and responses.
Use case: Since GenericServlet is not tied to a specific protocol, it's often used as a base class for creating
protocol-specific servlets, though you would typically extend HttpServlet for web applications.
HttpServlet
Purpose: This is a protocol-specific servlet for handling HTTP requests, which are the standard for web
communication.
Implementation: It is created by extending the [Link] class.
Key methods: It provides default methods for different HTTP request types, such as:
doGet(): For handling GET requests.
doPost(): For handling POST requests.
doPut(): For handling PUT requests.
Use case: HttpServlet is the most common type for building web applications because it provides built-in
support for the HTTP protocol, including methods to handle different HTTP request types.
Advantage: By extending HttpServlet, you get default implementations for many HTTP-related tasks, making it
easier to develop web applications than with GenericServlet.
Lifecycle: The servlet lifecycle methods are init(), service(), and destroy().
Ans
JSP directives provide instructions to the JSP container during the translation phase, guiding how the JSP
page is processed and converted into a servlet. They offer global information about the entire JSP page and do
not appear in the final output. There are three main types of JSP directives:
Page Directive:
Purpose: Defines page-dependent attributes and communicates them to the JSP container. It influences how
the entire JSP page is handled.
Syntax: <%@ page attribute="value" %>
Common Attributes:
import: Imports Java classes or packages, similar to Java's import statement.
Java