Java MCQ Set 1
1. The Cobertura command to run while reporting is ______
a) cobertura-report.bat
b) cobertura-instrument.bat
c) cobertura-check.bat
d) cobertura-merge.bat
Answer
Answer: a [Reason:] The cobertura-report.bat command is used along with parameters to run reporting using Cobertura.
2. The ______ parameter is used to specify the type of report.
a) datafile
b) basedir
c) encoding
d) format
Answer
Answer: d [Reason:] The format parameter defines the type of report to be generated.
3. ______ parameter specifies the encoding used to read the source.
a) datafile
b) basedir
c) encoding
d) format
Answer
Answer: c [Reason:] During reporting with Cobertura, the encoding parameter defines the encoding of the files.
4. The source code directories are used to calculate the ______ of each class.
a) Data size
b) Lines of code
c) Cyclomatic code complexity
d) Mutant score
Answer
Answer: c [Reason:] The cyclomatic code complexity is a metric to indicate the complexity of the code.
5. The default value of the format parameter is ______
a) html
b) jar
c) java
d) dat
Answer
Answer: a [Reason:] The HTML reports are made of annotated versions of each source file.
6. The Cobertura command to run while checking coverage is ______
a) cobertura-report.bat
b) cobertura-instrument.bat
c) cobertura-check.bat
d) cobertura-merge.bat
Answer
Answer: c [Reason:] The cobertura-check.bat command is used along with parameters to run reporting using Cobertura.
7. “cobertura-check.bat” is run ________ the JUnit tests to show which classes do not have adequate test coverage.
a) Before
b) After
c) Along with
d) Before and after
Answer
Answer: b [Reason:] This is used to check test coverage and hence, can only be run after the JUnit tests.
8. The _____ parameter specifies the minimum acceptable branch coverage rate needed by each class during Cobetura coverage checking.
a) datafile
b) branch
c) line
d) regex
Answer
Answer: b [Reason:] The branch parameter should be an integer between 0 and 100.
9. The _____ parameter specifies the minimum acceptable line coverage rate needed by each class during Cobetura coverage checking.
a) datafile
b) branch
c) line
d) regex
Answer
Answer: c [Reason:] The line parameter should be an integer between 0 and 100.
10. The _____ parameter specifies the minimum acceptable branch coverage rate needed by each package during Cobetura coverage checking.
a) datafile
b) packagebranch
c) line
d) regex
Answer
Answer: b [Reason:] The packagebranch parameter should be an integer between 0 and 100.
Java MCQ Set 2
1. The Executor implementations provided implement ______ which is a more extensive interface.
a) ExecutorService
b) ThreadPoolExecutor
c) ArrayDeque
d) SerialExecutor
Answer
Answer: a [Reason:] The ExecutorService interface is extended and implemented by the Executor implementations.
2. The ____ command executes the given command at some time in the future.
a) Execution()
b) execute(Runnable command)
c) scheduleNext()
d) poll()
Answer
Answer: b [Reason:] The command may execute in a new thread, in a pooled thread, or in the calling thread.
3. The _______ exception can be thrown by the execute(Runnable command) function.
a) Arithmetic
b) ArrayIndexOutOfBounds
c) StringIndexOutOfBounds
d) RejectedExecutionException
Answer
Answer: d [Reason:] RejectedExecutionException is thrown if the task cannot be accepted for execution.
4. Other than RejectedExecutionException, the execute(Runnable command) function can also throw which exception?
a) Arithmetic
b) ArrayIndexOutOfBounds
c) StringIndexOutOfBounds
d) NullPointerException
Answer
Answer: d [Reason:] This exception is thrown if the command passed as argument is null.
5. ________ runs all commands that are currently pending.
a) runUntilIdle
b) runPendingCommands
c) execute
d) isIdle
Answer
Answer: b [Reason:] If those commands also schedule commands for execution, the scheduled commands will not be executed.
6. ______ runs executed commands until there are no commands pending execution.
a) runUntilIdle
b) runPendingCommands
c) execute
d) isIdle
Answer
Answer: a [Reason:] runUntilIdle does not tick time forward but just runs executed commands.
7. ______ returns whether this executor is idle.
a) runUntilIdle
b) runPendingCommands
c) execute
d) isIdle
Answer
Answer: d [Reason:] isIdle() function checks that there are no pending background tasks waiting to be run.
8. ______ runs time forwards by a given duration, executing any commands scheduled for execution during that time period.
a) runUntilIdle
b) runPendingCommands
c) tick
d) isIdle
Answer
Answer: c [Reason:] The tick() command also runs any background tasks spawned by the scheduled tasks.
9. When a call to tick returns, the executor will be idle.
a) True
b) False
Answer
Answer: a [Reason:] Since the spawned background tasks are run the executor remains idle.
10. ____ blocks until all tasks have completed execution after a shutdown request, or the timeout occurs.
a) awaitTermination
b) runPendingCommands
c) tick
d) isIdle
Answer
Answer: a [Reason:] awaitTermination returns true if this executor terminated and false if the timeout elapsed before termination.
Java MCQ Set 3
1. When unit testing, it’s important to be able to control as much as possible of the environment in which the tests execute.
a) True
b) False
Answer
Answer: a [Reason:] This ensures that the test results are reproducible.
2. ___ is a Java HTTP (Web) server and Java Servlet container.
a) Maven
b) Ant
c) Jetty
d) Zimbra
Answer
Answer: c [Reason:] Jetty is often used for machine to machine communications, usually within larger software frameworks.
3. Jetty was originally called ____
a) Eclipse
b) Maven
c) Ant
d) IssueTracker
Answer
Answer: d [Reason:] Jetty was originally known as IssueTracker as that was its original application.
4. To create a Jetty server object, we have to import _______
a) org.mortbay.jetty.Server;
b) org.jetty.Server;
c) org.junit.jetty.Server;
d) org.junit.Server;
Answer
Answer: a [Reason:] The Jetty Server is found in “org.mortbay.jetty.Server”.
5. In Jetty, ______ object processes the HTTP requests.
a) Server
b) Context
c) Root
d) Handler
Answer
Answer: b [Reason:] Context object processes the HTTP requests and passes them to various handlers.
6. To create a Jetty context object, we have to import _______
a) org.mortbay.jetty.Context;
b) org.jetty.Context;
c) org.mortbay.jetty.servlet.Context;
d) org.junit.Server;
Answer
Answer: c [Reason:] The Jetty Server is found in “org.mortbay.jetty.servlet.Context”.
7. While creating a server object like- Server obj = new Server(8080), 8080 represents the number of connections.
a) True
b) False
Answer
Answer: b [Reason:] The parameter of the constructor, in this case 8080, represents the port number.
8. The ________ method sets the document root from which to serve resources.
a) setResourceBase
b) resourceBase
c) setResource
d) setBase
Answer
Answer: a [Reason:] The setResourceBase method is used to set the document root from which resources will be served.
9. A _______ handler is attached to the root to serve files from the file system.
a) SourceHandler
b) ResourceHandler
c) AttachHandler
d) RootHandler
Answer
Answer: b [Reason:] The ResourceHandler is attached to serve files from the file system.
10. The ResourceHandler is found in the package ____
a) org.mortbay.jetty.handler.ResourceHandler
b) org.jetty.handler.ResourceHandler
c) org.mortbay.junit.handler.ResourceHandler
d) org.junit.jetty.handler.ResourceHandler
Answer
Answer: a [Reason:] The ResourceHandler class is a part of the handler package found at “org.mortbay.jetty.handler.ResourceHandler”.
Java MCQ Set 4
1. _____ is an existing defect in the system which does not cause any failure.
a) Latent defect
b) Redundancy
c) Failure
d) Exit Cause
Answer
Answer: a [Reason:] Latent Defect does not cause any failure because the exact set of conditions has never been met.
2. ____ are set of documents, tools and other components that has to be developed and maintained in support of testing.
a) Test Functions
b) Test Deliverables
d) Test Solutions
c) Test Mechanisms
Answer
Answer: b [Reason:] Test Deliverables are artefacts which are given to the stakeholders of software project during the sdlc.
3. ________ is a technique to identify whether a set of test data is useful by intentionally introducing various code changes (bugs).
a) Unit Testing
b) Stress Testing
c) Load Testing
d) Mutation Testing
Answer
Answer: d [Reason:] Mutation testing involves retesting with original test data to determine if the bugs are detected.
4. Mutation testing is a form of ________
a) Black Box Testing
b) Redundancy
c) White Box Testing
d) Loss Testing
Answer
Answer: c [Reason:] In mutation testing, the internals of the code need to be known.
5. Mutation score = _______ / total number of mutants
a) Number of mutants killed
b) Number of mutants not killed
c) Total number of mutants
d) Total number of live mutants
Answer
Answer: a [Reason:] The number of mutants killed or the number of dead mutants is used in calculating the mutation score.
5. For a mutant to be killed, the test must ____ the mutated statement.
a) Overlook
b) Ignore
c) Limit
d) Reach
Answer
Answer: d [Reason:] Mutants which cannot be reached cannot be affected by the test.
6. Input data from the test must ____ the program state by causing different program states for the mutant and the original program.
a) Reach
b) Infect
c) Kill
d) Destroy
Answer
Answer: b [Reason:] Infecting is the same as executing the mutant code by such test data that different states are produced.
7. The incorrect program state must ____ to the program’s output and be checked by the test.
a) Reach’
b) Infect
c) Propagate
d) Limit
Answer
Answer: c [Reason:] The test data for the mutant must be noticed in the output.
8. Mutation Testing follows the ______ model.
a) RIP
b) KISS
c) RUN
d) GOD
Answer
Answer: a [Reason:] RIP stands for reach, infect and propagate.
9. The ______ hypothesis states that most software faults are due to small syntactic errors.
a) Coupling effect
b) Competent programmer
c) Higher-order mutation
d) Equivalent mutation
Answer
Answer: b
Answer: The competent programmer hypothesis is one of the basis of mutation testing.
10. The ________ asserts that simple faults can cascade to form other emergent faults.
a) Coupling effect
b) Competent programmer
c) Higher-order mutation
d) Equivalent mutation
Answer
Answer: a [Reason:] Coupling effect is further supported by subtle and important faults being revealed by higher-order mutants.
Java MCQ Set 5
1. The Cobertura command for merging datafiles is ____
a) cobertura-report.bat
b) cobertura-instrument.bat
c) cobertura-check.bat
d) cobertura-merge.bat
Answer
Answer: d [Reason:] The cobertura-merge.bat command is used along with parameters to run merging using Cobertura.
2. In order to write testable code, ________ should be reduced as much as possible.
a) Dependencies
b) Redundancies
c) Objects
d) Classes
Answer
Answer: a [Reason:] Classes with too many dependencies require complicated tests.
3. A solution to reducing dependencies is to separate code between methods that instantiate new ______ and methods that provide application logic.
a) Classes
b) Objects
c) Modules
d) Functions
Answer
Answer: b [Reason:] Separation of objects and logic leads to reduced dependencies.
4. ____ is a design guideline that states that one class should know only as much as it needs to know.
a) Law of knowledge
b) Class laws
c) Law of Demeter
d) Action methods
Answer
Answer: c [Reason:] The law of demeter is also known as the Principle of Least Knowledge.
5. ______ is a useful design pattern that ensures a class has only one instance.
a) Modular code
b) Lossless paradigm
c) Granular methods
d) Singleton
Answer
Answer: d [Reason:] Most often, the implementation of a singleton defines a private constructor and a static variable.
6. The obvious drawback of a singleton is that it introduces _______ into the application.
a) Redundancies
b) Errors
c) Global State
d) Modules
Answer
Answer: c [Reason:] The global state object can be accessed by anyone.
7. ___ can easily be used to substitute application code with the test code.
a) Encapsulation
b) Polymorphism
c) Overloading
d) Static binding
Answer
Answer: b [Reason:] Polymorphism is used to force certain code patterns to be tested.
8. At runtime, code can’t change a/an _____ hierarchy.
a) Encapsulation
b) Polymorphism
c) Overloading
d) Inheritence
Answer
Answer: d [Reason:] As code cannot change the hierarchy, objects needs to be composed differently.
9. For wrtiting favourable tests, ____ is perferred over inheritance.
a) Encapsulation
b) Polymorphism
c) Overloading
d) Composition
Answer
Answer: d [Reason:] Composition is a better code re-use mechanism.
10. One of the main ways to decrease complexity is to try to avoid long ___ and if statements.
a) switch
b) then
c) default
d) static
Answer
Answer: a [Reason:] Long switch statements increase the complexity of code and corresponding test cases.