Disclaimer: This is an example of a student written essay.
Click here for sample essays written by our professional writers.

Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of UKEssays.com.

Lottery Program Java

Paper Type: Free Essay Subject: Information Technology
Wordcount: 4522 words Published: 1st Jan 2015

Reference this

Aim:-To prepare a lottery program in java by using RMI mechanism and report that describe REMOTE METHOD INVOCATION (RMI).3


This report implements a distributed application using java RMI. The main purpose of this report is just to investigate and study of remote method invocation and their structure. Where In the RMI program that is well known middle wear frame work I used in two files one belongs to the server and another belongs to client .where server does not know any thing abut the client and client keep some little information about the server. Also message interface is providing the interface services between server and class in this report I am describing the RMI structure functionality and reliability and using protocol to make them RMI communication possible.

Aim:-To prepare a lottery program in java by using RMI mechanism and report that describe REMOTE METHOD INVOCATION (RMI).


The objectives of the report are to attain:

  • To describing the lottery program by using RMI.
  • Investigate the relation ship between server and client program using java RMI mechanism.
  • Understand the frame work .architecture and role of stub and skeleton.
  • Investigate about RMI and RPC. And their differences.
  • Study the working and process about the lottery program by using java RMI mechanism.
  • Search the web site to provide the useful information for the reader which could not be found in the books and journals.


there are thousand of different processor connected with each other .where object invocation allow to java virtual machine to locate and run another java virtual machine located any where else .this extremely important technology makes possible to distribute the load across other distribute machine that can be one. In short java RMI is a remote procedure call.

RMI application are divided into two parts .server, client. That gives you very easy solution.

This report explores the brief discussion about the java RMI and how the lotto programmes has been define in order to use RMI technology. Where three entities are involved in running program that java RMI use.

Back ground:-

Distributed need a computation process in different address space in order to make communication in different host? Java language in one of the best plate form to communicate communication mechanism that support RMI and RPC and socket programming. Java remote method provides integrated and reliable communication via remote method calls.

In RMI back ground process and entities participate in three different orders to translate RMI set up

(1)Client (2) server (3) object registry

1) Client: this is the program that has been written to access remote method.

2) Server:-at the server side this program is to write an object method client put their request for this remote object to the server to be executed.

3) Object registry: – object registry classify object is registered and it will run on known port (by default) client must contact to make their access successful to remote object before invoking the remote method.

How RMI Works:-

Remote method invocation is a mechanism for communication that’s basically run between two machines that is basically running on java virtual machine.

For example:

There are two machines that are running on java. when java code on machine A need method then B translate it self as an java object method .the whole back end communication process between machine A and B is done by remote method invocation in this example the behind running procedure client and server make connection through special classes stub and skeleton .stub run on client side and skeleton run on server side.

These two program act as a middle ware.

Middle ware:-

Middle ware act like a glue or connectivity soft ware between two applications generally is it soft ware that does not have a user interface and that gives multiple process interact and exchange of data between systems.

Stub and skeleton programming in java:-

Stub and skeleton is a frame work and standard communication system that will not have to deal with network and socket programming .RMI stub and skeleton provides import interface and skeleton in RMI programming where client application program invoke the server side component and skeleton act as an interface means performing the job of marshalling and un marshalling



Skeleton Server

RMI Client stub



  • Client invoke to server for a remote method the request goes first towards stub

  • Stub sends the remote call request toward the server side skeleton.
  • The stub translate the socket toward s the remote server marshalling the parameter and send to the skeleton.
  • Through their method skeleton receive the remote call and un marshal all the parameter and send them back toward the actual remote implementation.

Marshalling represent data or object into byte stream and de marshalling represent conversion of byte stream into data and object.

RMI layered architecture:-

RMI (remote method architecture) is based on three layered architecture every layer has got their own functionality and independency. None of the layered effect on each other in order to enhancement even you are making a UDP connection as well.

Very first layered that belong to the stub and skeleton layer thus layer act like an interface reference variable and redirect the remote call toward the remote services.

The 2nd layered in RMI translate their job to intercept and manage references made from client side.

And the third layered in RMI system that makes complete RMI system is TCP/IP that provide a basic connectivity and fire wall prevention strategies even in the face of networking obstacles.


Java RMI at least three level of protocol. On the top TCP/IP protocol RMI uses JRMP (java remote method protocol) protocol .this wire level stream base protocol consist of two different level one of them is JDK 1.1 first version that basically require skeleton classes and the 2nd version protocol is 2SDK that does not require skeleton classes.

New released version is RMI-IIOP that is using object management (OMG) instead of JRMP in order to communicate server and client.

Explanation for lottery program:-

Lottery program in java by using RMI in client server mechanism that perform the operation each time when client run program and give any number to generate the 6 random number set of lottery number then server program generates n sets of lottery number.

The lottery number consists of following files.





This part represent the remote method invocation .where the method receive message belongs to server class implements this interface known as remote client .this lottery program where remote client program type server class is the interface.


In the 2nd part of this lottery program the RMI server program having a class where we defined the method is remote client. This RMI server class is the implementation of the RMI interface.


This class belongs to client program class. Where class translating their job to call REMOTE METHOD.

Execution out line for the lottery program:-

Execution of the lottery program are given below

  • RMI servers creating a kind of dictionary known as “registry”. Which is basically represented an ID of remote object and content of this ID is an object. In the program registry is being accessed through remote object by the port number and IP address.
  • RMI binds the RMI SERVER and itself in the registry like (RMI SERVER.CLASS).
  • Remote object (RMI SERVER) is being looked up by the (RMI CLIENT) .
  • RMI CLIENTS now calls the RMI SERVER class method which is “receive method”.

Compile source code.

javac LotteryServer.java

javac MessageInterface.java

javac LotteryClient.java

2) rmic LotteryServer


1) Run,

Java LotteryServer

2) On different command prompt

Java Lottery Client 5 (Note: here 5 could be any amount you want to play).

Difference between RPC and RMI:-

Distributing computing is playing vital and lead role in the electronics communication from last couple of year. Where main frame, dumb terminal and finally intelligent client and worked station led the revolution concept in network technology and distributed system. Here I am talking about the RPC and RMI. in both technology the common word is “REMOTE”. Where RPC is the predecessor of RMI same like oracle 7 is predecessor of oracle 8.or we can that RMI is totally based on previous technology RPC That

Developed in 980.

RPC (remote procedural call):-

REMOTE PROCEDURAL CALL (RPC is a power full technique) that allows a procedural programming for constructing the distributed client server based program RPC allow a procedural program language to call a function .calling argument is being passed from the remote procedure and the caller wait the feed back response from the remote procedure .

RPC translate their job in order to marshalling and networking of data.

For example: – packaging of function specification and enhancing the argument and return all these values over the network.

RMI (remote method invocation):-

RMI remote method invocation) is the predecessor, simplest and direct model of distributed communication and RPC .once a object is register that belong to the method of java being remotely accessed that client start to look up the server side to use the service after receiving the interface reference. In RMI marshalling of data is controlled by RMI .where system of method call is identical in order to call a object method in same program. Like a RPC in RMI the program need to be concerned with the transmission of data across the network. RMI does not keep the requirement for any developer to learn interface definition language (IDC). Because RMI is just supporting to one language. RMI is just giving the facility of truly and solid object oriented distributing computing. RMI is expandable plate form that provides all benefits transfer of object of complex data type. Low maintenance cost and secure environment.


RMI keep preference over RPC. At very initial and basic level RMI is belong to RPC.

RPC system is does support to procedural language system and essentially least common denominator system. So it cannot provide the functionality that is not available all possible target plate form.

RMI that using the native system focused on purely java that has fully approach to provide distributed communication technology java RMI keep across plate form portable feature where RPC require a lot more over head then RMI.

Algorithm fro server:-

  • import libraries
  • start remote object class
  • declare variable
  • start method sent receive message
  • print message
  • initialize and declare vector
  • loop start till number u entered
  • initialize another vector
  • add content in vector
  • loop end
  • after loop ending finishing process
  • return value
  • finish
  • generate remote number
  • Start loop run 0 to 49.
  • Add number in list
  • End loop
  • Another loop runs 0 to 5.
  • Add number in to vector
  • Return number
  • Start lottery server
  • Set IP add
  • Set port address
  • Print lottery server address and port address
  • Start main method
  • end

Algorithm for Client:-

  • import libraries
  • start class
  • declare variable
  • print message server address and port address
  • connect to the registry
  • look up for the RMI server
  • create vector
  • run loop until vector size
  • print lottery number
  • END



Flow Diagram for the Server

int thisPort;

String thisAddress

Registry registry;

public Vector sentreceiveMessage(int x)

System.out.println(“Received request to play for £”+x);


Vector mainVec=new Vector()

for(int m=0;mVector vArr=generateNos(5); mainVec.add(vArr);

System.out.println(“Process Finished!”)

return mainVec



Vector vNo=new Vector()

List numbers = new ArrayList()

for (int i = 0; i <= 49; i++)

{ numbers.add(i)




return vNo

thisAddress= “”

System.out.println(“Lottery Server running at address=”+thisAddress+”,port=”+thisPort)


LotteryServer s=new LotteryServer()


registry.rebind(“rmiServer”, this)

registry = LocateRegistry.createRegistry( thisPort )


Flow Diagram for the Client

MessageInterface rmiServer

Registry registry

String serverAddress=”″

String serverPort= “3232”

int amount=Integer.parseInt(args[0])

println(“sending request to “+serverAddress+”:”+serverPort)



(new Integer(serverPort)).intValue()

Rmi server=(messageinterface)(registery.look up(“rmiserver”)

Vector noArr= rmiServer.sentreceiveMessage(amount)

for(int x=0;xEND



System.out.println(“Lottery Numbers: “+noArr.get(x))

Conclusion: –

As represented report shows when using RMI communication in between the lottery program is quit simple and far greater by using RMI technique.

In this program host computer is not doing any thing but client side is working. Also this whole report expressing itself about the RMI server client and architecture and using protocol that makes possible communication between server and client.

Assignment plan:-

To complete this assignment we have to follow below schedule:

Assignment Schedule

Tasks Description

Duration (Hours)

Understand key issues



Understand System

Understand principle and existing system of lottery program


Literature Search

Investigate technology system, white paper, journal, article, interaction design criteria, understanding the main ethical behind this technology, and decide when and how they should be applied to maintain.


Examine & Testing of lottery program



Overview of all the assignment and changing’s



Recommend future work on the lottery system and report and how it may be improved and


Final Project Submission Date: – 7 May 2008

Total 110 hours

The attached plan shows these activities and the hours allocated to them. The schedule provides for study, giving average of about 16 hours study per week. The work structure and Gantt chart detailing project plan is attached with this report.

Gantt chart








Total Hours

Understand Key


Understand System


Literature Search


Examine & Testing all research






Total Hours 110To Complete Final Report



(Note: All these references were accessed between 20th April, 2008 and 6th may , 2008)

[1] eent3.lsbu.ac.uk/staff/xiaop/DSI/lab/RMI_Tutorial%201.pdf

[2] www.cs.kent.edu/~farrell/grid06/ass/RMI.html

[3] www.engr.mun.ca/~baxter/Publications/Steps2RMI.pdf

[4] java.sun.com/j2se/1.3/docs/guide/rmi/spec/rmiTOC.html – Cached

[5] www.cs.rutgers.edu/~pxk/rutgers/notes/content/rb-rmi.pdf

[6] answers.yahoo.com/question/index?qid=1006020703932

[7] 42.fht-esslingen.de/~adrian/master/rmi.pdf –

[8] yama-linux.cc.kagoshima-u.ac.jp/~yamanoue/researches/java/rmi-ex2/ – 59k –

[9] java.ittoolbox.com/pub/HS021003A.pdf


Lottery program for server

import java.rmi.*;

import java.rmi.registry.*;

import java.rmi.server.*;

import java.net.*;

import java.util.Random;

import java.util.*;

public class LotteryServer extends java.rmi.server.UnicastRemoteObject

implements MessageInterface


int thisPort;

String thisAddress;

Registry registry; // rmi registry for lookup the remote objects.

// This method is called from the remote client by the RMI.

// This is the implementation of the “MessageInterface”.

public Vector sentreceiveMessage(int x) throws RemoteException


System.out.println(“Received request to play for £”+x);


Vector mainVec=new Vector();

for(int m=0;mVector vArr=generateNos(5);



System.out.println(“Process Finished!”);

return mainVec;


/* Generate and add numbers b/w 0-49 in vector */

private Vector generateNos(int no){

Vector vNo=new Vector();

List numbers = new ArrayList();

for (int i = 0; i <= 49; i++){ numbers.add(i);}


for(int p=0;p<=5;p++){



return vNo;


public LotteryServer() throws RemoteException



// get the address of this host.

// thisAddress= (InetAddress.getLocalHost()).toString();

thisAddress= “”; // to run on localhost


catch(Exception e){

throw new RemoteException(“can’t get inet address.”);


thisPort=3232; // this port(registry’s port)

System.out.println(“Lottery Server running at address=”+thisAddress+”,port=”+thisPort);


// create the registry and bind the name and object.

registry = LocateRegistry.createRegistry( thisPort );

registry.rebind(“rmiServer”, this);


catch(RemoteException e){

throw e;



static public void main(String args[])



LotteryServer s=new LotteryServer();


catch (Exception e) {






Lottery program for client:-

import java.rmi.*;

import java.rmi.registry.*;

import java.net.*;

import java.util.Vector;

public class LotteryClient


static public void main(String args[])


MessageInterface rmiServer;

Registry registry;

String serverAddress=”″;

String serverPort= “3232”;

int amount=Integer.parseInt(args[0]);

System.out.println(“sending request to “+serverAddress+”:”+serverPort);


// get the “registry”



(new Integer(serverPort)).intValue()


// look up the remote object



// call the remote method

Vector noArr= rmiServer.sentreceiveMessage(amount);

for(int x=0;xSystem.out.println(“Lottery Numbers: “+noArr.get(x));



catch(RemoteException e){



catch(NotBoundException e){





Message interface program:-

import java.rmi.*;

import java.util.Vector;

public interface MessageInterface extends Remote


Vector sentreceiveMessage(int x) throws RemoteException;



Cite This Work

To export a reference to this article please select a referencing stye below:

Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.

Related Services

View all

DMCA / Removal Request

If you are the original writer of this essay and no longer wish to have your work published on UKEssays.com then please: