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

Exp1 Java

The document outlines an experiment focused on Object Oriented Programming (OOP) concepts in Java, including class, object, encapsulation, inheritance, polymorphism, and abstraction. It also covers Java Input and Output (IO) Streams, detailing types of streams and their applications, along with an algorithm for file handling operations. A sample Java code demonstrates creating a text file, reading from it, and copying its contents to another file.

Uploaded by

kong026lol
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Exp1 Java

The document outlines an experiment focused on Object Oriented Programming (OOP) concepts in Java, including class, object, encapsulation, inheritance, polymorphism, and abstraction. It also covers Java Input and Output (IO) Streams, detailing types of streams and their applications, along with an algorithm for file handling operations. A sample Java code demonstrates creating a text file, reading from it, and copying its contents to another file.

Uploaded by

kong026lol
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name : Anamika Chauhan

PRN : 246109049

Batch : SB3

Expirement 1

Aim
To study and understand the basic concepts of Object Oriented Programming such as Class, Object,
Encapsulation, Inheritance, Polymorphism, and Abstraction in Java.

Theory
Object Oriented Programming (OOP) is a programming paradigm that is based on the concept of
objects. Objects contain data and methods to operate on that data. OOP helps in improving code
reusability, modularity, security, and maintainability.

OOP Concepts

1. Class
A class is a blueprint used to create objects. It defines data members and member functions.

2. Object
An object is an instance of a class. It represents a real-world entity and occupies memory.

3. Encapsulation
Encapsulation is the process of wrapping data and methods into a single unit. It provides
data hiding using access specifiers.

4. Inheritance
Inheritance allows a class to acquire properties and behavior of another class. It improves
code reusability.

5. Polymorphism
Polymorphism means one function performing multiple operations. It is achieved using
method overloading and method overriding.

6. Abstraction
Abstraction hides implementation details and shows only essential information. It is
implemented using abstract classes and interfaces.

Algorithm
1. Define a class with variables and methods.

2. Create objects of the class.

3. Implement encapsulation using access modifiers.


4. Use inheritance to reuse class properties.

5. Apply polymorphism using method overloading/overriding.

6. Use abstraction to hide internal implementation.

Aim
To study Java Input and Output (IO) Streams and understand file handling operations in Java.

Theory
Java IO Streams are used to perform input and output operations such as reading data from a file or
writing data to a file. Streams represent a sequence of data.

Types of IO Streams
1. Byte Stream
Byte streams handle binary data such as images, audio, and video files.
Classes used: InputStream, OutputStream

2. Character Stream
Character streams handle text data using Unicode characters.
Classes used: Reader, Writer

3. Buffered Stream
Buffered streams improve performance by reducing disk access.
Classes used: BufferedInputStream, BufferedReader

4. Object Stream
Object streams are used to read and write objects using serialization.
Classes used: ObjectInputStream, ObjectOutputStream

Algorithm
1. Create a file object.

2. Select appropriate input or output stream.

3. Read or write data using stream methods.

4. Close the stream after operation completion.

Applications
 File handling

 Data storage
 Data transfer

 Serialization of objects

Aim: To Create text file in File io stream: Display on console


Save input in file and use buffer to copy on other file

Code:
import [Link].*;

import [Link];

public class fileInOpStream {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

try {

File file1 = new File("[Link]");

File file2 = new File("[Link]");

[Link]("Enter text to store in file:");

String data = [Link]();


FileWriter fw = new FileWriter(file1);

BufferedWriter bw = new BufferedWriter(fw);

[Link](data);

[Link]();

[Link]("\nReading from file:");

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String line;

while((line = [Link]()) != null){

[Link](line);

[Link]();

BufferedReader br2 = new BufferedReader(new FileReader(file1));

BufferedWriter bw2 = new BufferedWriter(new FileWriter(file2));

while((line = [Link]()) != null){

[Link](line);

[Link]();

[Link]();

[Link]();
[Link]("\nData copied to [Link] successfully!");

} catch (Exception e) {

[Link]("Error: " + e);

[Link]();

Output

You might also like