0% found this document useful (0 votes)
41 views5 pages

WJP Exp 2

The document describes a Java program that implements basic arithmetic operations using interfaces, classes, and remote method invocation (RMI). It defines an interface for addition, subtraction, multiplication, and division methods. A class implements this interface and performs the arithmetic operations. A server registers the implementation class and a client looks it up and calls the methods, printing the results. The program successfully performs addition, subtraction, multiplication, and division of sample numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views5 pages

WJP Exp 2

The document describes a Java program that implements basic arithmetic operations using interfaces, classes, and remote method invocation (RMI). It defines an interface for addition, subtraction, multiplication, and division methods. A class implements this interface and performs the arithmetic operations. A server registers the implementation class and a client looks it up and calls the methods, printing the results. The program successfully performs addition, subtraction, multiplication, and division of sample numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

20EUIT125

SAKTHI ISWARYA S

EXP NO: 2 Calculation program using Java

DATE: 10.03.2022

AIM:
To write a Java program to perform basic arithmetic operations such as
addition, subtraction, multiplication and division.
ALGORITHM:
STEP I: Start
STEP II: InclassITC, define the functions and return the values to be returned.
STEP-III: For example, greeting() function returns the string “GOOD MORNING
PEEPS.” And add() function is of int type and has two arguments which are used as
operands to perform the operation.
STEP-IV: A function can be made static with the keyword static.
STEP-V: Define a main() function in which an object of the class is created and the
function and the function which are non-static are called using that object and the
result is printed.
STEP VI: Stop

PROGRAM:

INTERFACE:
import java.rmi.*;
public interface computation extends Remote{
public int add(int x, int y) throws Exception;
public int sub(int x, int y) throws Exception;
public int muli(int x, int y) throws Exception;
public int div(int x, int y) throws Exception;
20EUIT125
SAKTHI ISWARYA S

public String ishu() throws Exception;


}
IMPLEMENTATION:
import java.rmi.*;
import java.rmi.server.*;
public class computation_impl extends UnicastRemoteObject implements
computation
{
public computation_impl() throws Exception
{
super();
}
public int add(int x, int y) throws Exception
{
return x+y;
}
public int sub(int x, int y) throws Exception
{
return x-y;
}
public int muli(int x, int y) throws Exception
{
return x*y;
}
public int div(int x, int y) throws Exception
{
return x/y;
}
20EUIT125
SAKTHI ISWARYA S

public String ishu() throws Exception


{
return "WELCOME TO MY PROGRAM :";
}
}
SERVER:
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class server{
public static void main(String args[])
{
try{
Registry registry=LocateRegistry.createRegistry(3678);
computation_impl obj=new computation_impl();
registry.rebind("ishu", obj);
System.out.println("server initiated.......");
}
catch(Exception e)
{
}
}
}
CLIENT:
import java.rmi.*;
public class client
{
20EUIT125
SAKTHI ISWARYA S

public static void main(String args[])


{
try{
computation c=(computation)Naming.lookup("rmi://localhost:4007/ishu");
System.out.println(c.add(10,20));
System.out.println(c.sub(30,50));
System.out.println(c.muli(4,7));
System.out.println(c.div(15,5));
System.out.println(c.ishu());
}
catch(Exception e)
{
}
}
}

OUTPUT:

INTERFACE , IMPLEMENTATION,SERVER:
20EUIT125
SAKTHI ISWARYA S

CLIENT:

RESULT:
Thus the program to perform basic arithmetic operations has been implemented
and executed successfully.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy