Difference Between JDK, JRE, and JVM
JDK (Java Development Kit) provides tools for developing and compiling Java programs. JRE (Java
Runtime Environment) contains the JVM and libraries needed to run Java programs. JVM (Java
Virtual Machine) executes bytecode, enabling platform independence. JDK includes both JRE and
development tools.
Difference Between Class and an Object
A class is a blueprint defining properties and behaviors (methods) of objects. An object is an
instance of a class, representing real entities with actual values. Classes define structure, while
objects use memory and perform actions based on class definitions.
Inheritance in Java and How It Is Implemented
Inheritance allows one class (subclass) to acquire properties and methods from another
(superclass). It is implemented using the extends keyword. Java supports single, multilevel, and
hierarchical inheritance, promoting code reuse and enabling polymorphism. Interfaces support
multiple inheritance in Java.
Use of Final Keyword
The final keyword restricts changes: final variables can't be reassigned, final methods can't be
overridden, and final classes can't be subclassed. It ensures immutability, prevents accidental
method modifications, and secures class definitions against further extension or misuse.
Try Block Work in Java
A try block contains code that might throw exceptions. It must be followed by one or more catch
blocks or a finally block. If an exception occurs, control passes to the appropriate catch block. It
prevents abnormal program termination.
How Do You Synchronise a Block of Code or Method in Java
Java uses the synchronized keyword to control access to code blocks or methods by multiple
threads. It ensures thread safety by allowing only one thread to execute the synchronized section at
a time, preventing data inconsistency in shared resources.
Purpose of Applet Class
The Applet class in Java is used to create programs that run within web browsers. It provides
lifecycle methods (init(), start(), stop(), destroy()) and drawing capabilities via the paint() method.
Applets were designed for interactive web content but are now outdated.
Role of an Event Listener
An event listener in Java handles events like mouse clicks or key presses. It waits for specific user
actions and responds appropriately. Interfaces such as ActionListener, MouseListener, and
KeyListener must be implemented to define behavior for corresponding events.
Layout Manager in Swing
Layout managers in Swing organize components within containers. Common managers include
FlowLayout, BorderLayout, GridLayout, and BoxLayout. They control component size, position, and
alignment, allowing flexible, dynamic UI design without manually specifying pixel coordinates.
Dialog Box in Swing
A dialog box in Swing is a pop-up window used to display messages or receive input. Classes like
JOptionPane provide predefined dialogs (message, confirm, input). Custom dialogs can be created
using JDialog. They enhance user interaction in GUI applications.