Java_Revision_Notes
Java_Revision_Notes
Exception Handling
Definition: Exception handling in Java is a way to handle runtime errors so the normal flow of the
Example:
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
} finally {
File Handling
Definition: File handling allows Java programs to read from and write to files stored on the disk.
Example:
writer.close();
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
reader.close();
Threads
Definition: A thread is a lightweight process. Java allows multiple threads to run concurrently.
System.out.println("Thread is running...");
Multithreading
Definition: Multithreading is the process of executing multiple threads simultaneously.
Example:
Encapsulation
Definition: Wrapping data and methods into a single unit using private variables and public methods.
Example:
class Student {
this.name = name;
return name;
Inheritance
Definition: One class inherits properties and methods from another using 'extends'.
Example:
class Animal {
void sound() {
System.out.println("Animal makes a sound");
void bark() {
System.out.println("Dog barks");
Polymorphism
Definition: One method behaves differently based on the object or data.
Method Overloading:
Method Overriding:
class Animal {
Abstraction
Definition: Hiding complex implementation details and showing only essential features.
Using Abstract Class:
void draw() {
System.out.println("Drawing Circle");
Using Interface:
interface Animal {
void makeSound();
System.out.println("Moo");