Show TOC

Procedure documentationDefining a Remote Interface Locate this document in the navigation structure

 

The remote interface extends java.rmi.Remote interface and declares a set of methods that may be invoked from a remote Java Virtual Machine (JVM).

Procedure

  1. Extend a remote interface. You usually extend the java.rmi.Remote interface directly.

  2. Specify the methods signatures that the remote object will have. You are not obliged to declare java.rmi.RemoteException in the throw clauses of the methods; you can declare exceptions that are specific to your application.

Example

The example shows the account interface, which is a remote interface that defines three methods. It extends java.rmi.Remote directly. The draw method declares an OverdrawException in its throw clause, which is an application-specific exception.

Syntax Syntax

  1. package examples.rmi_p4;
    
    public interface Account extends java.rmi.Remote {
        // Define method signatures
        public void deposit(int amount) throws java.rmi.RemoteException;
        public void draw (int amount) throws OverdrawException;
        public int getBalance();
    }
    
End of the code.

The definition of the OverdrawException class is as follows:

Syntax Syntax

  1. package examples.rmi_p4;
    
    public class OverdrawException extends Exception {
    
      public OverdrawException(int overdraw) {
        super("Overdraw:" + overdraw);
      }
    }
     
End of the code.