Java Exam Preparation Guide
1. Difference Between Interface and Abstract Class
- Interface: Defines abstract methods (no body) and supports multiple inheritance.
- Abstract Class: Can contain both abstract and concrete methods; supports single inheritance.
Example of Interface:
interface Animal {
void eat();
Example of Abstract Class:
abstract class Animal {
abstract void sound();
2. Wrapper Classes in Java & Static vs Non-Static Methods
- Wrapper Classes: Object representation of primitive data types (e.g., int -> Integer).
- Static Methods: Belong to the class; called without creating an object.
- Non-Static Methods: Require an object instance to be called.
3. Exception Handling in Java
- Exception: An error during program execution.
- Keywords:
- try-catch: Handle exceptions.
- finally: Executes always (cleanup).
- throw: Manually trigger an exception.
- throws: Declare exceptions in a method signature.
Example using throw and throws:
Java Exam Preparation Guide
void validate(int age) throws ArithmeticException {
if (age < 18) throw new ArithmeticException("Not eligible");
4. Life Cycle of an Applet
Applet Phases:
1. init(): Initialize resources.
2. start(): Begin execution.
3. paint(Graphics g): Draw content.
4. stop(): Pause the applet.
5. destroy(): Cleanup resources.
Example:
public void paint(Graphics g) {
[Link]("Hello Applet", 50, 50);
5. Java Program Using StringBuffer Methods
Methods:
- append(): Add to the end.
- insert(): Add at a position.
- replace(): Replace characters.
- delete(): Remove characters.
- reverse(): Reverse content.
Example:
[Link]("Java");
[Link]();