CONTENTS | PREV | NEXT Java Remote Method Invocation


2.5 Implementing a Remote Interface

The general rules for a class that implements a remote interface are as follows: For example, the following class BankAcctImpl implements the BankAccount remote interface and extends the java.rmi.server.UnicastRemoteObject class:
package mypackage;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class BankAccountImpl
        extends UnicastRemoteObject
        implements BankAccount
{
        private float balance = 0.0;

        public BankAccountImpl(float initialBalance) 
                throws RemoteException 
        {
                balance = initialBalance;
        }
        public void deposit(float amount) throws RemoteException {
                ...
        }
        public void withdraw(float amount) throws OverdrawnException,
                RemoteException {
                ...
        }
        public float getBalance() throws RemoteException {
                ...
        }
}


Note:


CONTENTS | PREV | NEXT
Copyright 1997, 2010, Oracle and/or its affiliates. All rights reserved.