250+ TOP MCQs on Spring Batch infrastructure and Reading,Writing and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) 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
Answer: c
Clarification: 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: a
Clarification: 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: b
Clarification: 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: a
Clarification: 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: a
Clarification: 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: a
Clarification: 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: a
Clarification: 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: b
Clarification: 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: c
Clarification: 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, which in turn delegates the task of identifying the fields within that record, to LineTokenizer.
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

Answer: a
Clarification: 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: a
Clarification: 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: d
Clarification: There’s support for writing JMS (JmsItemWriter), JPA (JpaItemWriter), JDBC (JdbcBatchItemWriter), Files (FlatFileItemWriter), iBatis (IbatisBatchItemWriter), Hibernate (HibernateItemWriter), and more.

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: c
Clarification: 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
View Answer

Answer: a
Clarification: 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: c
Clarification: 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.

Leave a Reply

Your email address will not be published. Required fields are marked *