0% found this document useful (0 votes)
12 views6 pages

Unit 4

Uploaded by

Vandana Bharti
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)
12 views6 pages

Unit 4

Uploaded by

Vandana Bharti
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/ 6

Unit- 4

History of OOP

 Overview: OOP was introduced to enhance code reusability,


modularity, and problem-solving capabilities in programming.
Originated in the 1960s with Simula, evolved through Smalltalk,
C++, and Java.
 Example: Java, developed in the 1990s, popularized OOP for web-
based and enterprise applications.

2. Features of OOP

 Key Features: Encapsulation, Abstraction, Inheritance,


Polymorphism.
 Example: Java supports all core OOP features, which allow
defining and organizing code around objects and classes.

3. Object-Oriented Concepts

 Classes and Objects: Classes are blueprints; objects are instances.

java
Copy code
class Car {
String model;
void drive() { System.out.println("Driving " + model); }
}
Car myCar = new Car();
myCar.model = "Toyota";
myCar.drive(); // Output: Driving Toyota

4. Inheritance
 Concept: Allows a class to inherit properties and methods of
another class.
 Example:

java
Copy code
class Animal {
void sound() { System.out.println("Animal sound"); }
}
class Dog extends Animal {
void bark() { System.out.println("Dog barks"); }
}
Dog dog = new Dog();
dog.sound(); // Output: Animal sound
dog.bark(); // Output: Dog barks

5. Packages

 Concept: Organizes classes into namespaces for easy


management.
 Example:

java
Copy code
package com.myapp;
public class Utility { /*...*/ }

6. Interface

 Concept: Defines a contract for classes without implementing


methods.
 Example:

java
Copy code
interface Animal {
void sound();
}
class Cat implements Animal {
public void sound() { System.out.println("Meow"); }
}

7. Abstract Methods and Classes

 Abstract Class: Cannot be instantiated; may contain abstract and


non-abstract methods.
 Example:

java
Copy code
abstract class Shape {
abstract void draw();
}
class Circle extends Shape {
void draw() { System.out.println("Drawing Circle"); }
}

8. Polymorphism

 Concept: Allows objects to be treated as instances of their parent


class/interface.
 Example:

java
Copy code
Animal myAnimal = new Dog();
myAnimal.sound(); // Calls Dog's implementation

9. Inner Classes

 Concept: Classes defined within other classes.


 Example:
java
Copy code
class Outer {
class Inner {
void display() { System.out.println("Inner Class"); }
}
}
Outer.Inner inner = new Outer().new Inner();
inner.display(); // Output: Inner Class

10. String Handling

 Concept: Java provides String class and methods for manipulating


text.
 Example:

java
Copy code
String str = "Hello World";
System.out.println(str.toUpperCase()); // Output: HELLO
WORLD

11. I/O (Input/Output)

 Concept: Java’s I/O package (java.io) handles reading and writing


files.
 Example:

java
Copy code
FileReader fr = new FileReader("file.txt");
BufferedReader br = new BufferedReader(fr);

12. Networking

 Concept: Java’s java.net package facilitates network operations.


 Example:
java
Copy code
URL url = new URL("http://example.com");
BufferedReader br = new BufferedReader(new
InputStreamReader(url.openStream()));

13. Event Handling

 Concept: Used for handling actions in GUI (Graphical User


Interface) applications.
 Example:

java
Copy code
button.addActionListener(e -> System.out.println("Button
clicked"));

14. Multithreading

 Concept: Allows concurrent execution of multiple parts of a


program.
 Example:

java
Copy code
class MyThread extends Thread {
public void run() { System.out.println("Running thread"); }
}
MyThread t1 = new MyThread();
t1.start();

15. Collection Framework

 Concept: Provides data structures like List, Set, and Map for
handling collections of objects.
 Example:
java
Copy code
List<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");

16. APIs

 Concept: Java provides a rich set of APIs to simplify tasks such as


networking, XML processing, and collections management.

You might also like