0% found this document useful (0 votes)
22 views10 pages

Document 405

The document provides a glossary of key terms related to Object-Oriented Programming (OOP) and Java exception handling, defining concepts such as abstraction, encapsulation, inheritance, and polymorphism. It also outlines the differences between checked and unchecked exceptions, exception handling syntax, and best practices for coding. Additionally, it includes common exam questions and tips for mastering Java OOP and exception handling concepts.

Uploaded by

gremasaa
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)
22 views10 pages

Document 405

The document provides a glossary of key terms related to Object-Oriented Programming (OOP) and Java exception handling, defining concepts such as abstraction, encapsulation, inheritance, and polymorphism. It also outlines the differences between checked and unchecked exceptions, exception handling syntax, and best practices for coding. Additionally, it includes common exam questions and tips for mastering Java OOP and exception handling concepts.

Uploaded by

gremasaa
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/ 10

Glossary of Key Terms

Abstraction: A process of hiding the implementation details and showing only


functionality to the user.

Applet: A special type of program that is embedded in a webpage to generate dynamic


content, running inside the browser on the client side.

Attribute (Field/Data Member/Instance Variable): Variables declared inside a class that


indicate the status of objects formed from that class.

Behavior: Represents the functionality of an object, typically implemented through


methods.

Class: A blueprint from which individual objects are created; a template or blueprint from
which objects are created.

Checked Exception: An exception that is checked (notified) by the compiler at


compilation-time, also called a compile-time exception, which must be handled by the
programmer.

Compile Time Polymorphism: Polymorphism achieved through method overloading,


resolved at compile time.

Constructor: Unique methods used to initialize class objects when an object is created.

Data Member: See Attribute.

Dynamic Method Dispatch: The mechanism by which a call to an overridden method is


resolved at runtime, which is the basis for runtime polymorphism.

Encapsulation: A process of wrapping code and data together into a single unit, protecting
data and controlling access.

Error: Problems that arise beyond the control of the user or the programmer, indicating
severe failures from which programs cannot normally recover.

Field: See Attribute.

Hierarchical Inheritance: When two or more classes inherit a single class.

Identity: An object's unique ID used internally by the JVM to identify each object uniquely.

Inheritance: When one object acquires some or all the properties and behaviors of a
parent object, providing code reusability.

Instance Variable: See Attribute.


Local Applet: An applet written and developed locally and stored in the local system.

Method: Functions defined inside a class that include the actions or behaviors that
objects of that class are capable of performing.

Method Overloading: Defining multiple methods in the same class with the same name
but different parameter lists; used for compile-time polymorphism.

Method Overriding: When a subclass provides the specific implementation of a method


that has been declared by one of its parent classes; used for runtime polymorphism.

Multi-level Inheritance: When there is a chain of inheritance (e.g., Class C inherits from
Class B, which inherits from Class A).

Multiple Inheritance: When a class inherits from more than one superclass (not directly
supported in Java for classes, but achieved through interfaces).

Object: A real-world entity that has state and behaviour; a tangible thing created from a
class blueprint.

Object-Oriented Programming (OOPs): A methodology for designing a program using


classes and objects.

Parent Class: See Super Class.

Polymorphism: The ability for one task to be performed in different ways.

Pure Object-Oriented Programming Language: A programming language where


everything is represented as an object.

Reusability: A mechanism that facilitates reusing the fields and methods of an existing
class when creating a new class.

Remote Applet: An applet designed and developed by another developer, located on a


remote computer connected to the internet.

Runtime Polymorphism: Polymorphism achieved through method overriding, resolved at


runtime.

Single Inheritance: When a class inherits another single class.

State: Represents the data (value) of an object, typically stored in fields.

Sub Class: A class that inherits from another class; also called a child class, derived
class, or extended class.
Super Class: The class from where a subclass inherits features; also called a base class
or a parent class.

Unchecked Exception: An exception that occurs at the time of execution, also called a
Runtime Exception, typically representing programming bugs and ignored at compilation
time.

convert_to_textConvert to source

Java Exception Handling: Exam-Focused Summary

1. Unchecked Exceptions

• Definition: Runtime exceptions not checked at compile-time.


• Causes: Programming errors (e.g., invalid input, logic flaws).
• Examples: int[] arr = {1, 2};
System.out.println(arr[3]); // ArrayIndexOutOfBoundsException
String s = null;
System.out.println(s.length()); // NullPointerException

• Hierarchy: Subclasses of RuntimeException.


• Handling: Optional (but recommended for robustness).

2. Exception Class Methods (Key Methods)

Method Purpose

getMessage() Returns a detailed error message.

printStackTrace() Prints stack trace to System.err (shows error origin).


toString() Returns class name + error message.

getCause() Returns the cause of the exception (if any).

getStackTrace() Returns an array of stack trace elements.

Mnemonic: "GPS-TS"

• GetMessage
• PrintStackTrace
• StackTrace (getStackTrace)
• ToString
• Suppressed (via getCause)

3. Exception Handling Syntax

Try-Catch Block

try {
// Risky code (e.g., file I/O, array access)
} catch (ExceptionType e) {
// Handle exception (e.g., log error, recover)
}

• Example: try {
int x = 10 / 0; // ArithmeticException
} catch (ArithmeticException e) {
System.out.println("Division by zero!");
}

Multiple Catch Blocks

• Order: Specific exceptions first, general (e.g., Exception) last. try {


// Code
} catch (IOException e) {
// Handle IO issues
} catch (Exception e) {
// Catch-all for other exceptions
}

Finally Block

• Purpose: Execute cleanup code (e.g., close files) always, even if an exception
occurs. try {
// Code
} catch (Exception e) {
// Handle
} finally {
// Cleanup (e.g., close database connection)
}

4. Throws vs. Throw

Keywo
Usage Example
rd

Declares exceptions a method might


throws void readFile() throws IOException
throw.

throw new
throw Explicitly throws an exception.
IllegalArgumentException()

Example:

public void deposit(double amount) throws InvalidAmountException {


if (amount < 0) {
throw new InvalidAmountException("Negative amount!");
}
}
5. Common Exam Questions

1. Q: What is the difference between throw and throws?

A: throw creates an exception; throws declares it.

2. Q: When does the finally block execute?

A: Always, unless the JVM exits (e.g., System.exit()).

3. Q: Why can’t you catch Error types?

A: Errors (e.g., OutOfMemoryError) are unrecoverable and indicate JVM failures.

6. Key Takeaways

• Checked vs. Unchecked:

Checked Unchecked

Compile-time enforcement. Runtime only (e.g., NullPointerException).

Must handle with try-catch or throws. Optional handling.

• Best Practices:
o Use try-with-resources for auto-closing streams (Java 7+).
o Log exceptions for debugging (e.g., e.printStackTrace()).
o Avoid empty catch blocks (hides errors).

Visual Mnemonic:

[Try] → [Catch] → [Finally]


↓ ↓ ↓
Code Handle Cleanup
This breakdown ensures you’ll master Java exception handling for exams!

Here's a last-minute study guide for your Java OOP exam, focusing on the most critical
topics and examples from your course material:

1. Core OOP Concepts

Class & Object

• Class: Blueprint for objects (e.g., class Employee { ... }).


• Object: Instance of a class (e.g., Employee e1 = new Employee();).
• Key Syntax: class ClassName {
// Fields (variables)
// Methods
// Constructors
}

Inheritance

• Purpose: Code reuse and polymorphism.


• Syntax: class SubClass extends SuperClass { ... }.
• Types:
o Single: A → B.
o Multilevel: A → B → C.
o Hierarchical: A → B, A → C.
o Multiple: Not supported in Java (use interfaces).
• Example: class Animal { void eat() { ... } }
class Dog extends Animal { void bark() { ... } }
Polymorphism

• Compile-Time (Static): Method overloading. class Adder {


int add(int a, int b) { return a + b; }
int add(int a, int b, int c) { return a + b + c; }
}

• Runtime (Dynamic): Method overriding. class Vehicle { void run() { ... } }


class Bike extends Vehicle { void run() { ... } } // Override

Abstraction

• Abstract Class:
o Cannot be instantiated.
o Contains abstract/non-abstract methods. abstract class Shape {
abstract void draw(); // No body
void display() { ... } // Concrete method
}

• Interface: Pure abstraction (100% abstract methods).

Encapsulation

• Goal: Protect data using private fields + public getters/setters. class Employee {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}

2. Exception Handling

• Types:
o Checked: Must be handled (e.g., IOException).
o Unchecked: Runtime errors (e.g., NullPointerException).
• Syntax: try {
// Risky code
} catch (Exception e) {
// Handle exception
} finally {
// Always executes (cleanup)
}

• Throws/Throw: void method() throws IOException { ... } // Declare


throw new IOException(); // Manually throw

3. Key Examples to Memorize

Inheritance Example

class Employee { float salary = 40000; }


class Programmer extends Employee { int bonus = 10000; }
// Output: salary=40000, bonus=10000

Polymorphism Example

class Animal { void eat() { ... } }


class Dog extends Animal { void eat() { ... } } // Override
Animal a = new Dog(); // Runtime polymorphism
a.eat(); // Calls Dog’s eat()

Encapsulation Example

Employee emp = new Employee("John", "EMP01", 50000);


emp.setSalary(60000); // Using setter
4. Applet Basics (Less Critical)

• Lifecycle Methods: init(), start(), stop(), paint(), destroy().


• Types:
o Local Applet: Stored on your system.
o Remote Applet: Downloaded from the web.

5. Common Exam Questions

1. Define polymorphism and give an example of method overriding.


2. What is the difference between abstract classes and interfaces?
3. Write a code snippet for a class with encapsulation.
4. Explain the try-catch-finally flow with an example.
5. Why does Java not support multiple inheritance?

6. Last-Minute Tips

• Focus on Code Snippets: Practice writing small classes with


inheritance/encapsulation.
• Memorize Keywords: extends, implements, abstract, throws, try/catch.
• Avoid Ambiguity:
o Overloading ≠ Overriding.
o final methods cannot be overridden.
o Static methods cannot be overridden.

You’ve got this! Prioritize understanding core OOP concepts and practice writing simple
code examples. Good luck!

You might also like