Hello world! as a Java Applet 

The client 

        public class HelloApplet extends Applet {

            String message = "blank"; // the string constructed in the try statement
            Hello obj = null;

            public void init() {
                try {                       // "//<hostname>/<objectname>"
                    obj = (Hello)Naming.lookup("//lysander.cs.ucsb.edu/HelloServer");
                    message = obj.sayHello();
                } catch (Exception e) {
                    System.out.println("HelloApplet exception: " + e.getMessage());
                    e.printStackTrace();
                }
            }

            public void paint(Graphics g) {
                g.drawString(message, 25, 50);
            }
        }


Since CLASSPATH is set, the applet's code attribute specifies the fully-qualified package name of the applet:


Compile and Deploy Class Files

When you use the javac and rmic compilers, you must specify where the resulting class files should reside.

    Compile the Java source files

    Make sure that the deployment directory $HOME/myclasses and the development directory $HOME/mysrc/examples/hello are each accessible through the local CLASSPATH on the development machine, before attempting to compile.

    While in the source directory where these files reside, execute:
     

    For an explanation of javac options, please refer to the Solaris javac manual page or the  Win32 javac manual page.

    Use rmic to generate skeletons and/or stubs

    Since the CLASSPATH is set, give rmic a fully qualified class name as an argument:
    rmic examples.helloApplet.HelloImpl


    Start the RMI registry, server, and client

Start the RMI registry

For example, on Solaris:
rmiregistry &
For example, on Windows 95 or Windows NT:
start rmiregistry

Start the server

Run the client

Once the registry and server are running, the client can be run as follows, from within the directory that contains the html file:
appletviewer HelloApplet.html
After running the client, you will see "Hello world!".