Pages

Saturday, 11 August 2012

HOW TO RUN JAVA RMI PROGRAM

 
Remote Method Invocation(RMI) facilitates object function calls between Java Virtual Machines(JVMs)
Step 1
$ first we create interface program like
           /*interface:inte.java*/
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface inte extends Remote
{
        int add(int a,int b)throws RemoteException;
        int sub(int a,int b)throws RemoteException;
        int mul(int a,int b)throws RemoteException;
        int div(int a,int b)throws RemoteException;
}

$ Save the program as inte.java, and compile the program
Step 2
$ Next create a server program like
            /*Server Program:cserver.java*/
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class cserver extends UnicastRemoteObject implements inte
{
        public cserver()throws RemoteException
        {
                super();
        }
        public int add(int a,int b)throws RemoteException
        {
                return a+b;
        }
        public int sub(int a,int b)throws RemoteException
        {
                return a-b;
        }
        public int mul(int a,int b)throws RemoteException
        {
                return a*b;
        }
        public int div(int a,int b)throws RemoteException
        {
                return a/b;
        }
       
         public static void main(String args[])
        {
        try
        {
                inte c1=new cserver();
                String I="CI";
                Naming.rebind(I,c1);
                System.out.println("Server bound and started");
        }
        catch(Exception e)
        {
                e.printStackTrace();
        }
        }
}
$ Save the program as cserver.java, and compile the program
Step 3
$ Now create a client program like
            /*Client Program:cclient.java*/

import java.rmi.*;
public class cclient
{
public static void main(String args[])
{
        try
        {
        String I="CI";
        inte c=(inte)Naming.lookup(I);
        System.out.println("Ready to continue");
        int i=c.add(2,3);
        int j=c.sub(3,2);
        int k=c.mul(2,4);
        int l=c.div(4,2);
        System.out.println(i);
        System.out.println(j);
        System.out.println(k);
        System.out.println(l);
        }
        catch(Exception e)
        {}
}
}
$ save the program as cclient.java, and compile like
Step 4
C:\java\jdk1.5.0\bin>javac inte.java
C:\java\jdk1.5.0\bin>javac cserver.java
C:\java\jdk1.5.0\bin>javac cclient.java

C:\java\jdk1.5.0\bin>rmic cserver
C:\java\jdk1.5.0\bin>start rmiregistry
// we see the new empty block cmd prompt
//new window
C:\java\jdk1.5.0\bin>java cserver
Server bound and started.
//new window
C:\java\jdk1.5.0\bin>java cclient
Ready to continue

5
1
8
2
                                                                        Thank you
                                                                     By BOOBALAN

HOW TO RUN C GRAPHICS PROGRAM


Five easy step to make your TC able to run graphics program are as follows.
1.     Download turbo 3 and install.
2.     Open the C:\TC\BGI and select and copy the CGA.BGI and EGAVGA.BGI FILES .
3.     Save the above to files in to C:\TC\BIN\ directory.
4.     Open TC .EXE and click the options->linker->libraries and select the graphics library option.
5.     And now you can compile your graphics program.

  THANK YOU
BY BOOBALAN

Wednesday, 8 August 2012

How to create java package programs

Hai now i show how to write java package programs and explain with examples

Step 1.
first create a java package like
note:  $ we must create sub directory to store the package
         $ package name and sub directory name are same
$ create a directory like
          c:\program files\java\jdk1.5.0\bin>md student
$ enter the sub directory like
          c:\program files\java\jdk1.5.0\bin>cd student
          c:\program files\java\jdk1.5.0\bin\student>
Step 2.
now we can type the package program
syntax : package packagename;
example :
         c:\program files\java\jdk1.5.0\bin\student>edit
package student;
public class p1
 {
    public void display()
       {
          System.out.println(" this is package");
        }
}

$ save the package as p1.java
$ and exit the program
Step 3.
compile the package program like
          c:\program files\java\jdk1.5.0\bin\student>javac p1.java
with no error go for next step
Step 4.
type the main program
here we just come out the sub directory and create the program like
         c:\program files\java\jdk1.5.0\bin\student>cd..
         c:\program files\java\jdk1.5.0\bin>
go for edit
         c:\program files\java\jdk1.5.0\bin>edit
              
                import student.p1;
                class p2
                  {
                     public static void main(String args[])
                        {
                            p1 ob = new p1();
                            ob.display();
                         }
                   }

$ save and exit the program like p2.java
$ compile and run the program like
          c:\program files\java\jdk1.5.0\bin>javac p2.java
$ without error
         c:\program files\java\jdk1.5.0\bin>java p2
          this is package
         c:\program files\java\jdk1.5.0\bin>


thank you by,  
          R.Boobalan