An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.
Posted Date:- 2021-09-04 00:41:22
A well-written OO program exhibits recurring structures that promote abstraction, flexibility, modularity and elegance.
Posted Date:- 2021-09-04 00:39:58
Strategically speaking, threads created by implementing Runnable interface are more advisable. If you create a thread by extending a thread class, you cannot extend any other class. If you create a thread by implementing Runnable interface, you save a space for your class to extend another class now or in future.
Posted Date:- 2021-09-04 00:38:34
The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:
Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st);
Posted Date:- 2021-09-04 00:37:08
An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.
Posted Date:- 2021-09-04 00:36:19
One more popular EJB interview question, not seen through it for some time but still an important question on EJB to prepare.
Ans: Both of these methods are used in the context of entity bean for the purpose of synchronizing the instance variable to the corresponding value store in the database. ejbLoad method load or refresh the instance variable from the database and ejbStore method writes variables value back to the database.
Posted Date:- 2021-09-04 00:35:15
No, Not possible because EJBs are created and managed by container and if in ejbs we allow threading containers life cycle methods will be interrupted by us and also the purpose of EJB is to perform business logic not to controlling a system or implementation level functioning so container will manage the thread and developer can concentrate on business logic.
Posted Date:- 2021-09-04 00:34:34
These were some of the EJB interview questions for practice if you are going to appear in any Java or J2EE interview which requires EJB skills. There are not many J2EE programmer who understand and use EJB very well. It was more difficult when EJB 2.0 was around but much better with EJB 3.0 and EJB 3.1. Please share if you have any other interesting EJB interview question or if you know answer of any EJB question shared here.
Posted Date:- 2021-09-04 00:33:30
No. Decorator design pattern, is the one which exhibits very low level runtime polymorphism, for the specific and single object (Instance of the class), but not for atleast for a class. It is the stuff to add specific functionality to a single & pointed object and leaves others like it unmodified. It is having close similarities like aspectJ stuff, but not with EJB stuff.
Posted Date:- 2021-09-04 00:32:05
There is a pure division of roles between the two. Home Interface is the way to communicate with the container which is responsible for creating , locating and removing beans and Remote Interface is the link to the bean that allows acces to all methods and members.
Posted Date:- 2021-09-04 00:30:58
J2EE is a platform for developing distributed enterprise applications that have many features lime security, state management, resource management, transaction management, etc. EJB is a part of J2EE that is an API used for developing enterprise applications. EJB make the application scalable.
Posted Date:- 2021-09-04 00:29:49
The reasons to choose EJB over Spring bean are as follows:
EJB has better support for Web services like JAS-WS 2.0 than
Messaging is easy in EJB through Message Driven beans whereas Spring needs to be configured for messaging.
EJB provides better security through JAAS whereas configuration needs to be added to Spring.
Posted Date:- 2021-09-04 00:29:08
The ejb-jar.xml file is located in the following places:
>> In case of a WAR, it is located in the /WEB-INF directory.
>> In case of a JAR, it is located in the /META-INF directory.
Posted Date:- 2021-09-04 00:28:29
The home interface is an interface that has methods that can be associated with all EJB of a class. It specifies the methods used by a client for developing and retrieving a bean instance. For creating a bean instance, the create method is used. For every creates method an ejbCreate method has to be defined.
Posted Date:- 2021-09-04 00:27:22
The EJB version can be checked by the following ways:
>> The EJB-jar.xml and application.xml file have to be checked. The version is present in the beginning lines of the XML file.
>> The ejb-jar.xml deployment descriptor can be used to find the version of EJB.
Posted Date:- 2021-09-04 00:26:52
EJB uses the RMI-IIOP protocol that stands for Internet Inter-ORB Protocol is used for communication that uses a Common Object Request Broker Architecture (CORBA). The IIOP protocol is used for distributed communication and can be executed on all platforms. Here RMI stands for Remote Method Invocation that is used for transferring messages from one JVM to another over a network.
Posted Date:- 2021-09-04 00:26:07
Static class fields that are not final are not allowed in EJB because they make it very difficult to distribute. These static class can behave differently when they run in a single JVM (Java Virtual Machine) which can create problems.
Posted Date:- 2021-09-04 00:25:33
The remote client view specification is only available in EJB 2.0. The remote client view of an enterprise bean is location independent. A client running in the same JVM as a bean instance uses the same API to access the bean as a client running in a different JVM on the same or different machine.
Remote interface: The remote interface specifies the remote business methods that a client can call on an enterprise bean.
Remote home interface: The remote home interface specifies the methods used by remote clients for locating, creating, and removing instances of enterprise bean classes.
Posted Date:- 2021-09-04 00:24:35
The local client view specification is only available in EJB 2.0. Unlike the remote client view, the local client view of a bean is location dependent. Local client view access to an enterprise bean requires both the local client and the enterprise bean that provides the local client view to be in the same JVM. The local client view therefore does not provide the location transparency provided by the remote client view. Local interfaces and local home interfaces provide support for lightweight access from enterprise bean that are local clients. Session and entity beans can be tightly couple with their clients, allowing access without the overhead typically associated with remote method calls.
Posted Date:- 2021-09-04 00:23:50
The data consistency is maintained by updating their fields every time a commitment of the transaction is made.
Posted Date:- 2021-09-04 00:22:34
When “one to one” mapping is involved, and the data is stored persistently is regional database, CMP is preferred. But when no “one to one” mapping is there and data is retrieved from numerous tables having a complex query, Bean Managed Persistence is used.
Posted Date:- 2021-09-04 00:22:10
A deployment descriptor is an XML file packaged with the enterprise beans in an EJB JAR file or an EAR file. It contains metadata describing the contents and structure of the enterprise beans, and runtime transaction and security information for the EJB container.
Posted Date:- 2021-09-04 00:18:03
Static variables are only ok if they are final. If they are not final, they will break the cluster. What that means is that if you cluster your application server (spread it across several machines) each part of the cluster will run in its own JVM.
Say a method on the EJB is invoked on cluster 1 (we will have two clusters – 1 and 2) that causes value of the static variable to be increased to 101. On the subsequent call to the same EJB from the same client, a cluster 2 may be invoked to handle the request. A value of the static variable in cluster 2 is still 100 because it was not increased yet and therefore your application ceases to be consistent. Therefore, static non-final variables are strongly discouraged in EJBs.
Posted Date:- 2021-09-04 00:15:31
The changes made are:
>> Message Driven Beans (MDBs): messages are accepted from other >> sources besides JMS.
>> EJB Query Language: New functions had been added.
>> Web services supported.
>> EJB Timer Service: Mechanism based on an event to invoke EJBs at particular times.
>> XML schema
>> Message destinations
Posted Date:- 2021-09-04 00:12:56
Modules are packaged based on their functionality as EAR, JAR and WAR files.
JAR files (.jar) : Modules which contain EJB class files and EJB deployment descriptor are packed as JAR files.
WAR Files (.war) : Web modules which contain Servlet class files, JSP Files, supporting files, GIF and HTML files are packaged as JAR file.
EAR Files (.ear) : ‘.jar’ & ‘.war’ files are packaged as JAR files. ‘Ear’ stands for enterprise archive. These files are deployed in the application server.
Posted Date:- 2021-09-04 00:11:27
While both undergo activation and passivation; EB have ejbStore () callback to save state through passivation and ejbLoad () callback to load state through activation. But in case of SS, this is not needed because S.S.B fields are serialized through objects by containers.
Posted Date:- 2021-09-04 00:09:47
Heavy weight application consume a lot of time while loading the plug-ins. In lazy loading approach, the plug-ins that are needed at that particular time are loaded and instantiated. This boosts up the performance as only the plug-ins that are used are loaded. This also ensures the efficiency and speeds up the initial load time of the applications. Applications like Eclipse use this approach. In other words, the goal of lazy loading is to dedicate memory only when it is absolutely necessary.
Posted Date:- 2021-09-04 00:08:10
EJB QL stands for Enterprise Java Beans - Query Language. It was introduced in the EJB 2.0 specification. QL provides navigation across network of EJBs and dependent objects which are defined by means of container managed persistence. Persistence is the ability to save the current state of a bean. EJB QL is portable across containers and persistence managers.
Finder Methods: These are defined in the home interface of an entity bean and which return entity objects.
Select methods: These are not exposed to the client. However, these are used by bean providers to select persistence values or entity objects related to entity bean which the query is defined on.
Posted Date:- 2021-09-04 00:07:45
When “one to one” mapping is involved, and the data is stored persistently is regional database, CMP is preferred. But when no “one to one” mapping is there and data is retrieved from numerous tables having a complex query, Bean Managed Persistence is used.
Posted Date:- 2021-09-04 00:07:15
As per the specifications, there can be ‘ZERO’ or ‘MORE’ create() methods defined in an Entity Bean. In cases where create() method is not provided, the only way to access the bean is by knowing its primary key, and by acquiring a handle to it by using its corresponding finder method. In those cases, you can create an instance of a bean based on the data present in the table. All one needs to know is the primary key of that table. i.e. a set a columns that uniquely identify a single row in that table. Once this is known, one can use the ‘getPrimaryKey()’ to get a remote reference to that bean, which can further be used to invoke business methods.
Posted Date:- 2021-09-04 00:05:35
The transaction attribute specifies how the Container must manage transactions for a method when a client invokes the method via the enterprise bean’s home or component interface or when the method is invoked as the result of the arrival of a JMS message. (Sun’s EJB Specification) Below is a list of transactional attributes:
1. NotSupported – transaction context is unspecified.
2. Required – bean’s method invocation is made within a transactional context. If a client is not associated with a transaction, a new transaction is invoked automatically.
3. Supports – if a transactional context exists, a Container acts like the transaction attribute is Required, else – like NotSupported.
4. RequiresNew – a method is invoked in a new transaction context.
5. Mandatory – if a transactional context exists, a Container acts like the transaction attribute is Required, else it throws a javax.ejb.TransactionRequiredException.
6. Never – a method executes only if no transaction context is specified.
Posted Date:- 2021-09-04 00:05:11
Acronym for Plain Old Java Object. POJO, or Plain Old Java Object, is a normalJava object class (that is, not a JavaBean, EntityBean etc.) and does not serve any other special role nor does it implement any special interfaces of any of the Javaframeworks.
Following are the key components of persistence API in EJB:
Entity – A persistent object representing the data-store record. It is good to be serializable.
EntityManager – Persistence interface to do data operations like add/delete/update/find on persistent object(entity). It also helps to execute queries using Query interface.
Persistence unit (persistence.xml) – Persistence unit describes the properties of persistence mechanism.
Data Source (*ds.xml) – Data Source describes the data-store related properties like connection url. user-name,password etc.
Posted Date:- 2021-09-04 00:04:45
This is another tough Java question on EJB interview. Putting complex business logic in stored procedure is not a good idea but its been there for long time. Main advantage of using EJB over stored procedure is that you don't need to port your SQL Stored procedure code when you change database e.g. form Sybase to Oracle or Oracle to SQL Server.
Posted Date:- 2021-09-04 00:00:40
If you have mentioned in your resume that you have worked on EJB 2.0, then better be prepared for this EJB interview question. It's not difficult to answer if you have indeed worked in EJB 2.0. There are several pain e.g. writing those local and remote interfaces, too many boiler plate coding etc.
Posted Date:- 2021-09-04 00:00:08
One of the tricky interview question on EJB. No you can not run EJB in web server like Tomcat. You need application server like Glassfish, WebLogic or Websphere to run Enterprise Java beans.
Posted Date:- 2021-09-03 23:59:39
They are:
>> MANDATORY:
>> REQUIRED
>> REQUIRES_NEW
>> SUPPORTS
>> NOT_SUPPORTED
>> NEVER
Posted Date:- 2021-09-03 23:58:33
Between the client and the session bean, the state of the conversation can be maintained using a stateful session bean. The instance variables contain a state only during the invocation by a client method.
It implements ‘javax.ejb.SessionBean’ interface and is deployed with the declarative attribute ‘stateful’.
They have instance fields that can be initialized and modified by the client with each method invocation. The bean can use the conversational states as its business process methods.
Posted Date:- 2021-09-03 23:57:42
An EJB client JAR file is an optional JAR file that can contain all the class files that a client program needs to use the client view of the enterprise beans that are contained in the EJB JAR file. If you decide not to create a client JAR file for an EJB module, all of the client interface classes will be in the EJB JAR file.
Posted Date:- 2021-09-03 23:57:02
They are:
<> Session Beans: Expanded as “Stateful”,”Stateless” and “Singleton”, A Remote or Local interface is used to access the EJB files.
<> Message Driven Beans (MDB): Asynchronous execution by means of messaging paradigm is supported.
Posted Date:- 2021-09-03 23:54:42
EJB was taken over by Sun Microsystems in 1999.
Posted Date:- 2021-09-03 23:53:55
Session and Entity EJBs consist of 4 and 5 parts respetively:
1. A remote interface (a client interacts with it),
2. A home interface (used for creating objects and for declaring business methods),
3. A bean object (an object, which actually performs business logic and EJB-specific operations).
4. A deployment descriptor (an XML file containing all information required for maintaining the EJB) or a set of deployment descriptors (if you are using some container-specific features).
5.A Primary Key class – is only Entity bean specific
Posted Date:- 2021-09-03 23:53:08
It manages and coordinates the allocation of resources to the applications. Enterprise beans typically contain the business logic for a J2EE application. TheEJB server must provide one or more EJB containers. An EJB container manages the enterprise beans contained within it.
Posted Date:- 2021-09-03 23:52:44
The different types of session beans are available in EJB are:
<> Stateful session beans
<> Stateless session beans
<> Singleton session beans
Posted Date:- 2021-09-03 23:52:23
Following are the key benefits of EJB.
<> Simplified development of large scale enterprise level application.
<> Application Server/ EJB container provides most of the system level services like transaction handling, logging, load balancing, persistence mechanism, exception handling and so on. Developer has to focus only on business logic of the application.
<> EJB container manages life cycle of ejb instances thus developer needs not to worry about when to create/delete ejb objects.
Posted Date:- 2021-09-03 23:51:38
EJB Calls from Servlets. A servlet can call Enterprise JavaBeans to perform additional processing. A typical application design often uses servlets as a front-end to do the initial processing of client requests, with EJBs being called to perform the business logic that accesses or updates a database.
Posted Date:- 2021-09-03 23:50:40
A session bean is a bean component developed by the client for storing the session data for a specific session. It performs different operations for the client. In the case of system failure, the session bean cannot be recovered. The bean is transactional but can be stateless or stateful. They get destroyed as soon as the session gets over.
Posted Date:- 2021-09-03 23:48:33
An EJB container is also called the application server that is an environment used for executing applications. It handles the security authorization and transactional management of an application so that the developer can focus on the important business logic.
The container also handles object pooling and life cycle management. Commonly used EJB containers are Glassfish, JBoss and Weblogic.
Posted Date:- 2021-09-03 23:45:41
The important features of EJB are as follows:
<> The EJB architecture is scalable, portable, distributed and transactional.
<> EJB components do not contain any system level programming and have only business logic.
<> EJB components are platform independent and are coded in Java.
The life cycle of EJB instances is managed by the EJB container.
Posted Date:- 2021-09-03 23:45:10
EJB stands for Enterprise Java Beans that is a Java application-programming interface. It is a server-side API and is used for developing enterprise applications which are large, high performing and scalable. Any EJB application can be executed in a server that complies with the J2EE 1.3 standards.
Posted Date:- 2021-09-03 23:44:22