0% found this document useful (0 votes)
2 views2 pages

Java Exam Preparation Guide

This Java Exam Preparation Guide covers key concepts such as the differences between interfaces and abstract classes, the use of wrapper classes, and exception handling techniques. It also outlines the life cycle of an applet and provides examples of using StringBuffer methods. Each section includes definitions and code snippets to illustrate the concepts effectively.

Uploaded by

Mayank
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Java Exam Preparation Guide

This Java Exam Preparation Guide covers key concepts such as the differences between interfaces and abstract classes, the use of wrapper classes, and exception handling techniques. It also outlines the life cycle of an applet and provides examples of using StringBuffer methods. Each section includes definitions and code snippets to illustrate the concepts effectively.

Uploaded by

Mayank
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]();

You might also like