EJB instance problem

Discussions

General J2EE: EJB instance problem

  1. EJB instance problem (2 messages)

    Hi, everybody,
    I am studying Bruce Eckel`s book -- Thinking in Enterprise Java. In the Chapter Enterprise JavaBeans, there is one sentence that I cannot understand:

    Original paragraph:

    Enterprise JavaBeans (EJB) are managed, server-side components for the modular construction of enterprise applications[7].

    We’ll start our tour of Enterprise JavaBeans by exploring the meaning of these three words.

    “Component” means that EJBs are distributed in binary format and are configurable, so that the client programmer can use them to create custom applications. It’s the same concept that you see with a JavaBean graphical component: you buy a JavaBean component to create pie chart graphs, you instantiate it in your application (probably using a RAD tool such as JBuilder), you set the component’s properties to your liking (for example the background color), and you use it in your reporting application. You don’t have the source code for the pie chart component, nonetheless you can customize it to your needs. The way you instantiate, customize and use Enterprise JavaBeans is not the same as with plain JavaBeans, but the concept of being a component is the same. It’s important to make a terminological distinction between the component and its instances: we use the term Enterprise JavaBean to refer to a type of component – for example an EJB that represents a bank account; and we use the term EJB instance to refer to an object that represents a specific bank account with a unique account number.


    What I cannot understand is this sentence-- It’s important to make a terminological distinction between the component and its instances: we use the term Enterprise JavaBean to refer to a type of component – for example an EJB that represents a bank account; and we use the term EJB instance to refer to an object that represents a specific bank account with a unique account number.


    What's the meaning? What's the difference between the EJB instance and EJB object?

    Many thanks.

    Threaded Messages (2)

  2. EJB instance problem[ Go to top ]

    Hi,

    There is no "EJB object" in the quoted text. EJB instance is an Java object, which is instantiated and controlled by container (but not every Java object is an EJB)

    Regards,
    Viktor
  3. EJB instance problem[ Go to top ]

    Hi,
      Let me reply to your question: Difference between EJB instance and EJB object.

    Actually object and instance can be typically used interchangebly (although some people do use 'Object' to mean 'Class'. So actually the question should be what is a differnce between EJB instance and EJB class.

    An EJB compomnent (or class) is the definition of the EJB i.e. the class itself. But you instantiate multiple objects (or instances) of the EJB component (class). So lets elaborate on the example in the book further to understand it: An EJB component called BankAccount. It may have certain interfaces to deposit() or withdraw(). This definition itself is called a component ot a class definition.

    Typically you will intantiate an object of this class to hold data for a particular account, the key could be account id. You may also have multiple instances of this class/component. Each of these instances will provide deposit()/withdraw() kind of service for a particular user account.

    This is very similar to non-EJB classes. Say you have class called Car.
    Now when you do Car myCar = new Car("XYZ 1234"); // where XYZ 1234 is my car's registration number.

    so myCar is an object or instance of the class Car.

    HTH,
    Khushnood Naqvi