Java MCQ Set 1
1. Spring Batch provides a lot of flexibility and guarantees to your application, but it cannot work in a vacuum. To do its work:-
a) Job
b) JobRepo
c) JobRepository
d) All of the mentioned
Answer
Answer: c [Reason:] To do its work, the JobRepository requires a database. Additionally, there are several collaborators required for Spring Batch to do its work. This configuration is mostly boilerplate.
2. There’s only one really useful implementation of the JobRepository interface, which stores information about the state of the batch processes in a database.
a) SimpleJobRepository
b) SimpleJob
c) SimpleRepo
d) All of the mentioned
Answer
Answer: a [Reason:] Creation is done through a JobRepositoryFactoryBean. Another standard factory, MapJobRepositoryFactoryBean is useful mainly for testing because its state is not durable – it’s an in-memory implementation. Both factories create an instance of SimpleJobRepository.
3. To load the contents of a properties file (batch.properties) whose values you use to configure the data source.
a) PropertyPlaceholder
b) PropertyPlaceholderConfigurer
c) Property
d) PropertyConfigurer
Answer
Answer: b [Reason:] You need to place values for your particular database in this file. This example uses Spring’s property schema (“p”) to abbreviate the tedious configuration.
4. MapJobRegistry instance. This is critical—it is the central store for information regarding a given Job.
a) True
b) False
Answer
Answer: a [Reason:] It controls the “big picture” about all Jobs in the system. Everything else works with this instance.
5. SimpleJobLauncher, whose sole purpose is to give you a mechanism to launch batch jobs, where a “job” in this case is our batch solution.
a) True
b) False
Answer
Answer: a [Reason:] The jobLauncher is used to specify the name of the batch solution to run as well as any parameters required.
6. Spring Batch models solutions using XML schema.
a) True
b) False
Answer
Answer: a [Reason:] This schema is new to Spring Batch 2.1.
7. However, it’s important to wear another hat, that of a DBA, when writing applications.
a) True
b) False
Answer
Answer: a [Reason:] A common solution is to create a denormalized table whose contents can be coerced into valid data once inside the database, perhaps by a trigger on inserts.
8. Indeed, a step could be considered the smallest unit of work for a job. Input (what’s read) is passed to the Step and potentially processed; then output (what’s written) is created from the step.
a) Steplet
b) Tasklet
c) All of the mentioned
d) None of the mentioned
Answer
Answer: b [Reason:] This processing is spelled out using a Tasklet. You can provide your own Tasklet implementation or simply use some of the preconfigured configurations for different processing scenarios.
9. Attribute to configure how many items will be processed before the transaction is committed all the input is sent to the writer.
a) interval
b) commit
c) commit-interval
d) none of the mentioned
Answer
Answer: c [Reason:] If there is a transaction manager in play, the transaction is also committed.
10. Class which delegates the task of delimiting fields and records within a file to a LineMapper
a) org.springframework.batch.item.file.FlatFileItemReader
b) org.springframework.batch.item.file.FlatFile
c) org.springframework.batch.item.file.FlatFileItem
d) org.springframework.batch.item.file.FileItemReader
Answer
Answer: a [Reason:] The FlatFileItemReader also declares a fieldSetMapper attribute that requires an implementation of FieldSetMapper.
11. The names and values for the named parameters are being created by the bean configured for the itemSqlParameterSourceProvider property, an instance of the interface
a) BeanPropertyItemSqlParameterSourceProvider
b) BeanPropertyItemSqlParameterSource
c) BeanPropertyItemSqlParameter
d) All of the mentioned
Answer
Answer: a [Reason:] BeanPropertyItemSqlParameterSourceProvider, whose sole job it is to take JavaBean properties and make them available as named parameters corresponding to the property name on the JavaBean.
12. There’s support for writing JMS:-
a) JmsItemWriter
b) JpaItemWriter
c) JdbcBatchItemWriter
d) All of the mentioned
Answer
Answer: d [Reason:] There’s support for writing JMS (JmsItemWriter
13. The processor attribute on the chunk element expects a reference to a bean of the interface:-
a) org.springframework.batch.item.Item
b) org.springframework.batch.item
c) org.springframework.batch.item.ItemProcessor
d) none of the mentioned
Answer
Answer: c [Reason:] The processor attribute on the chunk element expects a reference to a bean of the interface org.springframework.batch.item.ItemProcessor.
14. Spring Batch provides a convenience class, CompositeItemProcessor, which forwards the output of the filter to the input of the successive filter.
a) True
b) False
Answer
Answer: a [Reason:] In this way, you can write many, singly focused ItemProcessors and then reuse them and chain them as necessary.
15. If the preceding job was run on a batch with a 100 rows, each item was read and passed through the processor, and it found 10 items invalid (it returned null 10 times), the value for the filter_count column would be:-
a) 100
b) 1
c) 10
d) 1000
Answer
Answer: c [Reason:] You could see that a 100 items were read from the read_count. The write_count column would reflect that 10 items didn’t make it and would show 90.
Java MCQ Set 2
1. You want to control how steps are executed, perhaps to eliminate a needless waste of time by:-
a) concurrent steps
b) decisions
c) sequential steps
d) all of the mentioned
Answer
Answer: d [Reason:] There are different ways to change the runtime profile of your jobs, mainly by exerting control over the way steps are executed: concurrent steps, decisions, and sequential steps.
2. Typical jobs of almost any complexity will have multiple steps, however.
a) True
b) False
Answer
Answer: a [Reason:] A step provides a boundary (transactional or not) to the beans and logic it encloses.
3. There’s nothing to prevent you from having many steps within the flow elements.
a) True
b) False
Answer
Answer: a [Reason:] Nor was there anything preventing you from having more steps after the split element. The split element, like the step elements, takes a next attribute as well.
4. Spring Batch provides a mechanism to offload processing to another process.
a) chunking
b) remote chunking
c) remote
d) none of the mentioned
Answer
Answer: b [Reason:] Spring Batch provides a mechanism to offload processing to another process. This feature, called remote chunking, is new in Spring Batch 2.x.
5. Pattern which refers to the arrangement of multiple JMS clients all consuming the same queue’s messages.
a) aggressive-consumer
b) aggressive
c) all of the mentioned
d) none of the mentioned
Answer
Answer: a [Reason:] If one client consumes a message and is busy processing, other idle queues will get the message instead.
6. Spring Batch ships with only handler, which executes steps in multiple threads using a TaskExecutor strategy.
a) TaskExecutorPartition
b) TaskExecutorPartitionHandler
c) TaskExecutorPartitionHandle
d) TaskExecutor
Answer
Answer: b [Reason:] This simple improvement might be enough of a justification for this feature! If you’re really hurting, however, you can extend it.
7. To determine the next step is the simplest example of a conditional flow.
a) Exit
b) Status
c) ExitStatus
d) None of the mentioned
Answer
Answer: c [Reason:] Spring Batch facilitates this through the use of the stop, next, fail, and end elements.
8. If you want to vary the execution flow based on some logic more complex than a job’s ExitStatuses:-
a) ExitStatus
b) Exit
c) Decision
d) All of the mentioned
Answer
Answer: c [Reason:] If you want to vary the execution flow based on some logic more complex than a job’s ExitStatuses, you may give Spring Batch a helping hand by using a decision element and providing it with an implementation of a JobExecutionDecider.
9. Spring Batch work with a system scheduler:-
a) cron
b) autosys
c) all of the mentioned
d) none of the mentioned
Answer
Answer: c [Reason:] Spring Batch work with a system scheduler such as cron or autosys, or from a web application.
10. JobLauncher reference you configured previously is obtained and used to then launch an instance of a Job.
a) True
b) False
Answer
Answer: a [Reason:] The result is a JobExecution. You can interrogate the JobExecution for information on the state of the Job, including its exit status and runtime status.
11. TaskExecutor that will spawn a thread of execution and manage that thread without blocking.
a) Async
b) Sync
c) Simple
d) SimpleAsyncTaskExecutor
Answer
Answer: d [Reason:] SimpleAsyncTaskExecutor will spawn a thread of execution and manage that thread without blocking.
12. The CommandLineJobRunner for success will return system error codes:-
a) 0
b) 1
c) 2
d) none of the mentioned
Answer
Answer: a [Reason:] The CommandLineJobRunner will even return system error codes (0 for success, 1 for failure, and 2 for an issue with loading the batch job) so that a shell (such as used by most system schedulers) can react or do something about the failure.
13. More complicated return codes can be returned by creating and declaring a top-level bean that implements the interface:-
a) ExitCode
b) ExitCodeMapper
c) ExitMapper
d) All of the mentioned
Answer
Answer: b [Reason:] More complicated return codes can be returned by creating and declaring a top-level bean that implements the interface ExitCodeMapper, in which you can specify a more useful translation of exit status messages to integer-based error codes that the shell will see on process exit.
14. The bean is recognized and becomes part of the application context because of the:-
a) @Component
b) @Attr
c) All of the mentioned
d) None of the mentioned
Answer
Answer: a [Reason:] The bean is recognized and becomes part of the application context because of the @Component annotation, which we enabled with the context:component-scan element in our reworked batch.xml (which we’re calling scheduled_batch.xml).
15. To parameterize a job, which is then available to your steps through Spring Batch’s expression language.
a) Job
b) Steps
c) JobParameters
d) None of the mentioned
Answer
Answer: c [Reason:] A job is a prototype of a JobInstance. JobParameters are used to provide a way of identifying a unique run of a job (a JobInstance). These JobParameters allow you to give input to your batch process, just as you would with a method definition in Java.
Java MCQ Set 3
1. Beans can be created by which of the following properties?
a) Scope
b) Property
c) Class
d) It’s own constructor
Answer
Answer: d [Reason:] Class’s constructor can create bean.
2. Which attribute is used to specify classname of the bean?
a) name
b) id
c) class
d) constructor-args
Answer
Answer: c [Reason:] Class attribute is mandatory and denotes the class used to create bean.
3. Which of the following method can be used to used to instantiate a method?
a) static factory method
b) default-init method
c) destroy method
d) lazy-init method
Answer
Answer: a [Reason:] Class attribute is used to specify the name of the class that contains the static factory method.
4. Which attribute is used to specify static factory-method?
a) factory-method
b) default-init method
c) destroy method
d) lazy-init method
Answer
Answer: a [Reason:] factory-method attribute denotes the name of actual method of the class.
5. Purpose of Static Factory Method?
a) Static method to create an object
b) Initialize bean
c) All of the mentioned
d) None of the mentioned
Answer
Answer: a [Reason:] Instantiate a bean using static method.
6. Exception thrown by factory method?
a) IllegalArgumentException
b) IndexOutofBoundException
c) ClassPathNotFoundException
d) BeanCreationException
Answer
Answer: d [Reason:] Spring generates the above mentioned exception, in case something’s wrong.
7. Snippet of Code:
public class CreatePro { String ProductId; public CreatePro(String ProductId){ this.ProductId = ProductId; } public static Product creation_Product(String productId) { System.out.println("Bean Created"); if ("aaa".equals(productId)) { return new Battery("AAA", 2.5); } else if ("cdrw".equals(productId)) { return new Disc("CD-RW", 1.5); } } } <beans ...> <bean id="aaa" class="CreatePro" factory-method="createProduct"> <constructor-arg value="aaa" /> </bean> <bean id="cdrw" class="CreatePro" factory-method="createProduct"> <constructor-arg value="cdrw" /> </bean> </beans>
What will be the output?
a) BeanCreationException
b) Bean Created
c) ClassPathException
d) None of the mentioned
Answer
Answer: a [Reason:] Since factory-method doesn’t exists in the ProductCreator class, so exception thrown.
Output: BeanCreationException
8. A bean can have more than one name using multiple id attributes?
a) True
b) False
Answer
Answer: a [Reason:] Beans are allowed to have more than one ids.
9. Bean’s naming convention:-
starts with lowercase, camel-case from then on.?
a) True
b) False
Answer
Answer: a [Reason:] Beans follow naming conventions.
10. Beans can be created by which of the following properties?
a) Static factory-method
b) Instance Fatcory-Method
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Instantiate a bean via static and instance Factory methods.
11. The bean instance is mentioned by the factory-method attribute, while the factory method is signified by the factory-bean attribute?
a) True
b) False
Answer
Answer: b [Reason:] The bean instance is mentioned by factory-bean attr while factory method is for factory-method attr.
12. One factory class can also hold more than one factory method True/False?
a) True
b) False
Answer
Answer: a [Reason:] A single instantiated bean can have more than one methods.
13. Snippet of Code:
public class CreatePro { String ProductId; public CreatePro(String ProductId) this.ProductId = ProductId; } public static Product creation_Product(String productId) { System.out.println("Bean Created"); if ("aaa".equals(productId)) { return new Battery("AAA", 2.5); } else if ("cdrw".equals(productId)) { return new Disc("CD-RW", 1.5); } } <beans ...> <bean id="aaa" class="CreatePro" factory-method="createProduct"> <constructor-arg value="aaa" /> </bean> <bean id="cdrw" class="CreatePro" factory-method="createProduct"> <constructor-arg value="cdrw" /> </bean> </beans> slight change in XML file:- <bean id="aaa" factory-bean="productCreator" factory-method="createProduct"> <constructor-arg value="aaa" /> </bean> <bean id="cdrw" factory-bean="productCreator" factory-method="createProduct"> <constructor-arg value="cdrw" /> </bean>
What will be the output:-
a) BeanCreationException
b) IllegalArgumentException
c) New Product will be created
d) None of the mentioned
Answer
Answer: c [Reason:] Factory-Bean is used instead of class.
14. Instance Factory method’s main purpose is to encapsulate the object-creation process in a method of another object instance.
a) True
b) False
Answer
Answer: a [Reason:] The client who requests an object can simply make a call to this method without knowing about the creation detail.
15. Which Attribute is used to specify the bean declared?
a) factory-bean
b) scope
c) getBean
d) declareBean
Answer
Answer: a [Reason:] To declare a bean created by an instance factory method, you specify the bean hosting the factory method in the factory-bean attribute.
Java MCQ Set 4
1. A Grails view can contain:-
a) HTML Tags
b) GSP or JSTL Tags
c) Groovy or Java code
d) All of the mentioned
Answer
Answer: d [Reason:] A Grails view can contain display elements (e.g., HTML tags), business logic elements (e.g., GSP or JSTL tags) or straightforward Groovy or Java code to achieve its display objectives.
2. A view can require a unique combination of display elements and business logic.
a) True
b) False
Answer
Answer: a [Reason:] To simplify the inclusion of such a combination and facilitate its reuse in multiple views a custom tag can be used.
3. To create custom tags.
a) grails create tag
b) grails create-tag-lib tag-lib-name
c) all of the mentioned
d) none of the mentioned
Answer
Answer: b [Reason:] To create custom tags, you can use the grails create-tag-lib tag-lib-name command.
4. grails create-tag-lib tag-lib-name command creates a custom tag library under:-
a) /grails-app/tag/
b) /grails-app/
c) /grails-app/tag-lib/
d) none of the mentioned
Answer
Answer: c [Reason:] This command creates a skeleton class for a custom tag library under an application’s /grails-app/tag-lib/ directory.
5. In order for this custom tag to function properly in JSP, it’s necessary to add it to the corresponding Tag Library Definition (TLD) grails.tld.
a) True
b) False
Answer
Answer: a [Reason:] TLDs are located in an application’s /web-app/WEB-INF/tld/ directory.
6. Custom tags can also rely on input parameters.
a) True
b) False
Answer
Answer: a [Reason:] Custom tags can also rely on input parameters passed in as tag attributes to perform a backing class’s logic.
7. By default, Grails assigns custom tags to:-
a) g: namespace
b) f: namespace
c) j: namespace
d) all of the mentioned
Answer
Answer: a [Reason:] Finally, a word about the namespace used in Grails custom tags—by default, Grails assigns custom tags to the g: namespace.
8. By default, Grails applies a global layout to display an application’s content.
a) True
b) False
Answer
Answer: a [Reason:] This allows views to have a minimal set of display elements (e.g., HTML, CSS, and JavaScript) and inherit their layout behavior from a separate location.
9. Grails doesn’t supports the concept of templates.
a) True
b) False
Answer
Answer: b [Reason:] Grails also supports the concept of templates, which serve the same purpose as layouts, except applied at a more granular level. In addition, it’s also possible to use templates for rendering a controller’s output, instead of a view as in most controllers.
10. Where is subdirectory called layouts located, containing the layouts available to an application?
a) /grails-app/view/
b) /grails-app/
c) /grails-app/view/WEB-INF
d) none of the mentioned
Answer
Answer: a [Reason:] Inside the /grails-app/view/ directory of an application, you can find a subdirectory called layouts, containing the layouts available to an application.
11. Tag is used to define the contents of a layout’s title section.
a) g:layoutTitle
b) g:layoutHead
c) g:layoutBody
d) g:layoutMeta
Answer
Answer: a [Reason:] The g:layoutTitle tag is used to define the contents of a layout’s title section.
12. Tag is used to define the contents of a layout’s head section.
a) g:layoutTitle
b) g:layoutHead
c) g:layoutBody
d) g:layoutMeta
Answer
Answer: b [Reason:] Any values declared in the head of a view head inheriting this layout are placed in this location upon rendering.
13. Tag allows any view inheriting this layout automatic access to JavaScript libraries.
a) g:javascript library=”application”
b) g:layoutHead
c) g:layoutBody
d) g:layoutMeta
Answer
Answer: a [Reason:] Upon rendering, this element is transformed into the following: script type=”text/javascript” src=”/court/js/application.js” /script.
14. A view’s body content is inside the:-
a) g:javascript library=”application”
b) g:layoutHead
c) g:layoutBody
d) g:layoutMeta
Answer
Answer: c [Reason:] Grails automatically sorts out the substitution process by placing a view’s title content inside the g:layoutTitle tag, a view’s body content inside the g:layoutBody / tag, and so on.
15. GORM dynamic finder comparators:-
a) InList
b) LessThan
c) LessThanEquals
d) All of the mentioned
Answer
Answer: d [Reason:] GORM comparator Query
InList If value is present in a given list of values
LessThan For lesser object(s) than the given value
LessThanEquals For lesser or equal object(s) than the given value
GreaterThan For greater object(s) than the given value
GreaterThanEquals For greater or equal object(s) than the given value
Like For object(s) like the given value
Ilike For object(s) like the given value in a case insensitive manner
NotEqual For object(s) not equal to the given value
Between For object(s) between to the two given values
IsNotNull For not null object(s); uses no arguments
IsNull For null object(s); uses no arguments
Java MCQ Set 5
1. Declaring Beans using:-
a) Static field
b) Object Properties
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Beans can be declared from static fields as well as Object properties.
2. Ways to declare bean from a static field?
a) FieldRetrievingFactoryBean
b) util:contant
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] To declare a bean from a static field, you can make use of either the built-in factory bean FieldRetrievingFactoryBean, or the util:constant tag in Spring 2.x.
3. Declaring a bean from a static field requires a built-in factory bean FieldRetrievingFactoryBean and fully qualified field name or instance filed is specified in the list property.
a) True
b) False
Answer
Answer: b [Reason:] StaticField property is used to specify instance field name.
4. A)
public abstract class Product { public static final Product AAA = new Battery("AAA", 2.5); public static final Product CDRW = new Disc("CD-RW", 1.5); ... } <beans ...> <bean id="aaa" class="org.springframework.beans.factory.config. FieldRetrievingFactoryBean"> <property name="staticField"> <value>com.shop.Product.AAA</value> </property> </bean> <bean id="cdrw" class="org.springframework.beans.factory.config. FieldRetrievingFactoryBean"> <property> name="staticField" valuecom.shop.Product.CDRW/value </property> </bean> </beans> B) Product aaa = com.shop.Product.AAA; Product cdrw = com.shop.Product.CDRW;
a) A and B are equivalent
b) A and B provides different functionality
c) Runtime Error in A
d) Exception in B
Answer
Answer: a [Reason:] StaticField method fills up the static fields with the provided property’s values.
5. As an alternative to specifying the field name in the staticField property explicitly, you can set it as the bean name of FieldRetrievingFactoryBean.
a) True
b) False
Answer
Answer: a [Reason:] Bean name may get rather long and verbose.
6.
<beans ...> bean id="com.shop.Product.AAA" class="org.springframework.beans.factory.config. FieldRetrievingFactoryBean" / bean id="com.shop.Product.CDRW" class="org.springframework.beans.factory.config. FieldRetrievingFactoryBean" / </beans>
Is this bean configuration metadata correct?
a) Yes
b) No
Answer
Answer: a [Reason:] This is an alternate method of using staticfield in property attributes.
7. Which tag is also allowed by static field?
a) util:constant
b) list
c) set
d) constructor-args
Answer
Answer: a [Reason:] Spring 2 and later allow you to declare a bean from a static field by using the util:constant tag.
8.
<beans >="http://www.springframework.org/schema/beans" >:xsi="http://www.w3.org/2001/XMLSchema-instance" >:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util/spring-util-3.0.xsd" util:constant id="aaa" static-field="com.shop.Product.AAA" /> util:constant id="cdrw" static-field="com.shop.Product.CDRW" /> </beans>
Is this bean configuration correct?
a) Yes
b) No
Answer
Answer: b [Reason:] Schema for util:constant needs to be included using this link: http://www.springframework.org/schema/util.
9. Declaring bean form object properties can be done using:-
a) PropertyPathFactoryBean
b) util:constant
c) None of the mentioned
d) All of the mentioned
Answer
Answer: a [Reason:] To declare a bean from an object property or a property path, you can make use of either the built-in factory bean PropertyPathFactoryBean or the util:property-path tag in Spring 2.x.
10. Inner Bean can be retrieved by it’s name.
a) True
b) False
Answer
Answer: b [Reason:] Since inner beans are local to another bean, so can’t be accessed globally.
11. PropertyPathFactoryBean declares a bean from an:-
a) Object Property
b) Property Path
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] The factory bean PropertyPathFactoryBean can be used to declare a bean from an object property or a property path.
12. The propertyPath property of PropertyPathFactoryBean can accept only a single property name.
a) True
b) False
Answer
Answer: b [Reason:] The propertyPath property of PropertyPathFactoryBean can accept not only a single property name but also a property path with dots as the separators.
13. Alternate way of PropertyPathFactoryBean to declare a bean.
a) util:property-path tag
b) util:constant tag
c) None of the mentioned
d) All of the mentioned
Answer
Answer: a [Reason:] Compared to using PropertyPathFactoryBean, it is a simpler way of declaring beans from properties.
14. We can combine target Object and propertyPath properties as bean name/id of PropertyPathFactoryBean.
a) True
b) False
Answer
Answer: a [Reason:] In addition to specifying the targetObject and propertyPath properties explicitly, you can combine them as the bean name of PropertyPathFactoryBean. The downside is that your bean name may get rather long and verbose.
15. The Spring Expression Language can be accessed by:-
a) XML configuration
b) Annotations
c) None of the mentioned
d) All of the mentioned
Answer
Answer: d [Reason:] The expression language is available via XML or annotations.