This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses on “Spring Batch infrastructure and Reading, Writing”.
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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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 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 12. There’s support for writing JMS:- 13. The processor attribute on the chunk element expects a reference to a bean of the interface:- 14. Spring Batch provides a convenience class, CompositeItemProcessor, which forwards the output of the filter to the input of the successive filter. 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:- Sanfoundry Global Education & Learning Series – Java Spring.
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
View Answer
Explanation: The FlatFileItemReader also declares a fieldSetMapper attribute that requires an implementation of FieldSetMapper.
a) BeanPropertyItemSqlParameterSourceProvider
b) BeanPropertyItemSqlParameterSource
c) BeanPropertyItemSqlParameter
d) All of the mentioned
View Answer
Explanation: 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.
a) JmsItemWriter
b) JpaItemWriter
c) JdbcBatchItemWriter
d) All of the mentioned
View Answer
Explanation: There’s support for writing JMS (JmsItemWriter
a) org.springframework.batch.item.Item
b) org.springframework.batch.item
c) org.springframework.batch.item.ItemProcessor
d) none of the mentioned
View Answer
Explanation: The processor attribute on the chunk element expects a reference to a bean of the interface org.springframework.batch.item.ItemProcessor.
a) True
b) False
View Answer
Explanation: In this way, you can write many, singly focused ItemProcessors and then reuse them and chain them as necessary.
a) 100
b) 1
c) 10
d) 1000
View Answer
Explanation: 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.
To practice all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.