Java Blog

 
 
 
----------------------------------------------------------------------------------
                    Interface
----------------------------------------------------------------------------------
public interface perInterface extends java.rmi.Remote

{
    float find_per(int marks[]) throws java.rmi.RemoteException;
}


-------------------------------------------------------------------------------------------------
                    Implementation
-------------------------------------------------------------------------------------------------

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

public class perImpl extends UnicastRemoteObject
               implements perInterface
{
    public perImpl(String name) throws RemoteException
    {
        super();
        try
        {
            Naming.rebind(name,this);
        }
        catch(Exception e) 
        { 
            System.out.println(\"Exception:\"+ e.getMessage());
            e.printStackTrace();
        }
    }

    public float find_per(int marks[]) throws RemoteException
    {
        int sum=0;
        float per;

        for(int counter=0;counter < marks.length;counter++)
            sum+=marks[counter];

        per = (float)sum/3;

        return per;
    }

}

-------------------------------------------------------------------------------------------------
                    Client
-------------------------------------------------------------------------------------------------

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.io.*;

public class perClient
{
    public static void main(String args[])
    {
        System.setSecurityManager(new RMISecurityManager());

        try
        {
            float percentage=0;
            int marks[]=new int[6];

            perInterface pi = (perInterface) Naming.lookup(\"//localhost/pno\");

            BufferedReader ber=new BufferedReader(new InputStreamReader(System.in));
            String temp=new String();

            for(int counter=0;counter<6;counter++)
            {
                System.out.print(\"\\n Enter Marks For Subject \" + (counter+1) + \" : \");
                temp=ber.readLine();
                marks[counter]=Integer.parseInt(temp);
            }


            percentage = pi.find_per(marks);
            System.out.println(\"Percentage is : \" + percentage);

        }
        catch(Exception e)
        {
            System.out.println(\"System Exception\" + e);
        }
    }
}


-------------------------------------------------------------------------------------------------
                    Server
-------------------------------------------------------------------------------------------------

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class perServer
{
    public static void main(String args[])
    {
        System.setSecurityManager(new RMISecurityManager());

        try
        {
            perImpl pim = new perImpl(\"//localhost/pno\");
            System.out.println(\"\\nServer is ready...\");
        }
        catch(Exception e) 
        { 
            System.out.println(\"Exception: \" + e.getMessage());
            e.printStackTrace();
        }
    }
}    


-------------------------------------------------------------------------------------------------
                    Policy
-------------------------------------------------------------------------------------------------

grant
{
    // Allow everything for now
    permission java.security.AllPermission;
};

----------------------------------------------------------------------------------
                    Output
----------------------------------------------------------------------------------


 Enter Marks For Subject 1 : 30

 Enter Marks For Subject 2 : 25

 Enter Marks For Subject 3 : 28

 Enter Marks For Subject 4 : 21

 Enter Marks For Subject 5 : 29

 Enter Marks For Subject 6 : 22
Percentage is : 51.666668

    Related Post:
  1. Program using session tracking capability of Servlets, which displays information of current user session by HttpServletRequest object

  2. Program to show the use of If-Else Statement

  3. Program of telnet server - client

  4. Program in CORBA which takes a long sentence from client (at least 7 words), passes to the server, server separates out each word and sends back

  5. Pass the marks of 10 students from the client side design a servlet, which takes these marks and returns the number of students who obtained first cls

  6. Program to show the use of Logical AND Operator (&) in If Statements

  7. Write a class whose objects holds a current value and have a method to add that value, printing the new value

  8. Program to convert the given temperature in faherenhiet to celsius using the following conversion formula C= F- 32/1.8

  9. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  10. Program to copy the elements of an array into another array in reverse order and print them

  11. Program to display following things on the client machine a)date and time of the server machine b)date and time of the client machine and difference

  12. Program to Concat Strings

  13. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  14. Program to show the use of some Character Methods

  15. Biological Sequence Allignment Using Dynamic Programing

  16. Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

  17. Program to show an example of getting at characters in a String

  18. Program of concatenating and Buffering files

  19. An applet program to give demo of getDocumentBase() and getCodeBase() methods

  20. Program of FTP client and server