250+ TOP MCQs on Introducing Behaviors and States to Your Beans and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Introducing Behaviors and States to Your Beans”.

1. Which special type of advice is used to implement an interface?
a) Introduction
b) Before
c) After
d) AfterSpecial
Answer: a
Clarification: It allows your objects to implement an interface dynamically by providing an implementation class for that interface.

2. Introduction advice helps in implementing multiple inheritance
a) True
b) False
Answer: a
Clarification: You are able to introduce multiple interfaces with multiple implementation classes to your objects at the same time.

3. In introduction advice you have to modify class to introduce new methods
a) True
b) False
Answer: b
Clarification: You can introduce methods to your existing classes even without source code available.

4. How does an Introduction advice do this in Spring?
a) dynamic proxy
b) web proxy
c) implements org.springframework.net.bundle interface
d) none of the mentioned
Answer: a
Clarification: Introduction works by adding an interface to the dynamic proxy.

5. Annotation used to declare an introduction
a) Before
b) After
c) @DeclareParents
d) None of the mentioned
Answer: c
Clarification: In this aspect, you can declare an introduction by annotating an arbitrary field with the @DeclareParents annotation.

6. Target Classes can be denoted by Introduction Annotation
a) True
b) False
Answer: a
Clarification: The value attribute of the @DeclareParents annotation type indicates which classes are the targets for this introduction.

7. Attribute used to specify implementation class
a) no such attribute
b) defaultImpl
c) defaultInterface
d) defaultImplement
Answer: b
Clarification: The interface to introduce is determined by the type of the annotated field. Finally, the implementation class used for this new interface is specified in the defaultImpl attribute.

8. How to keep track of the usage of your beans
a) Calling Count
b) Last modified date
c) New Interface to your object
d) All of the mentioned
Answer: d
Clarification: You can introduce a new interface to your objects with an implementation class that holds the state field.

9. How to introduce counter field to original bean class?
a) Using Spring AOP
b) Implementing interface
c) AspectJ Pointcut
d) None of the mentioned
Answer: a
Clarification: Since there is no field for storing the counter value in the original classes, you need to introduce one with Spring AOP.

10. Tag used to declare aspects
a) aop:config
b) aop:auto-proxy
c) aop:autowire
d) None of the mentioned
Answer: a
Clarification: In the bean configuration file, all the Spring AOP configurations must be defined inside the aop:config element.

250+ TOP MCQs on JSON with REST and Answers

Java Spring Questions and Answers for experienced on “JSON with REST”.

1. Payload format for REST services.
a) RSS
b) Atom
c) JSON
d) All of the mentioned
Answer: d
Clarification: JSON, in addition to RSS and Atom, has blossomed into a favorite payload format for REST services.

2. All REST service payloads rely on XML markup.
a) True
b) False
Answer: b
Clarification: JSON is different in the sense that its content is a special notation based on the JavaScript language.

3. Class that forms part of Spring to apply JSON content.
a) MappingJacksonJsonView
b) MappingJsonView
c) MappingJacksonJson
d) JsonView
Answer: a
Clarification: In addition to relying on Spring REST support, we will also use the MappingJacksonJsonView class that forms part of Spring to facilitate the publication of JSON content.

4. The MappingJacksonJsonView class depends on Jackson JSON processor library.
a) org.codehaus.jackson
b) jackson-mapper-asl
c) all of the mentioned
d) none of the mentioned
Answer: a
Clarification: The MappingJacksonJsonView class depends on the presence of the Jackson JSON processor library which can be downloaded at http://wiki.fasterxml.com/JacksonDownload.

5. Information you wish to publishas a JSON Object can be located in a RDBMS or text file, accessed through JDBC or ORM.
a) True
b) False
Answer: a
Clarification: This information can be located in a RDBMS or text file, accessed through JDBC or ORM, inclusively be part of a Spring bean or some other type of construct.

6. JSON payload consists of text and separators like.
a) { , }
b) ( , )
c) :
d) All of the mentioned
Answer: d
Clarification: a JSON payload consists of text and separators like { , }, ( , ), : and “.

7. To access JSON in a Spring application, library used is:-
a) JSON-LIB
b) SpringJSON-lib
c) JSON-lib
d) None of the mentioned
Answer: a
Clarification: Though it’s technically possible to access JSON in a Spring application (i.e., on the server side), using a third-party Java library like JSON-LIB (http://json-lib.sourceforge.net/ ).

8. You are often better served accessing and manipulating REST services with XML payloads in Spring applications.
a) True
b) False
Answer: a
Clarification: The Java platform’s native support for XML, in addition to the fact that XML is more intuitive and does not have the same processing limitations as browsers.

9. Class which is capable of performing a multitude of operations on REST services.
a) RestTemplate
b) XPathTemplate
c) XMLTemplate
d) JavaTemplate
Answer: a
Clarification: Spring RestTemplate class is capable of performing a multitude of operations on REST services in order for their payloads to be used inside Spring applications, processing elaborate XML responses requires using a set of approaches beyond those of this last class.

10. XML query language for selecting nodes from an XML document.
a) XPathTemplate
b) XPath
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: XPath—an XML query language for selecting nodes from an XML document— knowledge about Spring HttpConverterMessage, as well as supporting facilities like Spring XPathTemplate.

11. The Handler method assigns the returning XML payload to a String.
a) True
b) False
Answer: a
Clarification: The handler method makes use of the getForObject method of the RestTemplate class and assigns the returning XML payload to a String, which is then added to the handler method Model object.

12. To extract and manipulate payloads in Spring REST in a format other than String.
a) HttpConverter
b) HttpMessage
c) HttpConverterMessage
d) None of the mentioned
Answer: c
Clarification: All objects that are returned and inclusively passed to the methods belonging to the RestTemplate class are converted to and from HTTP messages using a class which implements the HttpConverterMessage interface.

13. To write your own converters relying on the MarshallingHttpMessageConverter interface that would allow the use of custom marshallers.
a) messageConverters
b) messageConvert
c) converters
d) convertersMessage
Answer: a
Clarification: Using custom converters requires registering them with the messageConverters bean property in a Spring application.

14. To override the default implementations registered with the RestTemplate class.
a) messageConverters
b) messageConvert
c) converters
d) convertersMessage
Answer: a
Clarification: It’s also possible to override the default implementations registered with the RestTemplate class using the same messageConverters bean property.

15. To extract and manipulate the contents of a REST service payload.
a) messageConverters
b) StreamSource class
c) converters
d) convertersMessage
Answer: b
Clarification: It becomes easier to extract and manipulate the contents of a REST service payload since it can be done through the more flexible StreamSource class.


Java Spring for Experienced,

250+ TOP MCQs on ORM Frameworks and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “ORM Frameworks”.

1. Class which represents a real-world entity and its instances will be persisted to a database.
a) entity
b) persistent
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: Class is called an entity class or a persistent class because it represents a real-world entity and its instances will be persisted to a database.

2. Each entity class to be persisted by an ORM framework, a default constructor with no argument is required.
a) True
b) False
Answer: a
Clarification: For each entity class, you must define an identifier property to uniquely identify an entity.

3. If the identifier value is null, this entity will be treated as a new and unsaved entity.
a) True
b) False
Answer: a
Clarification: When this entity is persisted, an insert SQL statement will be issued; otherwise, an update statement will.

4. To allow the identifier to be null, you should choose a primitive wrapper type:-
a) java.lang.Integer
b) java.lang.Long
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: To allow the identifier to be null, you should choose a primitive wrapper type like java.lang.Integer and java.lang.Long for the identifier.

5. A set of persistent annotations for you to define mapping metadata.
a) JPA
b) JSR
c) XML
d) None of the mentioned
Answer: a
Clarification: JPA defines a set of persistent annotations for you to define mapping metadata in a standard format that is more likely to be reusable in other ORM frameworks.

6. For mapping and persisting your objects with Hibernate and JPA.
a) Using the Hibernate API to persist objects with Hibernate XML mappings
b) Using the Hibernate API to persist objects with JPA annotations
c) Using JPA to persist objects with JPA annotations
d) All of the mentioned
Answer: d
Clarification: Hibernate also supports the use of JPA annotations to define mapping metadata, so there are
essentially three different strategies for mapping and persisting your objects with Hibernate and JPA:
• Using the Hibernate API to persist objects with Hibernate XML mappings
• Using the Hibernate API to persist objects with JPA annotations
• Using JPA to persist objects with JPA annotations

7. Core Programming Elements for Different Data Access Strategies.
a) Resource
b) Resource Factory
c) Session
d) All of the mentioned
Answer: d
Clarification: Core Programming Elements for Different Data Access Strategies
Concept JDBC Hibernate JPA
Resource Connection Session EntityManager
Resource factory DataSource SessionFactory EntityManagerFactory
Exception SQLException HibernateException PersistenceException

8. Interface whose instances can be obtained from a SessionFactory instance.
a) Session
b) Session Factory
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: In Hibernate, the core interface for object persistence is Session, whose instances can be obtained from a SessionFactory instance.

9. Interface whose instances can be obtained from an EntityManagerFactory instance.
a) Entity
b) EntityManager
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: In JPA, the corresponding interface is EntityManager, whose instances can be obtained from an EntityManagerFactory instance.

10. The exceptions thrown by Hibernate are of type HibernateException, while those thrown by JPA may be of type PersistenceException.
a) True
b) False
Answer: a
Clarification: Other Java SE exceptions like IllegalArgumentException and IllegalStateException.

11. To accept a session factory via dependency injection.
a) HibernateCourseDao
b) HibernateCourse
c) HibernateDao
d) All of the mentioned
Answer: a
Clarification: Modify HibernateCourseDao to accept a session factory via dependency injection, instead of creating it directly with the native Hibernate API in the constructor.

12. Property for factory bean to load the Hibernate configuration file.
a) config.xml
b) config
c) configLocation
d) none of the mentioned
Answer: c
Clarification: The configLocation property is of type Resource, but you can assign a string value to it.

13. If you want to use this data source for your session factory, you can inject it into the dataSource property of LocalSessionFactoryBean.
a) True
b) False
Answer: a
Clarification: The data source specified in this property will override the database settings in the Hibernate configuration file.

14. FactoryBean to create an entity manager factory in the IoC container.
a) LocalEntityManagerFactoryBean
b) LocalEntityManagerFactory
c) LocalEntityManager
d) All of the mentioned
Answer: a
Clarification: Spring provides a factory bean, LocalEntityManagerFactoryBean, for you to create an entity manager factory in the IoC container.

15. It allows you to override some of the configurations in the JPA configuration file.
a) LocalEntityManagerFactoryBean
b) LocalContainerEntityManagerFactoryBean
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: Spring supports a more flexible way to create an entity manager factory by another factory bean, LocalContainerEntityManagerFactoryBean. It allows you to override some of the configurations in the JPA configuration file, such as the data source and database dialect.

250+ TOP MCQs on Spring Batch and Gateways and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Spring Batch and Gateways”.

1. To take an input file or a payload and reliably, and systematically, decompose it into events that an ESB can work with:-
a) Splitter
b) Spring Batch
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: You have a file with a million records in it. This file’s too big to handle as one event; it’s far more natural to react to each row as an event. Spring Batch works very well with these types of solutions. It allows you to take an input file or a payload and reliably, and systematically, decompose it into events that an ESB can work with.

2. Spring Integration does support reading files into the bus.
a) True
b) False
Answer: a
Clarification: Spring Batch does support providing custom, unique endpoints for data.

3. No processing system (such as an ESB) can deal with a million records at once efficiently.
a) True
b) False
Answer: a
Clarification: Strive to decompose bigger events and messages into smaller ones.

4. Spring Batch reads the file, transforms the records into:-
a) objects
b) outputs
c) all of the mentioned
d) none of the mentioned
Answer: a
Clarification: Spring Batch reads the file, transforms the records into objects, and writes the output to a JMS topic with a key correlating the original batch to the JMS message.

5. The BPM engine would thread together the different actors and work lists,
a) True
b) False
Answer: a
Clarification: The BPM engine would thread together the different actors and work lists, allow work to continue over the course of days instead of the small millisecond timeframes Spring Integration is more geared to.

6. You want to expose an interface to clients of your service, without betraying the fact that your service is implemented in terms of messaging middleware.
a) Enterprise Integration Patterns
b) Gateway
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: Use a gateway—a pattern from the classic book Enterprise Integration Patterns by Gregor Hohpe and Bobby Woolf (Addison-Wesley, 2004) that enjoys rich support in Spring Integration.

7. Serving to abstract away the functionality of other components in an abbreviated interface to provide courser functionality.
a) facade
b) façade
c) gateway
d) none of the mentioned
Answer: b
Clarification: You might use a façade to build an interface oriented around vacation planning that in turn abstracts away the minutiae of using a car rental, hotel reservation, and airline reservation system.

8. The capability to hide messaging behind a POJO interface.
a) Lingo
b) JCA
c) JMS
d) All of the mentioned
Answer: d
Clarification: Lingo, a project from Codehaus.org that is no longer under active development, had such a feature that was specific to JMS and the Java EE Connector Architecture (JCA –it was originally used to talk about the Java Cryptography Architecture, but is more commonly used for The Java EE Connector Architecture now).

9. The most fundamental support for gateways comes from the Spring Integration class:-
a) SimpleMessagingGateway
b) SimpleMessaging
c) SimpleGateway
d) None of the mentioned
Answer: a
Clarification: The class provides the ability to specify a channel on which requests should be sent and a channel on which responses are expected.

10. The SimpleMessagingGateway needs a request and a response channel, and it coordinates the rest.
a) True
b) False
Answer: a
Clarification: You’re doing nothing but forwarding the request to a service-activator, which in turn adds the operands and sends them out on the reply channel.

11. The first thing that the client configuration does is import a shared application context (to save typing if nothing else) that declares a JMS connection factor.
a) True
b) False
Answer: a
Clarification: The first thing that the client configuration does is import a shared application context (to save typing if nothing else) that declares a JMS connection factory that you reference in the client and service application contexts.

12. Messages sent on the requests channel are forwarded to the:-
a) jms:outbound-gateway
b) jms:outbound
c) jms-gateway
d) all of the mentioned
Answer: a
Clarification: The jms:outbound-gateway is the component that does most of the work. It takes the message you created and sends it to the request JMS destination, setting up the reply headers and so on.

13. The gateway element simply exists to identify the component and the interface.
a) True
b) False
Answer: a
Clarification: The gateway element simply exists to identify the component and the interface, to which the proxy is cast and made available to clients.

14. There is no coupling between the client facing interface exposed via the gateway component and the interface of the service that ultimately handles the messages.
a) True
b) False
Answer: a
Clarification: We use the interface for the service and the client to simplify the names needed to understand everything that’s going on.

15. The service-activator is what handles actual processing and there’s no mention of a response channel, for either the service-activator, or for the inbound JMS gateway.
a) True
b) False
Answer: a
Clarification: The service-activator looks, and fails to find, a reply channel and so uses the reply channel created by the inbound JMS gateway component, which in turn has created the reply channel based on the header metadata in the inbound JMS message.

250+ TOP MCQs on AspectJ Aspects and Answers

Java Spring Interview Questions and Answers on “AspectJ Aspects”.
1. Tag used to enable AspectJ annotation?
a) Introduction
b) aop:aspectj-autowire
c) aop:aspectj-autoproxy
d) AfterSpecial
Answer: c
Clarification: To enable AspectJ annotation support in Spring, you have already defined an empty XML element, aop:aspectj-autoproxy.

2. Tag which defined Spring AOP configurations
a) aop:config
b) aop:configregister
c) aop:configbeans
d) None of the mentioned
Answer: a
Clarification: In the bean configuration file, all the Spring AOP configurations must be defined inside the aop:config element.

3. What are the ways to declare an advice?
a) pointcut-ref attribute
b) pointcut attribute
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: An advice element requires either a pointcut-ref attribute to refer to a pointcut or a pointcut attribute to embed a pointcut expression directly.

4. Applying aspects to your target objects
a) AspectJ Annotation
b) Weaving
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: Weaving is the process of applying aspects to your target objects.

5. Special compiler used during weaving
a) jvm
b) gcc
c) ajc
d) none of the mentioned
Answer: c
Clarification: AspectJ compile-time weaving is done through a special AspectJ compiler called ajc.

6. Name of the process when targe classes are loaded into JVM
a) load-time weaving
b) process-time weaving
c) load-process weaving
d) process-delivery weaving
Answer: a
Clarification: AspectJ load-time weaving (also known as LTW) happens when the target classes are loaded into JVM by a class loader.

7. How to weave your classes using argument while compiling?
a) -javaagent:CLASSPATH
b) -javaagent:PackgePath
c) -javaweave:CLASSPATH
d) -javaweave:PackagePath
Answer: a
Clarification: You need only to add a VM argument to the command that runs your application. Then your classes will get woven when they are loaded into the JVM.

8. XML Element to include load-time weaver
a) aop:config
b) aop:auto-wire
c) context:load-time-weaver
d) aop:load-time-weaver
Answer: c
Clarification: To turn on a suitable load-time weaver for your Spring application, you need only to declare the empty XML element context:load-time-weaver.

9. You also have to include suitable load-time weaver’s configuration in XML
a) True
b) False
Answer: b
Clarification: Spring will be able to detect the most suitable load-time weaver for your runtime environment.

10. Library to use AspectJ weaver
a) spring-instrument.jar
b) spring-introduction.jar
c) spring-aop.jar
d) spring-weave.jar
Answer: a
Clarification: To use the AspectJ weaver, you need to include the spring-instrument.jar

11. Objects created outside the container:-
a) Domain Objects
b) User Objects
c) SpringVisitor Objects
d) None of the mentioned
Answer: a
Clarification: Objects created outside the Spring IoC container are usually domain objects. They are often created using the new operator or from the results of database queries.

12. How to inject Spring bean into domain objects
a) AOP
b) XML
c) AspectJ
d) Java Based
Answer: a
Clarification: To inject a Spring bean into domain objects created outside Spring, you need the help of AOP.

13. We can directly use Spring AOP for injection of beans
a) True
b) False
Answer: b
Clarification: As the domain objects are not created by Spring, you cannot use Spring AOP for injection.

14. Which scope does @Configurable instantiated class looks for?
a) Singleton
b) Prototype
c) None of the mentioned
d) All of the mentioned
Answer: b
Clarification: When a class with the @Configurable annotation is instantiated, the aspect will look for a prototype-scoped bean definition whose type is the same as this class.

15. Spring includes AnnotationBeanConfigurerAspect in its aspect library for configuring the dependencies of any objects
a) True
b) False
Answer: a
Clarification: Spring includes AnnotationBeanConfigurerAspect in its aspect library for configuring the dependencies of any objects, even if they were not created by the Spring IoC container. First of all, you have to annotate your object type with the @Configurable annotation to declare that this type of object is configurable.


Java Spring for Interviews,

250+ TOP MCQs on Flex and Sandbox in Spring and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Flex and Sandbox in Spring”.

1. IntelliJ IDEA product, versions 8 and 9, supports:-
a) Flex
b) AIR
c) None of the mentioned
d) All of the mentioned
Answer: d
Clarification: Particularly, IntelliJ IDEA product, versions 8 and 9, support Flex and AIR development with aplomb.

2. Flex is that it is, technically, a library implemented on top of the middleware.
a) True
b) False
Answer: b
Clarification: Flex is, technically, a library implemented on top of the Flash virtual machine.

3. In Flash, the displayed area where animation and rendering occurs.
a) Stage
b) Animation
c) Stagery
d) State
Answer: a
Clarification: In Flash, the displayed area where animation and rendering occurs is called the stage.

4. Flex uses a language called ActionScript 3.0.
a) True
b) False
Answer: b
Clarification: Flash uses a language called ActionScript 3.0.

5. ActionScript code pages end in .as, and ActionScript binaries are .sf files.
a) True
b) False
Answer: b
Clarification: ActionScript code pages end in .as, and ActionScript binaries are .swf files.

6. Linkable libraries have the extension.
a) .swc
b) .dll
c) .so
d) none of the mentioned
Answer: a
Clarification: You can use ActionScript tools to build linkable libraries, much like a .dll on Windows, or a .so on Linux. These linkable libraries have the extension .swc.

7. The source artifacts of a Flex application are:-
a) ActionScript files (ending in .as)
b) ActionScript files (ending in .mxml)
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: The two source artifacts of a Flex application are the ActionScript files (ending in .as) and the .mxml files.

8. XML variant that describe the UI components and provide a DOM.
a) AS files
b) MXML files
c) XML Files
d) All of the mentioned
Answer: b
Clarification: MXML files are an XML variant that describe the UI components and provide a DOM.

9. MXML files support a limited form of expression language binding
a) True
b) False
Answer: a
Clarification: Limited when compared to the EL support in frameworks like Tapestry or JSF, anyway.

10. Outermost tag in Flex.
a) mx:Application
b) mx:WindowedApplication
c) all of the mentioned
d) none of the mentioned
Answer: a
Clarification: In the case of Flex applications, the outermost tag is the mx:Application tag.

11. Outermost tag in AIR.
a) mx:Application
b) mx:WindowedApplication
c) all of the mentioned
d) none of the mentioned
Answer: b
Clarification: In the case of AIR applications, the outermost tag is the mx:WindowedApplication tag.

12. As soon as the application has been loaded and all the objects configured, an event will be fired.
a) applicationEvent
b) applicationComplete
c) eventConfigure
d) eventComplete
Answer: b
Clarification: Just as you can in the browser, you have two choices for listening to events in Flex: programmatic registration and through MXML attributes on the component that fires the event.

13. JavaScript library dynamically adds the plug-in content to the page.
a) True
b) False
Answer: a
Clarification: Because of this property, it triggered the “Dynamic Content” warning in Internet Explorer 6 for a few years.

14. JavaScript library dynamically generates.
a) object
b) plugin
c) FlashVars
d) all of the mentioned
Answer: d
Clarification: The library dynamically generates the relevant object and plugin tags, along with the FlashVars parameters.

15.To talk to the containing HTML page.
a) flash.external.ExternalInterface
b) flash.external.External
c) flash.external.ExternalInterface
d) none of the mentioned
Answer: a
Clarification: To talk to the containing HTML page, you can use the flash.external.ExternalInterface class. This class defines two static methods, call() (which lets the Flex application talk to the host) and addCallback() (which lets the host talk to Flex).