0% found this document useful (0 votes)
4 views

Java_Revision_Notes

The document provides Java revision notes covering key concepts such as exception handling, file handling, threads, multithreading, encapsulation, inheritance, polymorphism, and abstraction. Each concept is defined and illustrated with examples, demonstrating how to implement these features in Java. It serves as a concise reference for understanding fundamental Java programming principles.

Uploaded by

naveenshankar571
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)
4 views

Java_Revision_Notes

The document provides Java revision notes covering key concepts such as exception handling, file handling, threads, multithreading, encapsulation, inheritance, polymorphism, and abstraction. Each concept is defined and illustrated with examples, demonstrating how to implement these features in Java. It serves as a concise reference for understanding fundamental Java programming principles.

Uploaded by

naveenshankar571
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/ 5

Java Revision Notes

Exception Handling
Definition: Exception handling in Java is a way to handle runtime errors so the normal flow of the

program is not disrupted.

Keywords: try, catch, finally, throw, throws

Example:

try {

int result = 10 / 0;

} catch (ArithmeticException e) {

System.out.println("Cannot divide by zero.");

} finally {

System.out.println("This block always runs.");

File Handling
Definition: File handling allows Java programs to read from and write to files stored on the disk.

Example:

FileWriter writer = new FileWriter("example.txt");

writer.write("Hello, Java File Handling!");

writer.close();

BufferedReader reader = new BufferedReader(new FileReader("example.txt"));

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.

Example using Thread class:

class MyThread extends Thread {

public void run() {

System.out.println("Thread is running...");

Example using Runnable interface:

class MyRunnable implements Runnable {

public void run() {

System.out.println("Runnable thread is running...");

Multithreading
Definition: Multithreading is the process of executing multiple threads simultaneously.

Example:

class MyThread extends Thread {

public void run() {


for (int i = 1; i <= 5; i++) {

System.out.println(Thread.currentThread().getName() + " - Count: " + i);

Encapsulation
Definition: Wrapping data and methods into a single unit using private variables and public methods.

Example:

class Student {

private String name;

public void setName(String name) {

this.name = name;

public String getName() {

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");

class Dog extends Animal {

void bark() {

System.out.println("Dog barks");

Polymorphism
Definition: One method behaves differently based on the object or data.

Method Overloading:

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

double add(double a, double b) { return a + b; }

Method Overriding:

class Animal {

void sound() { System.out.println("Animal sound"); }

class Cat extends Animal {

void sound() { System.out.println("Meow"); }

Abstraction
Definition: Hiding complex implementation details and showing only essential features.
Using Abstract Class:

abstract class Shape {

abstract void draw();

class Circle extends Shape {

void draw() {

System.out.println("Drawing Circle");

Using Interface:

interface Animal {

void makeSound();

class Cow implements Animal {

public void makeSound() {

System.out.println("Moo");

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy