YouTube Icon

Interview Questions.

Top 100+ Java & Ejb & Spring Interview Questions And Answers - May 31, 2020

fluid

Top 100+ Java & Ejb & Spring Interview Questions And Answers

Question 1. What Is An Interface?

Answer :

An interface is a set of abstract techniques. A magnificence implements an interface, thereby inheriting the summary methods of the interface.

Question 2. Give Some Features Of Interface?

Answer :

Interface cannot be instantiated
An interface does not comprise any constructors.
All of the strategies in an interface are summary.
Adv Java Interview Questions
Question 3. Which Are The Two Subclasses Under Exception Class?

Answer :

The Exception elegance has two essential subclasses : IOException magnificence and RuntimeException Class

Question 4. When Throws Keyword Is Used?

Answer :

If a way does not manage a checked exception, the approach have to declare it using the throwskeyword. The throws key-word appears at the give up of a method's signature..

Adv Java Tutorial
Question 5. When Throw Keyword Is Used?

Answer :

An exception may be thrown, either a newly instantiated one or an exception that you simply caught, through the use of throw key-word.

J2EE Interview Questions
Question 6. How Finally Used Under Exception Handling?

Answer :

The subsequently keyword is used to create a block of code that follows a attempt block. A ultimately block of code usually executes, whether or not or no longer an exception has happened.

Question 7. What Things Should Be Kept In Mind While Creating Your Own Exceptions In Java?

Answer :

While growing your very own exception −

All exceptions ought to be a child of Throwable.
If you want to jot down a checked exception that is automatically enforced via the Handle or Declare Rule, you want to extend the Exception magnificence.
You need to put in writing a runtime exception, you want to extend the RuntimeException magnificence.
J2EE Tutorial Core Java Interview Questions
Question 8. Define Inheritance?

Answer :

It is the procedure in which one item acquires the properties of every other. With the usage of inheritance the records is made attainable in a hierarchical order.

Question nine. When Super Keyword Is Used?

Answer :

If the method overrides considered one of its superclass's methods, overridden technique can be invoked through using the keyword fantastic. It may be also used to consult a hidden area.

JSP Interview Questions
Question 10. What Is Polymorphism?

Answer :

Polymorphism is the potential of an object to take on many forms. The maximum commonplace use of polymorphism in OOP takes place when a figure elegance reference is used to refer to a child magnificence item.

Core Java Tutorial
Question eleven. What Is Abstraction?

Answer :

It refers back to the ability to make a class summary in OOP. It facilitates to lessen the complexity and also improves the maintainability of the gadget.

Java-Springs Interview Questions
Question 12. What Is Abstract Class?

Answer :

These training cannot be instantiated and are either in part implemented or in no way implemented. This elegance consists of one or greater abstract methods which are virtually method declarations without a frame.

Adv Java Interview Questions
Question 13. When Abstract Methods Are Used?

Answer :

If you want a category to incorporate a specific technique but you want the actual implementation of that technique to be decided through child lessons, you may claim the technique within the discern magnificence as abstract.

JSP Tutorial
Question 14. Is Jdk Required On Each Machine To Run A Java Program?

Answer :

JDK is development Kit of Java and is required for improvement best and to run a Java program on a system, JDK isn’t required. Only JRE is needed.

Question 15. Can A Constructor Have Different Name Than A Class Name In Java?

Answer :

Constructor in Java have to have equal call because the elegance call and if the name is different, it doesn’t act as a constructor and compiler thinks of it as a regular technique.

JMS(Java Message Service) Interview Questions
Question sixteen. Can We Use Goto In Java To Go To A Particular Line?

Answer :

In Java, there is not goto keyword and java doesn’t guide this feature of going to a specific categorised line.

 

Java-Springs Tutorial
Question 17. Can A Dead Thread Be Started Again?

Answer :

In java, a thread that is in useless state can’t be commenced once more. There isn't any manner to restart a useless thread.

Java applet Interview Questions
Question 18. A Person Says That He Compiled A Java Class Successfully Without Even Having A Main Method In It? Is It Possible?

Answer :

foremost technique is an entry point of Java class and is required for execution of the program but; a class gets compiled efficiently even supposing it doesn’t have a main approach. It can’t be run although.

J2EE Interview Questions
Question 19. Can We Call A Non-static Method From Inside A Static Method?

Answer :

Non-Static techniques are owned by items of a class and feature object level scope and so as to call the non-Static techniques from a static block (like from a static most important method), an item of the magnificence needs to be created first. Then the usage of item reference, these techniques may be invoked.

 

Java Tutorial
Question 20. What Are The Two Environment Variables That Must Be Set In Order To Run Any Java Programs?

Answer :

 Java packages can be achieved in a machine handiest as soon as following two surroundings variables have been nicely set:

PATH variable
CLASSPATH variable
Java Interview Questions
Question 21. Can Variables Be Used In Java Without Initialization?

Answer :

In Java, if a variable is utilized in a code without earlier initialization via a legitimate cost, application doesn’t assemble and offers an error as no default value is assigned to variables in Java.

Question 22. Can A Class In Java Be Inherited From More Than One Class?

Answer :

In Java, a class may be derived from most effective one elegance and not from multiple training. Multiple inheritances isn't always supported through Java.

Java eight Tutorial
Question 23. How Can We Use Primitive Data Types As Objects?

Answer :

Primitive facts types like int may be treated as objects by means of using their respective wrapper classes. For example, Integer is a wrapper magnificence for primitive facts kind int. We can follow distinctive methods to a wrapper elegance, similar to every other object.

Java eight Interview Questions
Question 24. Which Types Of Exceptions Are Caught At Compile Time?

Answer :

Checked exceptions may be caught at the time of program compilation. Checked exceptions need to be treated by way of the usage of try catch block within the code so that you can efficaciously assemble the code.

Core Java Interview Questions
Question 25. Describe Different States Of A Thread.

Answer :

A thread in Java can be in either of the following states:
Ready: When a thread is created, it’s in Ready state.
Running: A thread currently being done is in strolling kingdom.
Waiting: A thread waiting for some other thread to loose sure assets is in ready state.
Dead: A thread which has gone dead after execution is in useless country.

Question 26. What Is Ejb?

Answer :

EJB stands for Enterprise Java Beans. EJB is an critical part of a J2EE platform. J2EE platform have aspect based totally structure to offer multi-tiered, distributed and relatively transactional functions to company stage programs.
EJB provides an architecture to develop and installation issue based enterprise programs thinking about robustness, high scalability and high performance. An EJB application can be deployed on any of the application server compliant with J2EE 1.Three popular specification.

Java Programmer Interview Questions
Question 27. What Are The Benefits Of Ejb?

Answer :

Following are the important thing advantages of EJB.

Simplified improvement of large scale employer level software.
Application Server/ EJB field offers most of the gadget level services like transaction managing, logging, load balancing, endurance mechanism, exception dealing with and so on. Developer has to attention most effective on enterprise common sense of the utility.
EJB field manages existence cycle of ejb times therefore developer needs now not to worry approximately whilst to create/delete ejb gadgets.
 

JSP Interview Questions
Question 28. What Is A Session Bean In Ejb?

Answer :

Session bean shops records of a selected consumer for a single consultation. It may be stateful or stateless. It is much less useful resource intensive as compared to entity beans. Session bean receives destroyed as quickly as consumer session terminates.

Question 29. What Is Stateful Session Bean In Ejb?

Answer :

A stateful session bean is a form of enterprise bean which preserve the conversational country with patron. A stateful consultation bean as in step with its call maintains associated customer kingdom in its instance variables. EJB Container creates a separate stateful consultation bean to system consumer's each request. As quickly as request scope is over, statelful session bean is destroyed.

Question 30. What Is Stateless Session Bean In Ejb?

Answer :

A stateless session bean is a type of corporation bean that is normally used to do unbiased operations. A stateless consultation bean as in line with its call does no longer have any associated client state, however it may maintain its instance country. EJB Container generally creates a pool of few stateless bean's items and use those objects to system customer's request. Because of pool, instance variable values are not guaranteed to be same across lookups/approach calls.

Question 31. What Is Entity Bean In Ejb?

Answer :

Entity beans represents chronic records storage. User data can be saved to database through entity beans and later on can be retrived from the database inside the entity bean.

Question 32. What Is Message Driven Bean In Ejb?

Answer :

A message driven bean is a type of company bean that is invoked with the aid of EJB container whilst it receives a message from queue or topic. Message pushed bean is a stateless bean and is used to do mission asynchronously.

 

Question 33. When A Local Session Bean Is Used In Ejb?

Answer :

If ejb consumer is in equal surroundings in which ejb consultation bean is to be deployed then we use local consultation bean.

 

Java-Springs Interview Questions
Question 34. What A Remote Session Bean Is Used In Ejb?

Answer :

if ejb client is in distinctive surroundings wherein ejb consultation bean is to be deployed then we use far off session bean.

Question 35. What Are The Differences Between Stateful Session Bean And Stateless Session Bean?

Answer :

Following are the variations between stateful consultation bean and stateless consultation bean:
EJB Container creates a separate stateful consultation bean to procedure patron's every request.Whereas EJB Container usually creates a pool of few stateless bean's objects and use these gadgets to system purchaser's request.
As quickly as request scope is over, statelful consultation bean is destroyed however stateless bean stays lively.
A stateful session bean is a sort of business enterprise bean which keep the conversational kingdom with client. A stateful consultation bean as in keeping with its name continues associated customer kingdom in its instance variables Whereas because of pool of stateless session beans, example variable values are not assured to be equal across lookups/technique calls in stateless session beans.

Question 36. What Are The Key Components Of Persistence Api In Ejb?

Answer :

Following are the key components of endurance API in EJB:
Entity - A chronic object representing the information-keep document. It is good to be serializable.
EntityManager - Persistence interface to do records operations like upload/delete/update/discover on chronic object(entity). It additionally facilitates to execute queries the usage of Query interface.
Persistence unit (staying power.Xml) - Persistence unit describes the homes of patience mechanism.
Data Source (*ds.Xml) - Data Source describes the information-save related properties like connection url. Person-call,password and many others.

JMS(Java Message Service) Interview Questions
Question 37. Is Message Driven Bean A Stateless Bean?

Answer :

Message driven bean is a stateless bean and is used to do assignment asynchronously.

Question 38. Explain @javax.Ejb.Stateless Annotation.?

Answer :

@javax.Ejb.Stateless annotation specifies that a given ejb magnificence is a stateless session bean.Following are its attributes:
call - Used to specify name of the session bean.
MappedName - Used to specify the JNDI name of the consultation bean.
Description - Used to provide description of the session bean.

Question 39. Explain @javax.Ejb.Stateful Annotation.?

Answer :

@javax.Ejb.Stateful annotation specifies that a given ejb class is a stateful consultation bean.Following are its attributes:
call - Used to specify name of the session bean.
MappedName - Used to specify the JNDI name of the consultation bean.
Description - Used to offer description of the session bean.

Question 40. Explain @javax.Ejb.Messagedrivenbean Annotation.

Answer :

@javax.Ejb.MessageDrivenBean annotation specifies that a given ejb class is a message driven bean. Following are its attributes:
name - Used to specify call of the message driven bean.
MessageListenerInterface - Used to specify message listener interface for the message driven bean.
ActivationConfig - Used to specify the configuration info of the message-pushed bean in operational environment of the message driven bean.
MappedName - Used to specify the JNDI name of the message driven bean.
Description - Used to provide description of the message pushed bean.

Java applet Interview Questions
Question 41. Explain @javax.Ejb.Ejb Annotation.

Answer :

@javax.Ejb.EJB annotation is used to specify or inject a dependency as ejb instance into any other ejb. Following are its attributes:
call - Used to specify call in an effort to be used to discover the referenced bean in surroundings.
BeanInterface - Used to specify the interface type of the referenced bean.
BeanName - Used to offer name of the referenced bean.
MappedName - Used to specify the JNDI call of the referenced bean.
Description - Used to offer description of the referenced bean.

Question forty two. Explain @javax.Ejb.Nearby Annotation.

Answer :

@javax.Ejb.Local annotation is used to specify Local interface(s) of a consultation bean. This nearby interface states the enterprise methods of the session bean (which may be stateless or stateful).
This interface is used to reveal the business methods to nearby clients that are running in same deployment/application as EJB.
Following are its attributes:
fee - Used to specify the listing of neighborhood interfaces as an array of interfaces.

Java Interview Questions
Question forty three. What Is Container Managed Transactions?

Answer :

In this kind, box manages the transaction states.

Question forty four. What Is A Transaction?

Answer :

A transaction is a unmarried unit of work items which follows the ACID residences. ACID stands for Atomic, Consistent,Isolated and Durable.

Question forty five. Which Types Of Java Classes Can Be Mapped Using @lob Annotation?

Answer :

Following java types may be mapped the usage of @Lob annotation:

java.Square.Blob
java.Sq..Clob
byte[]
String
Serializable Object
Question forty six. Explain @lob Annotation.

Answer :

EJB three.Zero provides assist for Blob and Clob types the use of @Lob annotation.

Question forty seven. Explain @embeddable Annotation.

Answer :

EJB three.0 presents choice to embed JAVA POJO (Plain Old Java Object) into an entity bean and permits to map column names with the methods of the embedded POJO elegance. A java POJO to be embedded need to be annotated as @Embeddable.

Question 48. What Is Method Level Interceptor In Ejb?

Answer :

Method level interceptor is invoked for a particular technique of the bean. Method level interceptor may be implemented both by using annotation of via xml(ejb-jar.Xml).

Question forty nine. What Is Default Interceptor In Ejb?

Answer :

Default interceptor is invoked for each bean within deployment.Default interceptor can be implemented best thru xml (ejb-jar.Xml).

Question 50. What Is Class Level Interceptor In Ejb?

Answer :

Class level interceptor is invoked for every technique of the bean. Class degree interceptor can be implemented both via annotation or via xml(ejb-jar.Xml).

Question fifty one. What Is Spring?

Answer :

Spring is an open supply development framework for Enterprise Java. The middle capabilities of the Spring Framework may be used in growing any Java software, however there are extensions for constructing internet applications on top of the Java EE platform. Spring framework targets to make Java EE improvement easier to use and sell good programming exercise through permitting a POJO-based programming model.

Question fifty two. What Are Benefits Of Spring Framework?

Answer :

Lightweight: Spring is light-weight in terms of size and transparency. The simple version of spring framework is around 2MB.
Inversion of manage (IOC): Loose coupling is achieved in Spring, with the Inversion of Control approach. The gadgets deliver their dependencies rather than developing or seeking out dependent objects.
Aspect oriented (AOP): Spring helps Aspect oriented programming and separates application business common sense from system services.
Container: Spring carries and manages the existence cycle and configuration of utility items.
MVC Framework: Spring’s web framework is a nicely-designed net MVC framework, which presents a remarkable opportunity to internet frameworks.
Transaction Management: Spring provides a steady transaction management interface that can diminish to a local transaction and scale up to worldwide transactions (JTA).
Exception Handling: Spring gives a convenient API to translate era-specific exceptions (thrown by way of JDBC, Hibernate, or JDO) into steady, unchecked exceptions.

Question 53. Which Are The Spring Framework Modules?

Answer :

The primary modules of the Spring framework are :

Core module
Bean module
Context module
Expression Language module
JDBC module
ORM module
OXM module
Java Messaging Service(JMS) module
Transaction module
Web module
Web-Servlet module
Web-Struts module
Web-Portlet module
Question fifty four. Explain The Core Container (software Context) Module?

Answer :

This is the primary Spring module, which presents the fundamental functionality of the Spring framework. BeanFactory is the coronary heart of any spring-based totally application. Spring framework turned into built on the pinnacle of this module, which makes the Spring field.

Question fifty five. What Is Beanfactory?

Answer :

A BeanFactory is an implementation of the factory pattern that applies Inversion of Control to split the software’s configuration and dependencies from the real software code.
The most generally used BeanFactory implementation is the XmlBeanFactory elegance.

Question 56. Explain Xmlbeanfactory?

Answer :

The most beneficial one is org.Springframework.Beans.Factory.Xml.XmlBeanFactory, which loads its beans primarily based on the definitions contained in an XML document. This field reads the configuration metadata from an XML document and uses it to create a completely configured machine or application.

Question 57. Explain The Aop Module

Answer :

The AOP module is used for growing factors for our Spring-enabled application. Much of the help has been furnished through the AOP Alliance for you to ensure the interoperability among Spring and other AOP frameworks. This module additionally introduces metadata programming to Spring.

Question fifty eight. Explain The Jdbc Abstraction And Dao Module

Answer :

With the JDBC abstraction and DAO module we can be positive that we hold up the database code easy and easy, and save you problems that end result from a failure to shut database resources. It gives a layer of significant exceptions on pinnacle of the error messages given with the aid of numerous database servers. It additionally makes use of Spring’s AOP module to provide transaction management services for gadgets in a Spring application.

Question 59. Explain The Object/relational Mapping Integration Module

Answer :

Spring also helps for using of an object/relational mapping (ORM) tool over directly JDBC via presenting the ORM module. Spring offers guide to tie into numerous popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL Maps. Spring’s transaction control supports every of these ORM frameworks as well as JDBC.

Question 60. Explain The Web Module

Answer :

The Spring web module is built at the application context module, presenting a context that is suitable for internet-based totally applications. This module additionally incorporates guide for several web-oriented tasks such as transparently handling multipart requests for file uploads and programmatic binding of request parameters to your business items. It additionally incorporates integration assist with Jakarta Struts.

Question sixty one. Explain The Spring Mvc Module

Answer :

MVC framework is provided with the aid of Spring for building internet programs. Spring can without problems be integrated with other MVC frameworks, but Spring’s MVC framework is a higher choice, because it makes use of IoC to offer for a clean separation of controller good judgment from enterprise gadgets. With Spring MVC you can declaratively bind request parameters in your commercial enterprise gadgets.

Question sixty two. What Is Spring Configuration File?

Answer :

Spring configuration document is an XML file. This record incorporates the classes information and describes how these instructions are configured and brought to every different.

Question sixty three. What Is Spring Ioc Container?

Answer :

The Spring IoC is answerable for growing the objects,dealing with them (with dependency injection (DI)), wiring them together, configuring them, as also dealing with their entire lifecycle.

Question sixty four. What Are The Benefits Of Ioc?

Answer :

IOC or dependency injection minimizes the quantity of code in an application. It makes smooth to test applications, for the reason that no singletons or JNDI lookup mechanisms are required in unit tests. Loose coupling is promoted with minimum effort and least intrusive mechanism. IOC packing containers guide eager instantiation and lazy loading of services.

Question 65. What Are The Common Implementations Of The Applicationcontext?

Answer :

The FileSystemXmlApplicationContext box hundreds the definitions of the beans from an XML document. The full course of the XML bean configuration report need to be provided to the constructor.
The ClassPathXmlApplicationContext box also hundreds the definitions of the beans from an XML file. Here, you want to set CLASSPATH well because this container will look bean configuration XML document in CLASSPATH.
The WebXmlApplicationContext: container loads the XML record with definitions of all beans from within an internet application.
Question sixty six. What Is The Difference Between Bean Factory And Applicationcontext?

Answer :

Application contexts offer a means for resolving text messages, a frequent way to load report assets (which include pix), they can publish occasions to beans which can be registered as listeners. In addition, operations at the field or beans within the container, which have to be dealt with in a programmatic style with a bean factory, may be treated declaratively in an software context. The application context implements MessageSource, an interface used to gain localized messages, with the actual implementation being pluggable.

Question sixty seven. What Does A Spring Application Look Like?

Answer :

An interface that defines the features.
The implementation that contains properties, its setter and getter strategies, functions and so on.,Spring AOP 
The Spring configuration XML report.
Client application that uses the function

Question 68. How Jdbctemplate Can Be Used?

Answer :

With use of Spring JDBC framework the weight of useful resource management and mistakes managing is reduced a lot. So it leaves builders to jot down the statements and queries to get the data to and from the database. JdbcTemplate affords many convenience methods for doing matters inclusive of changing database data into primitives or items, executing organized and callable statements, and imparting custom database blunders dealing with.

Question sixty nine. How Jdbc Can Be Used More Efficiently In Spring Framework?

Answer :

JDBC can be used greater correctly with the help of a template magnificence supplied via spring framework called as JdbcTemplate.

Question 70. What Are The Types Of The Transaction Management Spring Supports?

Answer :

Spring helps two kinds of transaction control:
Programmatic transaction management: This means that you have controlled the transaction with the assist of programming. That gives you excessive flexibility, however it is tough to hold.
Declarative transaction control: This way you separate transaction management from the business code. You simplest use annotations or XML primarily based configuration

Question seventy one. What Are The Types Of Advice?

Answer :

Spring elements can paintings with 5 styles of recommendation referred to below:
earlier than: Run recommendation before the a technique execution.
After: Run advice after the a way execution irrespective of its final results.
After-returning: Run advice after the a method execution best if technique completes successfully.
After-throwing: Run advice after the a technique execution only if method exits with the aid of throwing an exception.
Around: Run recommendation earlier than and after the suggested approach is invoked.

 

Question 72. What Are The Different Points Where Weaving Can Be Applied?

Answer :

Weaving can be done at compile time, load time, or at runtime.

Question 73. What Is Target Object?

Answer :

The object being counseled with the aid of one or greater components, this item will usually be a proxy item. Also called the cautioned object.

 

Question seventy four. Describe Some Of The Standard Spring Events.

Answer :

Spring offers the subsequent preferred occasions:

ContextRefreshedEvent: This event is published when the ApplicationContext is either initialized or refreshed. This can also be raised the usage of the refresh method on the ConfigurableApplicationContext interface.
ContextStartedEvent: This occasion is posted whilst the ApplicationContext is began the use of the begin approach at the ConfigurableApplicationContext interface. You can poll your database or you could re/begin any stopped utility after receiving this occasion.
ContextStoppedEvent: This occasion is posted while the ApplicationContext is stopped using the stop approach at the ConfigurableApplicationContext interface. You can do required housekeep work after receiving this event.
ContextClosedEvent: This occasion is published while the ApplicationContext is closed the usage of the close method at the ConfigurableApplicationContext interface. A closed context reaches its end of lifestyles; it can not be refreshed or restarted.
RequestHandledEvent: This is an internet-unique event telling all beans that an HTTP request has been serviced.

 

Question 75. What Is The Difference Between Concern And Cross-reducing Concern In Spring Aop?

Answer :

Concern: Concern is behavior which we want to have in a module of an software. Concern may be described as a capability we want to implement. Issues in which we're interested define our concerns.
Cross-reducing concern: It's a challenge that's applicable at some stage in the application and it impacts the whole utility. E.G. Logging , safety and information switch are the concerns which might be needed in almost every module of an software, for this reason are cross-slicing issues.




CFG