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

Detailed Java Assignment

The document is an assignment on Java OOP concepts and applets, covering topics such as abstraction, encapsulation, method overriding, exception handling, and applet lifecycle. It includes examples and explanations of key concepts, as well as a bibliography for further reading. The assignment acknowledges the support of faculty and mentors in understanding these Java concepts.
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 views9 pages

Detailed Java Assignment

The document is an assignment on Java OOP concepts and applets, covering topics such as abstraction, encapsulation, method overriding, exception handling, and applet lifecycle. It includes examples and explanations of key concepts, as well as a bibliography for further reading. The assignment acknowledges the support of faculty and mentors in understanding these Java concepts.
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
You are on page 1/ 9

Java OOP Concepts and Applets - Assignment

Index

No Topic Page

1 Abstraction and Encapsulation in Java 2

2 Abstract Classes vs. Interfaces 3

3 Method Overriding vs. Overloading, Polymorphism, Dynamic Binding


4

4 Exception Handling in Java 5

5 Custom Exceptions in Java 6

6 Applet Lifecycle and Modern Relevance 7

7 Bibliography 8
Java OOP Concepts and Applets - Assignment

Acknowledgement
I would like to express my heartfelt gratitude to my faculty and mentors for their valuable guidance

and support throughout this assignment. Their insights helped me understand complex Java

concepts and apply them practically.


Java OOP Concepts and Applets - Assignment

1. Abstraction and Encapsulation in Java

Abstraction means hiding implementation details and showing only essential features. It helps

reduce complexity. Example:

abstract class Vehicle {

abstract void start();

Encapsulation is wrapping data and methods into a class and using access modifiers. It protects

internal data. Example:

class Person {

private String name;

public String getName() { return name; }

}
Java OOP Concepts and Applets - Assignment

2. Abstract Classes vs Interfaces

Abstract classes can have method bodies and constructors. Interfaces only define method

signatures.

Example Abstract Class:

abstract class Animal {

void eat() { System.out.println("Eating"); }

abstract void sound();

Example Interface:

interface Drawable {

void draw();

Use abstract classes when methods share code. Use interfaces for unrelated behaviors.
Java OOP Concepts and Applets - Assignment

3. Overriding vs Overloading, Polymorphism, and Dynamic Binding

Overloading: Same method name, different parameters.

Overriding: Redefining parent class method in subclass.

class Demo {

void show(int a) {}

void show(String s) {} // Overloading

class A {

void display() {}

class B extends A {

void display() {} // Overriding

Polymorphism: One interface, many implementations.

Dynamic binding: Method call resolved at runtime.


Java OOP Concepts and Applets - Assignment

4. Exception Handling in Java

Checked Exceptions: Checked at compile time. e.g., IOException

Unchecked Exceptions: Runtime errors. e.g., ArithmeticException

try {

int a = 5 / 0;

} catch (ArithmeticException e) {

System.out.println(e);

} finally {

System.out.println("Cleanup");

}
Java OOP Concepts and Applets - Assignment

5. Custom Exceptions in Java

Custom exceptions extend Exception or RuntimeException.

class AgeException extends Exception {

AgeException(String msg) { super(msg); }

Use in code:

if (age < 18) throw new AgeException("Too young");


Java OOP Concepts and Applets - Assignment

6. Applet Lifecycle and Modern Relevance

Applet lifecycle methods:

- init(): Initializes applet.

- start(): Starts applet.

- stop(): Pauses applet.

- destroy(): Frees resources.

public void init() { setBackground(Color.white); }

Modern Java no longer uses applets due to browser support removal and security issues.
Java OOP Concepts and Applets - Assignment

7. Bibliography

1. Oracle Java Documentation - https://docs.oracle.com/javase/

2. Head First Java by Kathy Sierra & Bert Bates

3. GeeksforGeeks Java Tutorials - https://www.geeksforgeeks.org/java/

4. Java: The Complete Reference by Herbert Schildt

You might also like