{"id":10208,"date":"2015-08-25T07:51:26","date_gmt":"2015-08-25T11:51:26","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10208"},"modified":"2015-08-24T08:41:32","modified_gmt":"2015-08-24T12:41:32","slug":"rmi-example-numerical-integration-a-more-realistic-rmi-example-that-sends-an-evaluatable-object-function-from-a-client-to-a-server-for-numerical-integration","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10208","title":{"rendered":"RMI Example &#8211; Numerical Integration, a more realistic RMI example that sends an evaluatable object (function) from a client to a server for numerical integration."},"content":{"rendered":"<pre>Integral.java\u00a0 Performs actual numerical integration of the function (evaluatable object).\r\n\r\n\/** A class to calculate summations and numeric integrals. The\r\n\u00a0*\u00a0 integral is calculated according to the midpoint rule.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class Integral {\r\n\u00a0 \/** Returns the sum of f(x) from x=start to x=stop, where the\r\n\u00a0\u00a0 *\u00a0 function f is defined by the evaluate method of the\r\n\u00a0\u00a0 *\u00a0 Evaluatable object.\r\n\u00a0\u00a0 *\/\r\n\r\n\u00a0 public static double sum(double start, double stop,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 double stepSize,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Evaluatable evalObj) {\r\n\u00a0\u00a0\u00a0 double sum = 0.0, current = start;\r\n\u00a0\u00a0\u00a0 while (current &lt;= stop) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 sum += evalObj.evaluate(current);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 current += stepSize;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 return(sum);\r\n\u00a0 }\r\n\r\n\u00a0 \/** Returns an approximation of the integral of f(x) from\r\n\u00a0\u00a0 *\u00a0 start to stop, using the midpoint rule. The function f is\r\n\u00a0\u00a0 *\u00a0 defined by the evaluate method of the Evaluatable object.\r\n\u00a0\u00a0 *\/\r\n\r\n\u00a0 public static double integrate(double start, double stop,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int numSteps,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Evaluatable evalObj) {\r\n\u00a0\u00a0\u00a0 double stepSize = (stop - start) \/ (double)numSteps;\r\n\u00a0\u00a0\u00a0 start = start + stepSize \/ 2.0;\r\n\u00a0\u00a0\u00a0 return(stepSize * sum(start, stop, stepSize, evalObj));\r\n\u00a0 }\r\n}\r\n\r\n\r\n\r\nEvaluatable.java\u00a0 An interface for evaluating functions. Requires the Evaluatable\u00a0 object to implement the evaluate method. \r\n\r\n\/** An interface for evaluating functions y = f(x) at a specific\r\n\u00a0*\u00a0 value. Both x and y are double-precision floating-point\r\n\u00a0*\u00a0 numbers.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic interface Evaluatable {\r\n\u00a0 public double evaluate(double value);\r\n}\r\n\r\n\r\nRemoteIntegral.java\u00a0 Establishes the methods in the remote object available to the client. \r\n\r\nimport java.rmi.*;\r\n\r\n\/** Interface for remote numeric integration object.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic interface RemoteIntegral extends Remote {\r\n\r\n\u00a0 public double sum(double start, double stop, double stepSize,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Evaluatable evalObj)\r\n\u00a0\u00a0\u00a0 throws RemoteException;\r\n\r\n\u00a0 public double integrate(double start, double stop,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int numSteps, Evaluatable evalObj)\r\n\u00a0\u00a0\u00a0 throws RemoteException;\r\n}\r\n\r\n\r\nRemoteIntegralClient.java\u00a0 The client that sends an Evaluatable object to the remote server for integration. \r\n\r\nimport java.rmi.*;\r\nimport java.net.*;\r\nimport java.io.*;\r\n\r\n\/** This class calculates a variety of numerical integration\r\n\u00a0*\u00a0 values, printing the results of successively more accurate\r\n\u00a0*\u00a0 approximations. The actual computation is performed on a\r\n\u00a0*\u00a0 remote machine whose hostname is specified as a command-\r\n\u00a0*\u00a0 line argument.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class RemoteIntegralClient {\r\n\u00a0 public static void main(String[] args) {\r\n\u00a0\u00a0\u00a0 try {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 String host = (args.length &gt; 0) ? args[0] : \"localhost\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 RemoteIntegral remoteIntegral =\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (RemoteIntegral)Naming.lookup(\"rmi:\/\/\" + host +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\/RemoteIntegral\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 for(int steps=10; steps&lt;=10000; steps*=10) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (\"Approximated with \" + steps + \" steps:\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from 0 to pi of sin(x)=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 remoteIntegral.integrate(0.0, Math.PI,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 steps, new Sin()) +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from pi\/2 to pi of cos(x)=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 remoteIntegral.integrate(Math.PI\/2.0, Math.PI,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 steps, new Cos()) +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from 0 to 5 of x^2=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 remoteIntegral.integrate(0.0, 5.0, steps,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 new Quadratic()));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (\"`Correct' answer using Math library:\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from 0 to pi of sin(x)=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (-Math.cos(Math.PI) - -Math.cos(0.0)) +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from pi\/2 to pi of cos(x)=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (Math.sin(Math.PI) - Math.sin(Math.PI\/2.0)) +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from 0 to 5 of x^2=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (Math.pow(5.0, 3.0) \/ 3.0));\r\n\u00a0\u00a0\u00a0 } catch(RemoteException re) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"RemoteException: \" + re);\r\n\u00a0\u00a0\u00a0 } catch(NotBoundException nbe) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"NotBoundException: \" + nbe);\r\n\u00a0\u00a0\u00a0 } catch(MalformedURLException mfe) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"MalformedURLException: \" + mfe);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}\r\n\r\n\r\nSin.java\u00a0 Evaluatable version of sin(x).\r\nimport java.io.Serializable;\r\n\r\n\/** An evaluatable version of sin(x).\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\nclass Sin implements Evaluatable, Serializable {\r\n\u00a0 public double evaluate(double val) {\r\n\u00a0\u00a0\u00a0 return(Math.sin(val));\r\n\u00a0 }\r\n\r\n\u00a0 public String toString() {\r\n\u00a0\u00a0\u00a0 return(\"Sin\");\r\n\u00a0 }\r\n}\r\n\r\nCos.java\u00a0 Evaluatable version of cos(x). \r\n\r\nimport java.io.Serializable;\r\n\r\n\/** An evaluatable version of cos(x).\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\nclass Cos implements Evaluatable, Serializable {\r\n\u00a0 public double evaluate(double val) {\r\n\u00a0\u00a0\u00a0 return(Math.cos(val));\r\n\u00a0 }\r\n\r\n\u00a0 public String toString() {\r\n\u00a0\u00a0\u00a0 return(\"Cosine\");\r\n\u00a0 }\r\n}\r\n\r\n\r\nQuadratic.java\u00a0 Evaluatable version of x2. \r\n\r\n\r\nimport java.io.Serializable;\r\n\r\n\/** An evaluatable version of x^2.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\nclass Quadratic implements Evaluatable, Serializable {\r\n\u00a0 public double evaluate(double val) {\r\n\u00a0\u00a0\u00a0 return(val * val);\r\n\u00a0 }\r\n\r\n\u00a0 public String toString() {\r\n\u00a0\u00a0\u00a0 return(\"Quadratic\");\r\n\u00a0 }\r\n}\r\n\r\nRemoteIntegralImpl.java\u00a0 The remote object which provides a concrete implementation of the RemoteIntegral interface. \r\n\r\nimport java.rmi.*;\r\nimport java.rmi.server.UnicastRemoteObject;\r\n\r\n\/** The actual implementation of the RemoteIntegral interface.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class RemoteIntegralImpl extends UnicastRemoteObject\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 implements RemoteIntegral {\r\n\r\n\u00a0 \/** Constructor must throw RemoteException. *\/\r\n\r\n\u00a0 public RemoteIntegralImpl() throws RemoteException {}\r\n\r\n\u00a0 \/** Returns the sum of f(x) from x=start to x=stop, where the\r\n\u00a0\u00a0 *\u00a0 function f is defined by the evaluate method of the\r\n\u00a0\u00a0 *\u00a0 Evaluatable object.\r\n\u00a0\u00a0 *\/\r\n\r\n\u00a0 public double sum(double start, double stop, double stepSize,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Evaluatable evalObj) {\r\n\u00a0\u00a0\u00a0 return(Integral.sum(start, stop, stepSize, evalObj));\r\n\u00a0 }\r\n\r\n\u00a0 \/** Returns an approximation of the integral of f(x) from\r\n\u00a0\u00a0 *\u00a0 start to stop, using the midpoint rule. The function f is\r\n\u00a0\u00a0 *\u00a0 defined by the evaluate method of the Evaluatable object.\r\n\u00a0\u00a0 * @see #sum\r\n\u00a0\u00a0 *\/\r\n\r\n\u00a0 public double integrate(double start, double stop, int numSteps,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Evaluatable evalObj) {\r\n\u00a0\u00a0\u00a0 return(Integral.integrate(start, stop, numSteps, evalObj));\r\n\u00a0 }\r\n}\r\n\r\n\r\n\r\nRemoteIntegralServer.java\u00a0 Creates an instance of RemoteIntegralImpl on the remote server and binds the object in the registry for lookup by the client. \r\n\r\nimport java.rmi.*;\r\nimport java.net.*;\r\n\r\n\/** Creates a RemoteIntegralImpl object and registers it under\r\n\u00a0*\u00a0 the name 'RemoteIntegral' so that remote clients can connect\r\n\u00a0*\u00a0 to it for numeric integration results. The idea is to place\r\n\u00a0*\u00a0 this server on a workstation with very fast floating-point\r\n\u00a0*\u00a0 capabilities, while slower interfaces can run on smaller\r\n\u00a0*\u00a0 computers but still use the integration routines.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class RemoteIntegralServer {\r\n\u00a0 public static void main(String[] args) {\r\n\u00a0\u00a0\u00a0 try {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 RemoteIntegralImpl integral =\u00a0 new RemoteIntegralImpl();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Naming.rebind(\"rmi:\/\/\/RemoteIntegral\", integral);\r\n\u00a0\u00a0\u00a0 } catch(RemoteException re) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"RemoteException: \" + re);\r\n\u00a0\u00a0\u00a0 } catch(MalformedURLException mfe) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"MalformedURLException: \" + mfe);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}\r\n\r\n\r\nRemoteIntegralClient2.java\u00a0 An enterprise version of the client that imposes a security manager to support the Java 2 RMI 1.2 stub protocol. \r\n\r\nimport java.rmi.*;\r\nimport java.net.*;\r\nimport java.io.*;\r\n\r\n\/** This class is a Java 2 version of RemoteIntegralClient\r\n\u00a0*\u00a0 that imposes a SecurityManager to allow the client to\r\n\u00a0*\u00a0 connect to a remote machine for loading stub files and\r\n\u00a0*\u00a0 performing numerical integration through a remote\r\n\u00a0*\u00a0 object.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class RemoteIntegralClient2 {\r\n\u00a0 public static void main(String[] args) {\r\n\u00a0\u00a0\u00a0 try {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.setSecurityManager(new RMISecurityManager());\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 String host =\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (args.length &gt; 0) ? args[0] : \"localhost\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 RemoteIntegral remoteIntegral =\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (RemoteIntegral)Naming.lookup(\"rmi:\/\/\" + host +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\/RemoteIntegral\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 for(int steps=10; steps&lt;=10000; steps*=10) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (\"Approximated with \" + steps + \" steps:\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from 0 to pi of sin(x)=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 remoteIntegral.integrate(0.0, Math.PI,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 steps, new Sin()) +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from pi\/2 to pi of cos(x)=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 remoteIntegral.integrate(Math.PI\/2.0, Math.PI,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 steps, new Cos()) +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from 0 to 5 of x^2=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 remoteIntegral.integrate(0.0, 5.0, steps,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 new Quadratic()));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (\"`Correct' answer using Math library:\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from 0 to pi of sin(x)=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (-Math.cos(Math.PI) - -Math.cos(0.0)) +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from pi\/2 to pi of cos(x)=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (Math.sin(Math.PI) - Math.sin(Math.PI\/2.0)) +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\\n\u00a0 Integral from 0 to 5 of x^2=\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (Math.pow(5.0, 3.0) \/ 3.0));\r\n\u00a0\u00a0\u00a0 } catch(RemoteException re) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"RemoteException: \" + re);\r\n\u00a0\u00a0\u00a0 } catch(NotBoundException nbe) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"NotBoundException: \" + nbe);\r\n\u00a0\u00a0\u00a0 } catch(MalformedURLException mfe) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"MalformedURLException: \" + mfe);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}\r\n\r\nrmiclient.policy\u00a0 Policy file for the client. Grants permissions for the client to connect to the RMI server and Web server. \r\n\r\n\/\/\u00a0 Taken from Core Web Programming from\r\n\/\/\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\/\/\u00a0 .\r\n\/\/\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\/\/\u00a0 may be freely used or adapted.\r\n\r\ngrant {\r\n\u00a0 \/\/ rmihost - RMI registry and the server\r\n\u00a0 \/\/ webhost - HTTP server for stub classes\r\n\u00a0 permission java.net.SocketPermission \r\n\u00a0\u00a0\u00a0 \"rmihost:1024-65535\", \"connect\";\r\n\u00a0 permission java.net.SocketPermission \r\n\u00a0\u00a0\u00a0 \"webhost:80\", \"connect\";\r\n};<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Integral.java\u00a0 Performs actual numerical integration of the function (evaluatable object). \/** A class to calculate summations and numeric integrals. The \u00a0*\u00a0 integral is calculated according to the midpoint rule. \u00a0* \u00a0*\u00a0 Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 . \u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown; \u00a0*\u00a0 &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10208\">Continue reading<\/a><\/p>\n","protected":false},"author":130,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1417,1424],"tags":[706,308,1466],"class_list":["post-10208","post","type-post","status-publish","format-standard","hentry","category-code-programming-samples--","category-javaj2eej2me","tag-code","tag-java","tag-rmi","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":26747,"url":"http:\/\/bangla.sitestree.com\/?p=26747","url_meta":{"origin":10208,"position":0},"title":"# RMI Example &#8211; Numerical Integration, a more realistic RMI example that sends an evaluatable object (function) from a client to a server for numerical integration. #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 30, 2021","format":false,"excerpt":"# RMI Example - Numerical Integration, a more realistic RMI example that sends an evaluatable object (function) from a client to a server for numerical integration. Integral.java Performs actual numerical integration of the function (evaluatable object). \/** A class to calculate summations and numeric integrals. The * integral is calculated\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26745,"url":"http:\/\/bangla.sitestree.com\/?p=26745","url_meta":{"origin":10208,"position":1},"title":"RMI Example &#8211; Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes: #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 30, 2021","format":false,"excerpt":"RMI Example - Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes: Rem.java Establishes which methods the client can access in the remote object. import java.rmi.*; \/** The RMI client will use this interface directly. The RMI * server will make a\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10206,"url":"http:\/\/bangla.sitestree.com\/?p=10206","url_meta":{"origin":10208,"position":2},"title":"RMI Example &#8211; Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes","author":"","date":"August 25, 2015","format":false,"excerpt":"Rem.java\u00a0 Establishes which methods the client can access in the remote object. import java.rmi.*; \/** The RMI client will use this interface directly. The RMI \u00a0*\u00a0 server will make a real remote object that implements this, \u00a0*\u00a0 then register an instance of it with some URL. \u00a0* \u00a0*\u00a0 Taken from\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65920,"url":"http:\/\/bangla.sitestree.com\/?p=65920","url_meta":{"origin":10208,"position":3},"title":"What is Spring Framework? What does it mean to J2EE developers #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 17, 2021","format":false,"excerpt":"What is Spring Framework? What does it mean to J2EE developers? Spring is a light-weight framework, very often referred as an alternative\/competitor to EJB, for the development of enterprise-type applications. Spring provides many features such as declarative transaction management, access to remote logic using RMI or web services, mailing facilities\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":67690,"url":"http:\/\/bangla.sitestree.com\/?p=67690","url_meta":{"origin":10208,"position":4},"title":"Basic Java But Essential Knowledge for exams like SCJA, or to the project managers new to Java technologies #Computer Game Design #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 27, 2021","format":false,"excerpt":"By definition an enumerated type is a finite set of symbolic literals In Java an enumerated type is represented as first-class object. Enumerated type literals are allowed in case statements. The literals of an enumerated type may be of any valid Java identifier An interface may NOT contain any concrete\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26561,"url":"http:\/\/bangla.sitestree.com\/?p=26561","url_meta":{"origin":10208,"position":5},"title":"A Ship class illustrating object-oriented programming concepts #Programming Code Examples #Java\/J2EE\/J2ME #Object Oriented Programming","author":"Author-Check- Article-or-Video","date":"April 28, 2021","format":false,"excerpt":"************************ Ship.java A Ship class illustrating object-oriented programming concepts. Incorporates Javadoc comments. See ShipTest.java for a test. ************************ \/** Ship example to demonstrate OOP in Java. * * @author * Larry Brown * @version 2.0 *\/ public class Ship { \/\/ Instance variables private double x=0.0, y=0.0, speed=1.0, direction=0.0; private\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10208"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10208\/revisions"}],"predecessor-version":[{"id":10209,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10208\/revisions\/10209"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10208"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}