A) Write fully working remote procedure call (RPC) program using java.
Example
Here is an example of a fully working RPC program using Java:
First, we need to define the interfaces for the RPC calls (in two separate files):
[Link]:
```
import [Link];
import [Link];
public interface UserService extends Remote {
public String getName(String userId) throws RemoteException;
}
```
[Link]:
```
import [Link];
import [Link];
public class UserServiceImpl extends UnicastRemoteObject implements UserService
{
public UserServiceImpl() throws RemoteException {
super();
}
@Override
public String getName(String userId) throws RemoteException {
if ([Link]("1")) {
return "John Doe";
} else if ([Link]("2")) {
return "Jane Smith";
} else {
return "Unknown user";
}
}
}
```
Next, we implement the server (in one file):
[Link]:
```
import [Link];
import [Link];
import [Link];
public class UserServer {
public static void main(String[] args) {
try {
UserService userService = new UserServiceImpl();
UserService stub = (UserService) [Link](userService, 0);
Registry registry = [Link]();
[Link]("UserService", stub);
[Link]("UserServer ready.");
} catch (Exception e) {
[Link]("UserServer exception: " + [Link]());
[Link]();
}
}
}
```
Finally, we implement the client (in one file):
[Link]:
```
import [Link];
import [Link];
public class UserClient {
public static void main(String[] args) {
try {
Registry registry = [Link]("localhost");
UserService userService = (UserService) [Link]("UserService");
String name = [Link]("1");
[Link]("Name for user 1: " + name);
name = [Link]("2");
[Link]("Name for user 2: " + name);
name = [Link]("3");
[Link]("Name for user 3: " + name);
} catch (Exception e) {
[Link]("UserClient exception: " + [Link]());
[Link]();
}
}
}
```
To run this program, we need to compile all the files, start the server (`java
UserServer`) and then start the client (`java UserClient`). The client should output:
```
Name for user 1: John Doe
Name for user 2: Jane Smith
Name for user 3: Unknown user
```
B) Write fully working remote method invocation (RMI) program using java.
Example
Here is an example of a fully working RMI program in Java:
Server side implementation:
```java
import [Link].*;
import [Link].*;
public class RMIImplementation extends UnicastRemoteObject implements RMIInterface {
public RMIImplementation() throws RemoteException {
super();
}
public int add(int x, int y) throws RemoteException {
return x + y;
}
}
```
Client side implementation:
```java
import [Link].*;
public class RMIClient {
public static void main(String[] args) throws Exception {
RMIInterface obj = (RMIInterface) [Link]("//localhost/RMIServer");
int result = [Link](10, 20);
[Link]("Result: " + result);
}
}
```
Interface implementation:
```java
import [Link].*;
public interface RMIInterface extends Remote {
public int add(int x, int y) throws RemoteException;
}
```
Server startup code:
```java
import [Link].*;
public class RMIServer {
public static void main(String[] args) throws Exception {
RMIImplementation obj = new RMIImplementation();
[Link]("//localhost/RMIServer", obj);
}
}
```
To run the program, first run the server startup code:
```
java RMIServer
```
Then run the client code:
```
java RMIClient
```
The output should be:
```
Result: 30
```