Thursday, August 13, 2015

Java Beans Overview

About Java Beans

Java Bean is an implementation standard.

  • Serialize.
  • Zero-argument constructor.
  • Encapsulated properties (private) with access through getters & setters.

So, the bean can be mentioned as reusable software component in Java.
In other-words almost any class that follows this convention can be a Java Bean.

A bean can generate & receive the events from other objects.
A java bean can be configured to act in different ways, its config can be saved and restored from persistent storage.
Despite the growing amount of getters & setters that leads to boilerplate code, its flexible & can be well controlled by application.


CDI Managed Bean

A top-level Java class is managed bean if it's defined to be such by any other Java EE technology specification e.g. JSF spec. or if it fits the following standards:

  • It's not a nonstatic inner class.
  • It's a concrete class or is annotated @Decorator.
  • It's not annotated or declared as an EJB bean class in ejb-jar.xml.
  • It has either nonargument constructor or it declares a constructor annotated with @Inject.

No special annotation is required to define a managed bean. CDI beans could make use of scopes, interceptors, events, type safe injection, producer methods, decorator & stereotypes. So, CDI beans a far more advanced than JSF beans, and it's definitely woul'd be a better choice.

Note: if u've decided to use CDI beans instead of EJB in the distributed system (when u need remote access) u'll need to write your own implementation to maintain it.


Enterprise Java Beans

An EnterpriseJava Bean is a standardized modular component intended to provide encapsulated business logic for enterprise applications. A Java component is a bean if it can be managed by the EJB container according to Life Cycle (Stateful, Stateless, Entity, Message). It provides the system-level services, like a session management, security, resource pooling, etc. Almost any Java type may be a bean type of a bean.

  • Bean type may be an interface, an abstract or a concrete class & might be declared final.
  • Bean may be parameterized with type parameters & variables.
  • Bean type can be a raw type, a primitive type or an array type.

Enterprise Java Beans have the following benefits:

  • transactional;
  • local or remote;
  • able to passivate beans freeing up resources;
  • could be asynchronous;
  • might use the timers & timeouts.

Entity bean vs Session bean

Let's take a look on the Session against Entity objects characteristics first:

Session Objects

  • within a specific client session;
  • conversational state;
  • no memory outside the client session.

Entity objects

  • persistent;
  • unique primary key;
  • stores data across client sessions.

Session beans

Session bean stores data for a single session and gets destroyed as user session terminates. It can be either stateful, stateless or singleton & its less resource intensive than entity bean. Extends javax.ejb.SessionBean class.
For example Session Bean can process the sale orders or email the confirmation message to customer.

Entity beans

Entity bean represents the persistent data storage.
User data can be saved & retrieved from the database via entity bean. Extends the javax.ejb.EntityBean class.
For example Stock Entity Bean can contain getPrice() & setPrice() methods to represent data from persistent storage.

Message driven beans

Unlike a session bean, a message-driven bean has only a bean class, so, the clients do not access these through interfaces. Message driven beans merely similar to stateless session bean:

  • retain no data or conversational state for a specific client;
  • because of equality of instances EJB container can assign a message to any those message-driven bean instances; also those instances could be pooled by container allowing to be processed concurrently;
  • single message-driven bean can process messages from different clients.

Message-driven beans:

  • short-lived;
  • invoked asynchronously;
  • execute upon a client message receipt;
  • don't represent the DB data (but can access & update it);
  • stateless;
  • could be transaction-aware.

Session beans allow to send & receive JMS messages synchronously but not asynchronously. Message-driven beans are used to receive messages asynchronously avoiding tying up server resources.


see Also

29 comments:

  1. Yeap, Applications written to the EJB 3.0 and later APIs should use the facilities of the Java Persistence API (javax.persistence) to model persistent entities

    ReplyDelete
  2. Thanks a lot! You made a new blog entry to answer my question; I really appreciate your time and effort.
    best java training institute in chennai |
    java training institutes in chennai

    ReplyDelete
  3. Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in
    Click here:
    angularjs training in chennai
    Click here:
    angularjs2 training in chennai

    ReplyDelete
  4. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts
    Microsoft azure training in chennai
    Click here:
    Microsoft azure training in online
    Click here:
    Microsoft azure training in bangalore
    Click here:
    Microsoft azure training in pune

    ReplyDelete
  5. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 
    Blueprism training in velachery

    Blueprism training in marathahalli


    AWS Training in chennai

    ReplyDelete
  6. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    Devops Training in Chennai

    Devops Training in Bangalore

    ReplyDelete
  7. Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries.
    java training in chennai | java training in USA

    java training in indira nagar

    ReplyDelete
  8. Thank you so much for a well written, easy to understand article on this. It can get really confusing when trying to explain it – but you did a great job. Thank you!
    Data Science training in kalyan nagar | Data Science training in OMR
    Data Science training in chennai | Data science training in velachery
    Data science training in tambaram | Data science training in jaya nagar

    ReplyDelete
  9. It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete

  10. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.


    AWS Training in BTM Layout |Best AWS Training in BTM Layout

    AWS Training in Marathahalli | Best AWS Training in Marathahalli


    ReplyDelete
  11. This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot. 
    angularjs online training

    apache spark online training

    informatica mdm online training

    devops online training

    aws online training

    ReplyDelete
  12. I am a regular reader of your blog and I discover it surely informative.
    Hope greater Articles From You.

    click here formore info.

    ReplyDelete
  13. Nice post. Thanks for sharing! I want humans to understand simply how excellent this facts is to your article.
    It’s thrilling content material and Great work.
    300mb movies

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. this one is wonderful


    BEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT

    https://www.acte.in/angular-js-training-in-chennai
    https://www.acte.in/angular-js-training-in-annanagar
    https://www.acte.in/angular-js-training-in-omr
    https://www.acte.in/angular-js-training-in-porur
    https://www.acte.in/angular-js-training-in-tambaram
    https://www.acte.in/angular-js-training-in-velachery

    ReplyDelete
  16. v Great Article
    Cloud Computing Projects


    Networking Projects

    Final Year Projects for CSE


    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete
  17. Thank you for sharing such detailed Blog. I am learning a lot from you. Visit my website to get best Information About Best UPSC Coaching Institute in Andheri
    Best UPSC Coaching Institute in Andheri
    Top UPSC Coaching Institute in Andheri

    ReplyDelete
  18. This is an awesome post. Really very informative and creative contents. Visit my website to get best Information About Top UPSC Coaching Institute in Bhandup.
    Top UPSC Coaching Institute in Bhandup
    UPSC Coaching Institute in Bhandup

    ReplyDelete
  19. This is an awesome post. Really very informative and creative contents. Visit my website to get best Information About Modular kitchen in Ghaziabad.
    Modular kitchen in Ghaziabad
    Modular Kitchen in Noida

    ReplyDelete