Unit-5-JAVA I/O Programming And RMI.pptx

SonaShaiju1 0 views 25 slides Nov 01, 2025
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

I/O Programming in Java is used to take input (like reading from keyboard or file) and give output (like displaying on screen or writing into a file).
It helps the program communicate with the outside world.

RMI (Remote Method Invocation) allows a Java program to call methods on another computer ov...


Slide Content

Unit:5 I/O Programming & Remote Method Invocation I/O programming: Text and binary I/O, binary I/O classes, object I/O. RMI: Introduction to Client-Server architecture, RMI concepts, stubs and skeleton, java RMI classes and interfaces, writing simple RMI application, parameter passing in remote methods- marshalling and unmarshalling

I/O programming Java Input/Output (I/O) programming handles the flow of data between a Java program and external sources or destinations, such as files, network connections, or the console. This is achieved through the concept of streams, which are sequences of data.

Text I/O Text I/O in Java involves reading and writing sequences of characters, often intended for human readability. Key classes for text I/O include: FileReader  and  FileWriter :  These classes are used for reading and writing character streams to and from files.  They automatically handle character encoding and decoding based on the platform's default character set or a specified one

Text I/O BufferedReader and BufferedWriter : These classes enhance the performance of FileReader and FileWriter by providing buffering capabilities, which reduce the number of physical I/O operations. BufferedReader offers a convenient readLine () method for reading text line by line. Scanner :  A versatile class for parsing primitive types and strings using regular expressions. It can read input from various sources, including files and  InputStream  objects .

Text I/O PrintWriter : Provides convenient methods for printing formatted representations of objects to a text output stream, similar to System.out.println (). // Writing to a text file try ( BufferedWriter writer = new BufferedWriter (new FileWriter ("myTextFile.txt"))) // Reading from a text file try ( BufferedReader reader = new BufferedReader (new FileReader ("myTextFile.txt")))

Binary I/O: Binary I/O deals with reading and writing raw bytes, without any character encoding or decoding. This is suitable for non-textual data like images, audio files, or serialized objects. Key classes for binary I/O include:

Binary I/O: FileInputStream and FileOutputStream : These classes are used for reading and writing raw bytes to and from files. They operate at the byte level. BufferedInputStream and BufferedOutputStream : Similar to their text I/O counterparts, these classes add buffering to FileInputStream and FileOutputStream for improved performance.

Binary I/O: DataInputStream and DataOutputStream : These classes allow reading and writing primitive data types (like int , double, boolean ) in a platform-independent binary format. ObjectInputStream and ObjectOutputStream : Used for serializing and deserializing Java objects, allowing objects to be written to and read from files.

Object I/O Object I/O (Object Input and Output) Object I/O means reading and writing entire objects (not just text or bytes) to files or streams. It is used when we want to store objects permanently (serialization) or send objects across a network . Serialization To store an object, the object must be converted into a byte stream . This process is called Serialization . To read the object back, the byte stream is converted back to the original object . This is called Deserialization .

ObjectOutputStream Writes (serializes) objects to a file or output stream ObjectInputStream Reads (deserializes) objects from a file or input stream Classes Used in Java for Object I/O

Client-Server Architecture Client-Server Architecture is a network model in which clients request services and a server provides those services. The client is usually a user device or application, and the server is a powerful computer that stores data and processes requests. How it Works The client sends a request to the server. The server processes this request. The server sends a response back to the client.

Key Components of C/S Architecture Client:  A device or application (e.g., web browser, mobile app) that initiates requests for services or data from a server. Server:  A more powerful computer or application that listens for client requests, processes them, and provides the requested resources or services. Network:  The network facilitates communication between clients and servers. It enables data exchange using various protocols and ensures reliable connectivity. Protocols:  Protocols are standardized rules that govern data transmission and communication between clients and servers. They ensure that data is transmitted in a secure, reliable, and understood manner.

Key Components of C/S Architecture User Interface (UI):  The UI is the part of the client application that interacts with the user. It provides a means for users to input data and view results returned by the server. Application Logic:  Application logic refers to the code and algorithms that define the application's functionality. It processes user inputs, interacts with the server, and manages the flow of data between the client and the server.

Key Components of C/S Architecture Middleware:  Middleware is software that acts as an intermediary between clients and servers. It provides additional functionalities like authentication, logging, message queuing, and transaction management. Database:  A database is a structured collection of data stored on the server. It stores and manages data that clients request, ensuring data consistency, integrity, and security.

Remote Method Invocation RMI allows a Java program on one computer (client) to call methods of an object located on another computer (server) as if the object is local . RMI is used to build distributed applications; it provides remote communication between Java programs. It is provided in the package  java.rmi .

How RMI Works Server creates an object. Server registers the object in the RMI Registry . Client looks up the object in the RMI Registry. Client calls methods on the remote object. RMI internally handles sending the request and returning the result.

RMI works and its key components Remote Interface: This defines the methods that can be invoked remotely. Both the client and server must agree on this interface. Server: The server application creates and registers remote objects that implement the remote interface. These objects are made available for clients to access. Client: The client application obtains a reference to a remote object on the server and then invokes its methods as if it were a local object. RMI Registry: A naming service that stores references to remote objects. Clients use the RMI registry to look up and obtain references to desired remote objects

Stub (Client Side) A stub is a small helper object on the client side . It looks like the real object, but it just forwards method calls to the server . It sends the request to the server and receives the result . Skeleton (Server Side) A skeleton is the server-side helper. It receives the request from the stub , calls the actual object method , and sends the result back to the client.

RMI Packages 1. java.rmi This package provides the basic features for remote communication. It contains Remote interface , RemoteException , and Naming class. Helps the client and server talk to each other . 2. java.rmi.server This package contains classes used on the server side . It includes UnicastRemoteObject (used to create remote objects ). Helps the server create remote objects that clients can call. 3. java.rmi.registry This package is used to work with the RMI Registry . It has Registry and LocateRegistry classes. Helps store remote objects in the registry and allows clients to find them .

RMI Packages and Their Classes 1. java.rmi Package This package contains the basic interfaces and classes needed for remote communication. Class/Interface Purpose (Simple Meaning) Remote (Interface) Marks a method so it can be called from another computer. RemoteException (Exception) Handles errors in remote communication. Naming (Class) Helps register and find remote objects in RMI Registry ( bind , lookup ).

RMI Packages and Their Classes 2. java.rmi.server Package This package provides server-side support to create remote objects . Class Purpose (Simple Meaning) UnicastRemoteObject Makes an object remote (clients can call it over network). RemoteObject Base class for all remote objects. RemoteServer Provides server support functions for remote objects.

RMI Packages and Their Classes 3. java.rmi.registry Package This package deals with the RMI Registry , which stores remote objects using names. Class/Interface Purpose (Simple Meaning) Registry (Interface) Represents the RMI Registry . LocateRegistry (Class) Used to create or connect to an RMI Registry.

Marshalling and Unmarshalling Marshalling Marshalling means converting data or an object into a form that can be sent over a network. It packs the object into a byte stream. Prepare data to send from one computer to another.

Unmarshalling Unmarshalling means converting the received byte stream back into the original object. It unpacks the object after it arrives on the other side. Rebuild data after receiving it from the network.

When the client calls a remote method: Marshalling: The method parameters are converted into bytes and sent to the server . Unmarshalling: The server converts the bytes back into the original parameters and uses them. Then the result goes back the same way : Server marshalls the result → sends → Client unmarshalls and gets the answer.
Tags