Friday, August 28, 2009

CSC 3A)ANSWER

NOTE:THIS IS ACTUALLY A LARGE ANSWER.THIS ANSWER IS SUFFICIENT FOR 12 MARKS I THINK.

RMI:-
Remote Method Invocation allows a java object that executes on one machine to invoke a method of a java object that executes on another machine.This is an important feature because it allow to build Distributed applications.
RMI is an object oriented implementation of the Remote procedure Call Model.


A remote object is declared with a remote interface an extension of the java interface.
The remote interface is implemented by the object server.An object client access the object by invoking its methods .


API FOR THE JAVA:
There are mainly three areas to be covered
1)remote interface
2)server side software
3)client side software.

1)remote interface:
In the rmi api, the starting point of creating a distributed object is a java remote interface.A java remote interface is an interface from the Java remote Class,which allows the interface to be implemeted using RMI syntax.


2)server side software:
An object server is an object that provides the methods and the interface to a distributed object.Each object server must
1)implement each of the remote methods specified int he interface
2)register an object that contains the implementation with a directory service

The remote interface implementation:-
A class that implements the remote interface should be provided.
The object server:
The object server class instantiates and exports an object of the remote interface implemantation.


3)client side software:-
The program for the client class is like any other java class.The syntax needed for RMI involves locating the Rmi registry in the server host and looking up the remote reference for the server object;the reference then can be cast to the remote interface calss and the remote methods invoked.
Looking up the remote object:
Some code will be for looking up the remote object inthe registry.The lookup method of the Naming class is used to retrieve the object reference.

String registryURL="rmi://localhost:"+portNum+"/some";
SomeInterface h=(SomeInterface)Naming.lookup(registryURL);

Invoking the Remote method:
The remote interface reference can be used to invoke anu one of the methods in the remote interface.
String message=h.method1();
System.out.println(message);




A SAMPLE RMI APPLICATION:

HELLO INTERFACE.JAVA
import java.rmi.*;
public interface HelloInterface extends remote{

public String sayHello(String name) throws java.rmi.Remoteexception;
}


HELLOIMPL.JAVA:
import java.rmi.*;
import java.rmi.server.*;
public class HelloImpl extends UnicadstRemoteObject implements HelloInterafce{
public HelloImpl() throws Remoteexception{
super();
}
public String sayHello(String name) throws Remoteexception{
return "HelloWolrd"+name;
}
}



3B) THIS ANSWER CAN BE COLLECTED ANYWHERE BY YOU.

Saturday, August 22, 2009

wt lab programs

note:Please insert tags


2b)
//take an image 1.jpg
html
head
title sp /title
/head
body
img src="1.jpg" id="id1" alt="hai this sai" height=100 width=100 onclick="fun(event)" /
/body

script
function fun(event)
{
pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("id1").offsetLeft;
pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("id1").offsetTop;
document.getElementById("id1").alt=""+pos_x+","+pos_y+"";
}
/script



5b)
//create a page 1.html
html
head
title saipavan /title
/head
body
form name="f1" onsubmit="valid()" action="1.html"
username:input type="text" name="user" size="10"
input type="submit" value="submit"
/form
/body
/html

script
function valid()
{
var user=document.f1.user.value;
var pattern=new RegExp("^[a-zA-Z][a-zA-Z0-9]*$");
var res=pattern.exec(user);
if(res)
alert("valid");
else
alert("not valid");
}
/script