java
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.
d) What is use of executeQuery()?
In JDBC, executeQuery() is a method on Statement or PreparedStatement used to run SQL SELECT queries. It
returns a ResultSet containing the rows returned by the query.
e) Enlist JDBC drivers.
Common JDBC driver types:
Type 1: JDBC-ODBC Bridge driver (legacy).
Type 2: Native API driver (part Java, part native code).
Type 3: Network Protocol driver (middleware server).
Type 4: Pure Java (thin) driver — recommended (connects directly to DB).
a) What is method overriding?
Answer: Method overriding is a feature in object-oriented programming that allows a subclass or child class to
provide a specific implementation of a method that is already provided by one of its superclasses or parent
classes.
The implementation in the subclass overrides the implementation in the superclass. This is a way to achieve
runtime polymorphism. The method signature (name, parameters, and return type) must be the same in both
the superclass and subclass.
b) Enlist the types of Drivers.
Answer: The four main types of JDBC drivers are JDBC-ODBC Bridge Driver, Native API Driver, Network Protocol
Driver, and Thin Driver.
Type 1: JDBC-ODBC Bridge Driver: Uses the ODBC driver to connect to the database. It is slow and not suitable
for web applications.
Type 2: Native API Driver: Uses the client-side native libraries of the database. It is faster than Type 1 but
platform-dependent.
Type 3: Network Protocol Driver: Uses a middleware (application server) to convert JDBC calls into vendor-
specific network protocol calls. It is platform-independent.
Type 4: Thin Driver: Pure Java driver that communicates directly with the database server using its specific
network protocol. It is the fastest and most widely used driver.
c) What is the use of "this" keyword?
Answer: The "this" keyword in Java is a reference variable that refers to the current object.
It has several uses:
To differentiate between instance variables and local variables when they have the same name.
To call the default constructor of the current class (using this()).
To pass the current object as an argument in method calls or constructor calls.
To return the current class instance from a method.
d) Write any three types of layout.
Answer: Three common types of layouts used in programming (e.g., Java Swing/AWT, Android, web
development) are FlowLayout, BorderLayout, and GridLayout.
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.
e) State true or false: Java supports multiple catch block (Justify).
Answer: True, Java supports multiple catch blocks.
A single try block can be followed by multiple catch blocks. Each catch block is designed to handle a specific
type of exception. When an exception occurs, the catch blocks are examined in sequence from top to bottom,
and the first one that matches the exception type is executed. This allows for handling different exceptions in
different ways within the same try-catch structure.
a) Why Java is called portable?
Answer: Java is called portable because its compiled bytecode can run on any platform that has a Java Virtual
Machine (JVM) installed.
This is often summarized by the phrase "write once, run anywhere" (WORA). The Java compiler translates
source code into an intermediate representation (bytecode) which is platform-independent. The JVM acts as a
layer between the bytecode and the underlying operating system and hardware, executing the bytecode
regardless of the specific system architecture.
b) What is super class?
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.
c) Short note on collection inter Face
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.
d) List types of layout managers
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: Java 2 Platform, Enterprise Edition
J2EE is a platform-independent, object-oriented environment for developing, building, and deploying enterprise-
level applications online. It provides a set of specifications and APIs, such as Servlets, JavaServer Pages (JSP),
Enterprise JavaBeans (EJB), and more, designed to handle the complexity of multi-tier, scalable applications.
b) What is meant by JDBC Driver?
Answer: A software component enabling a Java application to interact with a database
A JDBC (Java Database Connectivity) driver is a mechanism that allows a Java application to communicate
with a database management system (DBMS) using the standard JDBC API. It translates the standard Java
calls into the specific protocol or language required by the particular database vendor (e.g., MySQL, Oracle,
PostgreSQL).
c) Which swing classes are used to create menu?
Answer: JMenuBar, JMenu, and JMenuItem
JMenuBar: This class is used to create the menu bar which is typically placed at the top of a window or frame.
JMenu: This class is used to create actual menus within the menu bar (e.g., "File", "Edit", "Help"). A JMenu
contains JMenuItems.
JMenuItem: This class is used to create the individual items that a user can select from within a JMenu.
d) "Vector is growable or changeble size" - Justify true of false.
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.
e) List types of layout managers.
Answer: BorderLayout, FlowLayout, GridLayout, GridBagLayout, and CardLayout
Common layout managers in Java Swing and AWT include:
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 of cells, with each component occupying one cell.
GridBagLayout: A more complex and flexible layout manager that aligns components by placing them within a
grid of cells, allowing components to span multiple cells.
CardLayout: Treats each component in the container as a card or page, only one of which is visible at a time.
i) Why Java is platform-neutral language?
Answer: Java is platform-neutral because it uses a Java Virtual Machine (JVM).
Java source code is compiled into an intermediate format called bytecode, rather than machine-specific code.
This bytecode can then be executed on any system that has a JVM installed, effectively making the code "write
once, run anywhere" across different operating systems and hardware platforms.
ii) What is final class?
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.
iii) Name the classes which implement the list interface.
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.
iv) What is a listener?
Answer: A listener is an object that waits for and responds to events.
In programming, particularly in event-driven programming (like GUI development in Java with AWT/Swing), a
listener is an object that implements a specific listener interface. It contains methods that are automatically
invoked when a particular event occurs (e.g., a button click, a key press, a mouse movement), allowing the
program to react to user interactions or system events.
v) Write any two implicit object in JSP?
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.