{"id":10206,"date":"2015-08-25T00:00:04","date_gmt":"2015-08-25T04:00:04","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10206"},"modified":"2015-08-24T08:41:20","modified_gmt":"2015-08-24T12:41:20","slug":"rmi-example-message-illustrates-retrieving-a-message-from-an-object-located-on-a-remote-server-requires-the-following-classes","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10206","title":{"rendered":"RMI Example &#8211; Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes"},"content":{"rendered":"<pre>Rem.java\u00a0 Establishes which methods the client can access in the remote object. \r\n\r\n\r\n\r\n\r\n\r\nimport java.rmi.*;\r\n\r\n\/** The RMI client will use this interface directly. The RMI\r\n\u00a0*\u00a0 server will make a real remote object that implements this,\r\n\u00a0*\u00a0 then register an instance of it with some URL.\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 Rem extends Remote {\r\n\u00a0 public String getMessage() throws RemoteException;\r\n}\r\n\r\n\r\nRemClient.java\u00a0 The client application which communicates to the remote object and retrieves the message. \r\n\r\nimport java.rmi.*; \/\/ For Naming, RemoteException, etc.\r\nimport java.net.*; \/\/ For MalformedURLException\r\nimport java.io.*;\u00a0 \/\/ For Serializable interface\r\n\r\n\/** Get a Rem object from the specified remote host.\r\n\u00a0*\u00a0 Use its methods as though it were a local 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 RemClient {\r\n\u00a0 public static void main(String[] args) {\r\n\u00a0\u00a0\u00a0 try {\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 \/\/ Get the remote object and store it in remObject:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Rem remObject =\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (Rem)Naming.lookup(\"rmi:\/\/\" + host + \"\/Rem\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Call methods in remObject:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(remObject.getMessage());\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\nRemImpl.java\u00a0 The concrete, remote object that implements the methods in Rem.java. \r\n\r\nimport java.rmi.*;\r\nimport java.rmi.server.UnicastRemoteObject;\r\n\r\n\/** This is the actual implementation of Rem that the RMI\r\n\u00a0*\u00a0 server uses. The server builds an instance of this, then\r\n\u00a0*\u00a0 registers it with a URL. The client accesses the URL and\r\n\u00a0*\u00a0 binds the result to a Rem (not a RemImpl; it doesn't\r\n\u00a0*\u00a0 have this).\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 RemImpl extends UnicastRemoteObject\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 implements Rem {\r\n\u00a0 public RemImpl() throws RemoteException {}\r\n\r\n\u00a0 public String getMessage() throws RemoteException {\r\n\u00a0\u00a0\u00a0 return(\"Here is a remote message.\");\r\n\u00a0 }\r\n}\r\n\r\n\r\nRemServer.java\u00a0 Creates an instance of RemImpl 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\/** The server creates a RemImpl (which implements the Rem\r\n\u00a0*\u00a0 interface), then registers it with the URL Rem, where\r\n\u00a0*\u00a0 clients can access it.\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 RemServer {\r\n\u00a0 public static void main(String[] args) {\r\n\u00a0\u00a0\u00a0 try {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 RemImpl localObject = new RemImpl();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Naming.rebind(\"rmi:\/\/\/Rem\", localObject);\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}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 Core Web Programming from \u00a0*\u00a0 &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10206\">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,285],"class_list":["post-10206","post","type-post","status-publish","format-standard","hentry","category-code-programming-samples--","category-javaj2eej2me","tag-code","tag-java","tag-rmi","tag-285","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":26745,"url":"http:\/\/bangla.sitestree.com\/?p=26745","url_meta":{"origin":10206,"position":0},"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":10208,"url":"http:\/\/bangla.sitestree.com\/?p=10208","url_meta":{"origin":10206,"position":1},"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.","author":"","date":"August 25, 2015","format":false,"excerpt":"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\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":26747,"url":"http:\/\/bangla.sitestree.com\/?p=26747","url_meta":{"origin":10206,"position":2},"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":67690,"url":"http:\/\/bangla.sitestree.com\/?p=67690","url_meta":{"origin":10206,"position":3},"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":66324,"url":"http:\/\/bangla.sitestree.com\/?p=66324","url_meta":{"origin":10206,"position":4},"title":"EJB Overview: EJB in a nutshell #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"Objects provide encapsulation\/re-usability at the class level. A component can be comprised of multiple objects Component = logical groups of classes = distributed objects = business objects A component can be developed to address a specific enterprise applications. Hence, components can provide significant encapsulation\/re-usability in the partitioned enterprise problems. Component\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":65920,"url":"http:\/\/bangla.sitestree.com\/?p=65920","url_meta":{"origin":10206,"position":5},"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":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10206","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=10206"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10206\/revisions"}],"predecessor-version":[{"id":10207,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10206\/revisions\/10207"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10206"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}