Programming Tips from the Designer

Hi, my name is Alex Westerman, and as you may know, I used to be one of the web designers of the Pyle Inside’s website. I posted some tips on this page about codes like C#, web designing tips for HTML, and more. If you are interested in programming and want to learn more: here are some links to books, tools, and resources that could make you successful in programming.

Head First Labs Book Series

Visual Studio 2012 for Windows developement

W3 Schools from the people who made the web standards

This Week’s Programming Tips are:

I hope you all had a great summer. Now I’m back and with more tips. Today’s is about taking advantage of Java RMI (Remote Method Invocation). This is how you can use Java Me and  complete large methods by using a remote computer.  Here is a example from Wikipedia*:

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.*; 

public class RmiServer
    extends UnicastRemoteObject 
    implements RmiServerIntf {
    public static final String MESSAGE = "Hello world";

    public RmiServer() throws RemoteException {
        super(0);    // required to avoid the 'mic' step, see below
    }

    public String getMessage() {
        return MESSAGE;
    }

    public static void main(String args[]) throws Exception {
        System.out.println("RMI server started");

        try { //special exception handler for registry creation
            LocateRegistry.createRegistry(1099); 
            System.out.println("java RMI registry created.");
        } catch (RemoteException e) {
            //do nothing, error means registry already exists
            System.out.println("java RMI registry already exists.");
        }

        //Instantiate RmiServer
        RmiServer obj = new RmiServer();

        // Bind this object instance to the name "RmiServer"
        Naming.rebind("//localhost/RmiServer", obj);
        System.out.println("PeerServer bound in registry");
    }
}
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface RmiServerIntf extends Remote {
    public String getMessage() throws RemoteException;
}
import java.rmi.Naming;

public class RmiClient { 
    public static void main(String args[]) throws Exception {
        RmiServerIntf obj = (RmiServerIntf)Naming.lookup("//localhost/RmiServer");
        System.out.println(obj.getMessage()); 
    }
}

 

 

My Blog Archive

Check out my scratch projects

*Always Remember that Wikipedia isn’t always reliable. I chose this structure because it is correct