Java Repeated Questions (2014–2020)
One Marker Questions (Repeated)
Q: What is inheritance?
Inheritance is the process by which one class acquires the properties and behaviors
(methods) of another class. It supports reusability and is a key feature of OOP.
Q: Why is Java platform-independent?
Java is platform-independent because Java programs are compiled into bytecode, which
can run on any device equipped with the Java Virtual Machine (JVM).
Q: What is a package? What is the use of packages in Java?
A package is a namespace that organizes classes and interfaces. It helps avoid name
conflicts and makes classes easier to locate and use.
Q: What is constructor overloading?
Constructor overloading is defining multiple constructors in a class with different sets
of parameters.
Q: What are lexical tokens?
Lexical tokens are the smallest elements of a program, such as keywords, identifiers,
literals, operators, and separators.
Q: What is the use of final variable?
A final variable in Java is a constant whose value cannot be changed once assigned.
Q: Explain public static void main(String args[]).
‘public’ allows access from anywhere, ‘static’ allows it to be called without an object,
‘void’ means no return, and ‘main’ is the entry point.
Q: What are vectors in Java? What is its purpose?
Vectors are dynamic arrays that can grow or shrink. They are synchronized and used to
store objects.
Q: What is an abstract class?
An abstract class cannot be instantiated and can contain abstract methods (without a
body) and concrete methods.
Two Marker Questions (Repeated)
Q: What is JVM (Java Virtual Machine)?
JVM is an engine that provides runtime environment to drive Java applications. It
converts bytecode into machine code.
Q: What is StringTokenizer?
StringTokenizer is a class in [Link] used to break a string into tokens based on
delimiters.
Q: What is an applet? What are different types of applets?
An applet is a small Java program that runs in a web browser. Types: local applet and
remote applet.
Q: What is the need of adapter class?
Adapter classes provide default implementations for listener interfaces so that we can
override only required methods.
Q: What are different types of errors?
1. Compile-time errors, 2. Run-time errors, 3. Logical errors.
Q: Differentiate between applet and application.
Applet: Runs in browser, no main(). Application: Standalone, has main(). Applet is GUI-
based; application can be console or GUI.
Four Marker Questions (Repeated)
Q: Explain access specifiers in Java.
Java has four access specifiers:
1. private – accessible within class
2. default – within package
3. protected – within package + subclasses
4. public – accessible everywhere
Q: Differentiate between applet and application.
Applet:
- No main()
- GUI based
- Runs in browser
Application:
- Has main()
- Can be GUI or console
- Runs standalone
Q: Write simple code to catch ArithmeticException.
```java
public class Demo {
public static void main(String[] args) {
try {
int a = 5 / 0;
} catch (ArithmeticException e) {
[Link]("Cannot divide by zero");
}
}
}
Q: Uses of final and super keywords with inheritance.
- `final`: Prevents method overriding or inheritance.
- `super`: Refers to superclass constructor or method.
Q: What are the various looping statements in Java? Explain any one.
Loops:
1. for
2. while
3. do-while
Example: while loop
```java
int i = 1;
while(i <= 5) {
[Link](i);
i++;
}
Q: What are AWT classes in Java?
AWT (Abstract Window Toolkit) provides GUI components. Examples: Button, Label,
Frame, TextField.
Q: Advantages of packages in Java.
- Avoid class name conflicts
- Easier to locate and use classes
- Controlled access
- Reusability and maintenance
Q: Differentiate between Java and C++.
- Java is platform-independent; C++ is not
- Java has garbage collection; C++ uses manual memory management
- Java doesn't support pointers directly; C++ does
Six Marker Questions (Repeated)
Q: Explain features of Java.
- Object-Oriented
- Platform Independent
- Simple
- Secure
- Robust
- Multithreaded
- High Performance
- Distributed
- Dynamic
Q: Difference between C++ and Java.
- Java is interpreted, C++ is compiled
- Java doesn't support multiple inheritance using classes
- Java is platform-independent
- Java has garbage collection
Q: Explain types of inheritance with examples.
- Single
- Multilevel
- Hierarchical
Example:
```java
class A {}
class B extends A {}
class C extends B {}
```
Q: Explain types of polymorphism in Java.
- Compile-time (method overloading)
- Run-time (method overriding)
Examples:
```java
// Overloading
int sum(int a, int b)
int sum(int a, int b, int c)
// Overriding
class A { void show() {} } class B extends A { void show() {} }
Q: Explain life cycle of an applet.
- init(): initialize
- start(): start execution
- paint(): render content
- stop(): suspend
- destroy(): cleanup
Q: Explain method overloading and overriding with examples.
- Overloading: same method name, different parameters
- Overriding: same method in subclass
Example:
```java
class A { void show() {} }
class B extends A { void show() {} }```
Q: Describe in detail the delegation event model.
- Source: Event origin
- Listener: Receives event
- Event Object: Info about event
Steps: Source generates -> Event object -> Listener handles it
Q: What is an event class? Write a program for mouse and keyboard events.
- Event classes: ActionEvent, KeyEvent, MouseEvent etc.
Example:
```java
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
[Link]("Key Pressed");
}
});
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
[Link]("Mouse Clicked");
}
});
```
Q: Explain exception handling in Java with examples.
- try: wrap risky code
- catch: handle exception
- finally: always executes
Example:
```java
try { int a = 5/0; } catch(Exception e) { [Link](e); } finally
{ [Link]("Done"); }```
Q: Explain multithreading in Java.
- Process of executing multiple threads simultaneously.
- Uses: resource sharing, better CPU utilization.
- Implemented via `Thread` class or `Runnable` interface.
Q: Explain serialization in Java.
- Process of converting object into byte stream.
- Used for saving object state.
- Implement `Serializable` interface.
Example:
```java
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("[Link]"));
[Link](obj);```