Sunday, 20 April 2014

Creating Stateless Session Bean Using NetBeans 7.4 with Companion Video on YouTube

In this article we will learn how to create a Stateless Session Bean in NetBeans 7.4. There is a screen cast video for this article on YouTube (Creating Sample Stateless Session Bean in NetBeans 7.4)


Session beans are the part of Enterprise Java Beans (EJB) which are based on RMI as basic foundation technology. Good Introduction to Enrerprise Java Beans its types and application is been provided by Oracle Inc on its site at  J2EE Tutorial (PDF)

A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean like Remote Method Invocation , the bean’s instance variables may contain a state specific to that client but only for the duration of the invocation. When the method is finished, the client-specific state should not be retained.

Most Often Stateless Session beans are more scalable due to their stateless nature.It is to be noted that it is developers responsibility that he/she does not include any code which may turn out to be a non-transient data for clients request for invocation of session beans business method.

When Creating stateless session beans in NetBeans we need to follow the following steps in general.
As like RMI where every client has a copy of interface containing  remote method's declaration , Session Bean's Remote interface is distributed in form of Java Class Library , a .file jar. So before we start creating session bean its good we create a blank Java Class Library Project.

We will be creating a Session Bean with business method "int getSquare(int var)" which would return us square value of argument passed. Finally we will create a java servlet to access Session Bean's business method as a client.

Step 1: Create a blank Java Class Library Project. with a proper name and remember the name of the the project created you need select this project while creating Remote interface  for Session Bean in Step 2



Step 2: Create an Enterprise application with EJB Module and Web Project. Ensure that you are selecting GlassFish as a Server ,since Apache Tomcat does not come with EJB Container.





After you are done with creating  Enterprise application you will find that two projects have been created one with EJB module and Other with Web Module in which you write a Servlet to act as Client.

Add a new Session Bean to the EJB module , the type of Session bean should be Stateless and also create Remote and Local Interfaces for the created Bean



While creating Remote interface you need to select the Java Class Library Project which you have created in Step 1 to hold Remote interface which would be containing Business method's declaration.


 Add a Business method to your Session Bean



Step 4: Create a Servlet in Web Project and call EJB's Business method







Step 5: Deploy the Enterprise Project and call servlet in browser by using its context path.


Your Servlet's output should look somewhat like below screen




Happy Coding !!! :)







17 comments:

  1. I have read your blog its very attractive and impressive. I like it your blog.


    JavaEE Training in Chennai JavaEE Training in Chennai

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Java 8 Training in Chennai

    ReplyDelete
    Replies
    1. IEEE Cloud computing DOamin is a general term for anything that involves delivering hosted services over the Internet. IEEE Projects on Cloud Computing The cloud is a metaphor for a global network of remote servers which operates as a single ecosystem, commonly associated with the Internet. IEEE FInal Year Project Domains Final Year Projects for CSE cloud computing is the delivery of computing services—including servers, storage, databases, networking, software, analytics, and intelligence


      JavaScript Training in Chennai


      JavaScript Training in Chennai

      Delete
    2. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
      Cyber Security Projects for Final Year

      JavaScript Training in Chennai

      Project Centers in Chennai

      JavaScript Training in Chennai

      Delete
  2. Spring's spring-beans institution has an org.springframework.beans.BeanUtils class that implements a copyProperties method for copying a source object instance into a target object occurrence. However, it only does so for the object's initial level fields.If you want to belong become learning for Java Real-Time Training and Live High-Level Experience instructor Trained from Java Training Programme Course to reach us
    Java Training in Chennai | Java Training Institute in Chennai

    ReplyDelete
  3. Great way of explaining.. searched the whole internet but didn't found such resource.. thnx a ton!

    ReplyDelete
  4. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site. hadoop training in bangalore

    ReplyDelete
  5. AWS Training in Bangalore - Live Online & Classroom
    myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.


    IOT Training in Bangalore - Live Online & Classroom
    IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Reading data through the sensors and processing it with applications sitting in the cloud and thereafter passing the processed data to generate different kind of output is the motive of the complete curricula. Students are made to understand the type of input devices and communications among the devices in a wireless media.

    ReplyDelete
  6. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  7. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete