Java MCQ Set 1
1. This encapsulates the context of a test’s execution:-
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener
Answer
Answer: a [Reason:] This encapsulates the context of a test’s execution, including the application context, test class, current test instance, current test method, and current test exception.
2. This manages a test context for a test and triggers test execution listeners:-
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener
Answer
Answer: b [Reason:] This manages a test context for a test and triggers test execution listeners at predefined test execution points, including when preparing a test instance, before executing a test method (before any framework-specific initialization methods), and after executing a test method (after any framework-specific cleanup methods).
3. This defines a listener interface; by implementing this, you can listen to test execution events.
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener
Answer
Answer: d [Reason:] The TestContext framework provides several test execution listeners for common testing features, but you are free to create your own.
4. Spring provides convenient TestContext support classes for:-
a) JUnit3
b) JUnit4
c) TestNG5
d) All of the mentioned
Answer
Answer: d [Reason:] Spring provides convenient TestContext support classes for JUnit 3, JUnit 4, and TestNG 5, with particular test execution listeners preregistered.
5. JUnit 4 allows you to annotate your test methods with:-
a) @Test
b) @Autowire
c) @JTest
d) None of the mentioned
Answer
Answer: a [Reason:] JUnit 4 allows you to annotate your test methods with JUnit’s @Test annotation, so an arbitrary public method can be run as a test case.
6. Usually, a test and its target class are located in the same package, but the source files of tests are stored in a separate directory.
a) True
b) False
Answer
Answer: a [Reason:] (e.g., test) from the source files of other classes (e.g., src).
7. Method to perform cleanup tasks:-
a) finalize
b) tearDown
c) all of the mentioned
d) none of the mentioned
Answer
Answer: c [Reason:] You can override the tearDown() method to perform cleanup tasks, such as releasing permanent resources.
8. The static assert methods is declared in the:-
a) org.junit.Assert
b) org.junit.*
c) all of the mentioned
d) none of the mentioned
Answer
Answer: c [Reason:] You can override the tearDown() method to perform cleanup tasks, such as releasing permanent resources.
9. Attribute which specifies the exception type:-
a) after
b) expected
c) before
d) test
Answer
Answer: b [Reason:] JUnit 4 offers a powerful feature that allows you to expect an exception to be thrown in a test case. You can simply specify the exception type in the expected attribute of the @Test annotation.
10. Test data sets are provided by data providers, which are methods with the:-
a) @DataProvider
b) @Autowire
c) @JTest
d) None of the mentioned
Answer
Answer: a [Reason:] In TestNG, test data sets are provided by data providers, which are methods with the @DataProvider annotation.
11. An object that simulates a dependent object:-
a) stub
b) mock
c) test
d) none of the mentioned
Answer
Answer: a [Reason:] A stub is an object that simulates a dependent object with the minimum number of methods required for a test.
12. An Object which usually knows how its methods are expected to be called:-
a) stub
b) mock
c) test
d) none of the mentioned
Answer
Answer: b [Reason:] In contrast to a stub, a mock object usually knows how its methods are expected to be called in a test.
13. Libraries that can help create mock objects:-
a) EasyMock
b) jMock
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] In Java, there are several libraries that can help create mock objects, including EasyMock and jMock.
14. Test used to test several units in combination as a whole.
a) Integration tests
b) JUnit4
c) TestNG5
d) All of the mentioned
Answer
Answer: a [Reason:] Integration tests, in contrast, are used to test several units in combination as a whole.
15. Spring supports web controller testing by providing Servlet API:-
a) MockHttpServletRequest
b) MockHttpServletResponse
c) MockHttpSession
d) All of the mentioned
Answer
Answer: d [Reason:] Spring supports web controller testing by providing a set of mock objects for the Servlet API (including MockHttpServletRequest, MockHttpServletResponse, and MockHttpSession).
Java MCQ Set 2
1. Interface for Dispatcher Servlet to auto detect view resolver beans.
a) localeResolver
b) tiles
c) ViewResolver
d) none of the mentioned
Answer
Answer: c [Reason:] Spring MVC comes with several ViewResolver implementations for you to resolve views using different strategies.
2. ViewResolver which maps each view name tol an application’s directory.
a) InternalViewResolver
b) InternalResourceViewResolver
c) InternalResolver
d) None of the mentioned
Answer
Answer: b [Reason:] The view resolver InternalResourceViewResolver maps each view name to an application’s directory by means of a prefix and a suffix declaration.
3. InternalResourceViewResolver resolves view names into view objects of type.
a) JstlView
b) Jst Library
c) View
d) None of the mentioned
Answer
Answer: a [Reason:] By default, InternalResourceViewResolver resolves view names into view objects of type JstlView if the JSTL library (i.e., jstl.jar) is present in the classpath.
4. By default, XmlViewResolver loads view beans from /WEB-INF/views.xml which is final.
a) True
b) False
Answer
Answer: b [Reason:] This location can be overridden through the location property.
5. View beans from a resource bundle is loaded by.
a) ResourceBundleViewResolver
b) ResourceBundleView
c) ResourceViewResolver
d) None of the mentioned
Answer
Answer: a [Reason:] ResourceBundleViewResolver loads view beans from a resource bundle in the classpath root.
6. Views that can’t be resolved by InternalResourceViewResolver.
a) redirect
b) redirect:prefix
c) redirect:suffix
d) all of the mentioned
Answer
Answer: a [Reason:] Now the resource bundle views.properties should only contain the views that can’t be resolved by InternalResourceViewResolver (e.g., the redirect views).
7. Properties used to determine the correct content and type for a certain web requests.
a) The URL extension provided in a request
b) The HTTP Accept header
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] When a request is received for a web application, it contains a series of properties that allow the processing framework, in this case Spring MVC, to determine the correct content and type to return to the requesting party.
8. Inspection of header is donw by which of the following.
a) InternalViewResolver
b) ContentNegotiatingViewResolver
c) ContentNegotiating
d) InternalResolver
Answer
Answer: b [Reason:] Inspecting HTTP Accept headers in a controller can be a messy process. So Spring MVC supports the inspection of headers through the ContentNegotiatingViewResolver.
9. ContentNegotiatingViewResolver resolver configuration sets up the resolver to have the highest priority among all resolvers.
a) True
b) False
Answer
Answer: a [Reason:] It’s necessary to make the content negotiating resolver work.
10. The ContentNegotiatingViewResolver resolver first determines the media type for a request based on which of the following criteria?
a) It checks a request path extension
b) If a request path has an extension but no match can be found in the default mediaTypes section of the ContentNegotiatingViewResolver bean
c) If no extension is present in a request path, the HTTP Accept header of the request is used
d) All of the mentioned
Answer
Answer: d [Reason:] It checks a request path extension (e.g., .html, .xml, or .pdf) against the default
media types (e.g., text/html) specified in the mediaTypes section of the
ContentNegotiatingViewResolver bean.
If a request path has an extension but no match can be found in the default
mediaTypes section of the ContentNegotiatingViewResolver bean, an attempt is
made to determine an extension’s media type using FileTypeMap belonging to Java
Activation Framework.
If no extension is present in a request path, the HTTP Accept header of the request
is used.
11. In a Spring MVC application, you can register one or more exception resolver beans in the web application context to resolve uncaught exceptions.
a) True
b) False
Answer
Answer: a [Reason:] These beans have to implement the HandlerExceptionResolver interface for DispatcherServlet to auto-detect them.
12. To configure the exception mappings in the web application context.
a) SimpleMappingExceptionResolver
b) ExceptionResolver
c) ExceptionViewResolver
d) None of the mentioned
Answer
Answer: a [Reason:] Spring MVC comes with the exception resolver SimpleMappingExceptionResolver for you to configure the exception mappings in the web application context.
13. Annotation which allows a controller’s field to be assigned using Spring Expression Language(SpEL)
a) @Value
b) @After
c) @Default
d) @None
Answer
Answer: a [Reason:] You can use the @Value annotation along with SpEL to query beans present in an application’s context and extract values to help you initialize controller fields.
14. SpEL statements are recognizable.
a) True
b) False
Answer
Answer: a [Reason:] They use a notation in the form “#{ SpEL statement }”.
15. Tag, used to define a location in which to place errors in case a form.
a) form
b) form:GET
c) form:POST
d) form:errors
Answer
Answer: d [Reason:] You can find the form:errors tag, used to define a location in which to place errors in case a form does not meet the rules set forth by a controller.
Java MCQ Set 3
1. In order to read any file in HDFS, instance of ____ is required.
a) filesystem
b) datastream
c) outstream
d) inputstream
Answer
Answer: a [Reason:] InputDataStream is used to read data from file.
2. Point out the correct statement :
a) The framework groups Reducer inputs by keys
b) The shuffle and sort phases occur simultaneously i.e. while outputs are being fetched they are merged
c) Since JobConf.setOutputKeyComparatorClass(Class) can be used to control how intermediate keys are grouped, these can be used in conjunction to simulate secondary sort on values
d) All of the mentioned
Answer
Answer: d [Reason:] If equivalence rules for keys while grouping the intermediates are different from those for grouping keys before reduction, then one may specify a Comparator.
3. ________ is method to copy byte from input stream to any other stream in Hadoop.
a) IOUtils
b) Utils
c) IUtils
d) All of the mentioned
Answer
Answer: a [Reason:] IOUtils class is static method in Java interface.
4. _______ is used to read data from bytes buffers .
a) write()
b) read()
c) readwrite()
d) all of the mentioned
Answer
Answer: a [Reason:] readfully method can also be used instead of read method.
5. Point out the wrong statement :
a) The framework calls reduce method for each
b) The output of the Reducer is re-sorted
c) reduce method reduces values for a given key
d) None of the mentioned
Answer
Answer: b [Reason:] The output of the Reducer is not re-sorted.
6. Interface ______ reduces a set of intermediate values which share a key to a smaller set of values.
a) Mapper
b) Reducer
c) Writable
d) Readable
Answer
Answer: b [Reason:] Reducer implementations can access the JobConf for the job.
7. Reducer is input the grouped output of a :
a) Mapper
b) Reducer
c) Writable
d) Readable
Answer
Answer: a [Reason:] In the phase the framework, for each Reducer, fetches the relevant partition of the output of all the Mappers, via HTTP.
8. The output of the reduce task is typically written to the FileSystem via :
a) OutputCollector
b) InputCollector
c) OutputCollect
d) All of the mentioned
Answer
Answer: a [Reason:] In reduce phase the reduce(Object, Iterator, OutputCollector, Reporter) method is called for each
9. Applications can use the ___ provided to report progress or just indicate that they are alive.
a) Collector
b) Reporter
c) Dashboard
d) None of the mentioned
Answer
Answer: b [Reason:] In scenarios where the application takes a significant amount of time to process individual key/value pairs, this is crucial since the framework might assume that the task has timed-out and kill that task.
10. Which of the following parameter is to collect keys and combined values ?
a) key
b) values
c) reporter
d) output
Answer
Answer: d [Reason:] reporter parameter is for facility to report progress.
Java MCQ Set 4
1. Which of the following property gives access to the JavaScript memory usage data?
a) performance.memory
b) memory(performance)
c) performance(memory)
d) none of the mentioned
Answer
Answer: a [Reason:] The property performance.memory gives access to the JavaScript memory usage data.
2. What is the purpose of the timing property in the window.performance object?
a) Time of navigation event
b) Time of page load event
c) Time of navigation and page load event
d) None of the mentioned
Answer
Answer: c [Reason:] Each performance.timing attribute shows the time of a navigation event (such as when the page was requested) or page load event (such as when the DOM began loading), measured in milliseconds.
3. Which of the following property is associated with the Response event?
a) responseStart
b) responseEnd
c) both responseStart and responseEnd
d) none of the mentioned
Answer
Answer: c [Reason:] The properties associated with the Response event are :
- responseStart
- responseEnd.
4. Which of the following computation is correct to calculate the time taken for page load once the page is received from the server?
a) responseEnd-loadEventEnd
b) loadEventEnd-responseEnd
c) loadEventEnd/responseEnd
d) responseEnd/loadEventEnd
Answer
Answer: b [Reason:] The time taken for page load once the page is received from the server: loadEventEnd-responseEnd.
5. Which of the following property is associated with the Processing event?
a) domComplete
b) domContentLoaded
c) domInteractive
d) none of the mentioned
Answer
Answer: d [Reason:] The following properties are associated with the Processing event :
- domComplete
- domContentLoaded
- domInteractive
- domLoading
- unLoadEnd.
6. What does it indicate when the type attribute of the navigation object is set to 2?
a) Navigation by moving back through history
b) Navigation by moving forward through history
c) Navigation by moving back & forward through history
d) None of the mentioned
Answer
Answer: c [Reason:] When the type attribute of the navigation object is set to 2, it means that the navigation is done by moving back or forward through history.
7. What does the method Performance.now() return?
a) DOMTimeStamp
b) DOMHighResTimeStamp
c) DOMStamp
d) TimeStamp
Answer
Answer: b [Reason:] The Performance.now() method returns a DOMHighResTimeStamp, measured in milliseconds, accurate to one thousandth of a millisecond equal to the number of milliseconds since the PerformanceTiming.navigationStart property and the call to the method.
8. Which of the following is a read-only property?
a) PerformanceTiming.navigationStart
b) PerformanceTiming.fetchStart
c) PerformanceTiming.navigationStart & PerformanceTiming.fetchStart
d) None of the mentioned
Answer
Answer: c [Reason:] Both PerformanceTiming.navigationStart and also the PerformanceTiming.fetchStart are a read-only properties.
9. Which of the following is an interface?
a) Time
b) Timing
c) Performance
d) PerformanceTiming
Answer
Answer: d [Reason:] PerformanceTiming is an interface in JavaScript.
10. How many properties are associated with the Response event?
a) 1
b) 2
c) 3
d) 4
Answer
Answer: b [Reason:] There are a total of 2 properties associated with the Response event namely :
- PerformanceTiming.responseEnd
- PerformanceTiming.responseStart.
Java MCQ Set 5
1. What is the property to access the first child of a node?
a) timestamp.Child1
b) timestamp.Child(1)
c) timestamp.Child(0)
d) timestamp.firstChild
Answer
Answer: d [Reason:] The first child of a node can be accessed using the firstChild property.
2. What are the properties supporting CSS styles for a document element?
a) style and font
b) style and className
c) size and style
d) className and font
Answer
Answer: b [Reason:] Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element.
3. The style property belongs to while of the following object?
a) Element
b) Window
c) Location
d) None of the mentioned
Answer
Answer: a [Reason:] Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element.
4. What is the purpose of the event handlers in the JavaScript?
a) Adds innerHTML page to the code
b) Performs handling of exceptions and occurences
c) Allows JavaScript code to alter the behaviour of windows
d) None of the mentioned
Answer
Answer: c [Reason:] Event handlers allow JavaScript code to alter the behavior of windows, of documents, and of the elements that make up those documents.
5. Which handler is triggered when the content of the document in the window is stable and ready for manipulation?
a) onload
b) manipulate
c) create
d) none of the mentioned
Answer
Answer: a [Reason:] One of the most important event handlers is the onload handler of the Window object. It is triggered when the content of the document displayed in the window is stable and ready to be manipulated. JavaScript code is commonly wrapped within an onload event handler.
6. When a program contains extensive use of event handlers, which of the following is necessary?
a) Modular functions
b) Nested functions
c) Split up programs
d) All of the mentioned
Answer
Answer: b [Reason:] Nested functions are common in client-side JavaScript, because of its extensive use of event handlers.
7. What is the code snippet to find all container elements with class “reveal”?
a) var elements = document.getElementsByClassName("reveal"); b) var elements = document.getElementByClassName("reveal"); c) var elements = document.getElementByName("reveal"); d) var elements = document.getElementsClassName("reveal");
Answer
Answer: a [Reason:] The above code snippet finds all container elements with class “reveal”.
8. What is the code snippet to update the content of the timestamp element when the user clicks on it?
a) timestamp.onLoad = function() { this.innerHTML = new Date().toString(); } b) timestamp.onclick = function() { this.innerHTML = new Date().toString(); } c) timestamp.onload = function() { this.innerHTML = new Date().toString(); } d) timestamp.onclick = function() { innerHTML = new Date().toString(); }
Answer
Answer: b [Reason:] The above code snippet updates the content of the timestamp element when the user clicks on it.
9. Which of the following is not an object?
a) Element
b) Location
c) Position
d) Window
Answer
Answer: c [Reason:] There is no object called Position.
10. What is the code snippet to change the class and let the stylesheet specify the details?
a) timestamp.className = "highlight"; b) timestamp.className = "change"; c) timestamp.className = "specify"; d) timestamp.className = "move";
Answer
Answer: a [Reason:] The above code snippet changes the class and lets the stylesheet specify the details.