Won Contests Let Us Talk Mail Me Light of Knowledge


 C lient Code Development
  
 Building the Client

     Client code is something which helps the Client or the End user to Acces the Actual Bean Related Data in other words end user will interact with the Client Code and Client Code will interact with the bean get data as requested by the client and return the data back to End User

     Simple Example will be , u go to a Hotel , u are the end user, u will request your food order to the waiter there, who is like a client code this waiter will go to kitchen and brings out the dish as u had requested it, so the chefs in the Kitchens are like Java Beans with whom u really do not interact, Hotel Manager is responsible for Business logic , what is the cost of which item , u may not even meet the manager at all......

 
 Actual Client Code => C:\myejb\myClient.java
Color Coding :

Gray : Comments
Maroon : Skeleton Framework for Client Code
Blue : Code Related to Get the Bean Info
	import javax.naming.Context;
	import javax.naming.InitialContext;
	import javax.rmi.PortableRemoteObject;

	// import Home and Remote Interfaces
	import myRemote;
	import myHome;

	public class myClient 
	{
	  public static void main(String[] args) 
	  {
		try 
		{
		  //Locate the Home Interface
		  Context initial = new InitialContext();
		  
		  //Retrieve the object bound to the name myJNDI
		  Object objref = initial.lookup("myJNDI");

		  //Narrow the reference to a myHome object
		  myHome home = (myHome)PortableRemoteObject.narrow(objref, myHome.class);

		  //Invoke create method of myHome Object
		  myRemote myRemote_object = home.create();
		
		  //Calling a business method "find_income"
		  double income = myRemote_object.find_income(3500,1200,800);

		  //Calling a business method "find_savings"
		  int expense=2000;
		  double savings = myRemote_object.find_savings(income,expense);
		
		  //Display final output at command prompt
		  System.out.println("My income is " +String.valueOf(income));
		  System.out.println("My Savings is" +String.valueOf(savings));

	           //Remove the Object Created
	           myRemote_object.remove();
			  
      		}
      		catch (Exception ex) 
      		{
         		  System.err.println("Caught an unexpected exception!");
         		  ex.printStackTrace();
      		}
   	    }
	} 
 Compiling the Client's Code : Create C:/myejb/compileClient.bat
set J2EE_HOME=C:\j2sdkee1.3.1
set CPATH=C:\j2sdkee1.3.1\lib\j2ee.jar;C:\myejb
javac -classpath %CPATH% myClient.java
C:\myejb\>compileClient
 Running the Client : Create C:/myejb/testClient.bat
set J2EE_HOME=C:\j2sdkee1.3.1
set CPATH=C:\j2sdkee1.3.1\lib\j2ee.jar;C:\myejb;myAppClient.jar
java -classpath "%CPATH%" myClient
C:\myejb\>testClient

Caught an unexpected Exception!
javax.naming.CommunicationException: Can't find SerialContextProvided
........
..................
OOPS! oh my god what to do now ? what went wrong ? :-(
Start the Server :-)


C:\myejb\>deploytool

........
..................
J2EE Server startup complete.

C:\myejb\>testClient
My income is 5500.0
My Savings is 3500.0

 NEXT >> Working with Session Beans

 My Dream to be your Friend and Create a Group of Intelligent and Understanding Programmers
     If you like this article and/or code mailme or Join our small Java User Group which is by the Programmers for the Programmers ,
Till we meet next time BYE      Kind Regards - James Smith

  Java, J2EE, J2SE and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc.
in the United States and other countries.