What is a remote interface in java?

Java 8Object Oriented ProgrammingProgramming

A Remote interface is available in the java.rmi package it is a marking/tagging interface, it is used with remote method invocation(RMI).

RMI is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM.

To it is a marking interface, to mark an object of a class remote, you need to implement this interface.

To create a remote interface −

  • Create an interface that extends the predefined interface Remote which belongs to the package or, implement the Remote interface with the class, which you need to make remote.

  • Declare all the business methods that can be invoked by the client in this interface.

  • Since there is a chance of network issues during remote calls, an exception named RemoteException may occur; throw it.

Example

import java.rmi.Remote;
import java.rmi.RemoteException;
// Creating Remote class for our application
public class RemoteExample implements Remote {
}
Or,
import java.rmi.Remote;
import java.rmi.RemoteException;
// Creating Remote interface for our application
public interface Hello extends Remote {
   void printMsg() throws RemoteException;
}
raja
Published on 04-Jul-2019 17:48:32
Advertisements