Java MCQ Set 1
1. What type of scooping is present in JavaScript?
a) Lexical
b) Literal
c) Both Lexical and Literal
d) None of the mentioned
Answer
Answer: a [Reason:] JavaScript supports lexical scooping that deals with functions instead of blocks.
2. Which function is used to stop the time logging?
a) stopTimeLogging()
b) stop()
c) finish()
d) abort()
Answer
Answer: a [Reason:] The function stopTimeLogging() is used to stop the time logging.
3. The lexical scooping in JavaScript is based on which of the following?
a) Segments
b) Blocks
c) Functions
d) Entire code
Answer
Answer: c [Reason:] JavaScript has lexical scoping based on functions but not blocks.
4. What is the return data type of the property accept that belongs to the Input element?
a) integer
b) string
c) boolean
d) float
Answer
Answer: b [Reason:] When type is “file”, this property is a comma-separated list of MIME types that specify the types of files that may be selected. The strings “audio/*”, “video/*”, and “image/*” are also legal. Mirrors the accept attribute.
5. What is the purpose of the property width belonging to the ImageData element?
a) Number of data
b) Number of pixels
c) Number of pixels per row of data
d) All of the mentioned
Answer
Answer: c [Reason:] The width property is used to retrieve or store the number of pixels per row of data.
6. What is the purpose of the adoptNode() method?
a) Removes node
b) Makes it ready for insertion
c) Removes node and Makes it ready for insertion
d) None of the mentioned
Answer
Answer: c [Reason:] This method removes node from whatever document it is currently part of and changes its ownerDocument property to this document, making it ready for insertion into this document.
7. What is the function of the method importNode()?
a) Copies without removing
b) Copies and removes
c) Only copies
d) Only removes
Answer
Answer: a [Reason:] The method importNode() copies a node from another document without removing it.
8. How can you create a node for comment in JavaScript?
a) comment()
b) createComment()
c) Comm()
d) None of the mentioned
Answer
Answer: b [Reason:] The comment node can be created using the method Comment createComment(string data).
9. How can you dispatch a synthetic event object?
a) dispatchEvent()
b) dispatch()
c) dispatch(Event)
d) None of the mentioned
Answer
Answer: a [Reason:] When you have created and initialized an synthetic event object, you can dispatch it using the dispatchEvent() method of EventTarget.
10. How do you specifically execute a command in JavaScript?
a) execcommand()
b) exec(command)
c) execCommand()
d) exec(command id)
Answer
Answer: c [Reason:] The command can be executed using boolean execCommand(string commandId, [boolean showUI, [string value]]).
Java MCQ Set 2
1. What is scorched-earth optimizations?
a) They optimize based on certain constraints
b) They strip out everything including best practices
c) Based on certain constraints
d) None of the mentioned
Answer
Answer: b [Reason:] Closure Compiler runs through a number of “scorched-earth” optimizations—it unfurls functions, rewrites variable names, and removes functions that are never called (as far as it can tell).
2. The Closure Compiler was introduced by
a) Microsoft
b) Apple
c) Google
d) None of the mentioned
Answer
Answer: c [Reason:] The Closure Compiler was introduced by Google.
3. What does the Minify return back to the Script tag?
a) File I/O
b) Minify JavaScript
c) HTTP Request
d) Gzip encoded
Answer
Answer: d [Reason:] The Minify sends back the gzip encoded back to the Script tag.
4. What is the return type of the script tag?
a) File I/O
b) Minify JavaScript
c) HTTP Request
d) Gzip encoded
Answer
Answer: c [Reason:] The script tag sends the HTTP Request to the Minify.
5. What does the JS File return ?
a) File I/O
b) Minify JavaScript
c) HTTP Request
d) Gzip encoded
Answer
Answer: b [Reason:] The JS File returns the Minify JavaScript.
6. What is the outcome of using R along with minification?
a) Sheer file size reduction
b) File size increase
c) More efficient
d) None of the mentioned
Answer
Answer: a [Reason:] Sheer file size reduction is the only one aspect of the overall determination got from the R along with the minification.
7. Which one of the following is more efficient in terms of the file size reduction?
a) YUI
b) Closure Compiler (advanced)
c) Minify
d) Closure Compiler (simple)
Answer
Answer: b [Reason:] The Closure Compiler (advanced) has a more number percent of file size reduction by product.
8. Which of the following are JavaScript optimizers?
a) JSMin
b) Packer
c) Minify
d) Both JSMin and Packer
Answer
Answer: d [Reason:] JavaScript optimizers such as JSMin and Packer are specially designed for modern web programming techniques, and are able to understand and preserve conditional comments, and similar.
9. Which of the following is the approach used to compress HTML in web servers and modern web browsers?
a) Content encoding
b) Content decoding
c) Compression algorithm – DEFLATE
d) None of the mentioned
Answer
Answer: a [Reason:] Content encoding is an approach taken by compatible web servers and modern web browsers to compress HTML and related textual content, often in the gzip format.
10. Which is the game that requires extremely minified source in the Perl culture?
a) Perl pool
b) Perl golf
c) Both Perl pool and golf
d) None of the mentioned
Answer
Answer: b [Reason:] In Perl culture, aiming at extremely minified source code is the purpose of the Perl golf game.
Java MCQ Set 3
1. Which version of Java introduced annotation?
a) Java 5
b) Java 6
c) Java 7
d) Java 8
Answer
Answer: a [Reason:] Annotation were introduced with Java 5 version.
2. Annotation type definition looks similar to which of the following?
a) Method
b) Class
c) Interface
d) Field
Answer
Answer: c [Reason:] Annotation type definition is similar to an interface definition in which the keyword interface is preceded by the sign @.
3. Which is the following is not pre defined annotation in Java?
a) @Deprecated
b) @Overriden
c) @SafeVarags
d) @FunctionInterface
Answer
Answer: b [Reason:] @Overriden is not a pre defined annotation in Java. @Depricated, @Override, @SuppressWarnings, @SafeVarags and @FunctionInterface are the pre defined annotations.
4. Annotations which are applied to other annotations are called meta annotations.
a) True
b) False
Answer
Answer: a [Reason:] Annotations which are applied to other annotations are called meta annotations.
5. Which one of the following annotations is not used in Hibernate?
a) @Entity
b) @Column
c) @Basic
d) @Query
Answer
Answer: d [Reason:] @Query is not an annotation used in Hibernate.
6. Which one of the following is not ID generating stratagy using @GeneratedValue annotation?
a) Auto
b) Manual
c) Identity
d) Sequence
Answer
Answer: b [Reason:] Auto, Table, Identity and Sequence are the ID generating stratagies using @GeneratedValue annotation.
7. Which one of the following is not an annotation used by Junit with Junit4?
a) @Test
b) @BeforeClass
c) @AfterClass
d) @Ignored
Answer
Answer: d [Reason:] @Test, @Before, @BeforeClass, @After, @AfterClass and @Ignores are the annotations used by Junit with Junit4.
8. Using which annotation non visible or private method can be tested?
a) @VisibleForTesting
b) @NonVisibleForTesting
c) @Visible
d) @NonVisible
Answer
Answer: a [Reason:] Using @VisibleForTesting annotation private or non visible method can be tested.
9. Which of the following annotation is used to avoid executation of Junits?
a) @NoTest
b) @explicit
c) @avoid
d) @ignore
Answer
Answer: d [Reason:] @ignore annotation is used to avoid executation of Junits.
10. Which is the Parent class of annotation class?
a) Class
b) Object
c) Main
d) Super
Answer
Answer: b [Reason:] Object is the parent class of annotation class.
Java MCQ Set 4
1. Which of below is not a dependency management tool?
a) Ant
b) Maven
c) Gradle
d) Jenkins
Answer
Answer: d [Reason:] Jenkins is continuous integration system. Ant, Maven, Gradle is used for build process.
2. Which of the following is not a maven goal?
a) clean
b) package
c) install
d) debug
Answer
Answer: d [Reason:] clean, package, install are maven goals. Debug is used finding and resolving of defects.
3. Which file is used to define dependency in maven?
a) build.xml
b) pom.xml
c) dependency.xml
d) version.xml
Answer
Answer: b [Reason:] pom.xml is used to define dependency which are used to package the jar. POM stands for project object model.
4. Which file is used to specify the packaging cycle?
a) build.xml
b) pom.xml
c) dependency.xml
d) version.xml
Answer
Answer: a [Reason:] Project structure is specified in build.xml.
5. Which environment variable is used to specify the path to maven?
a) JAVA_HOME
b) PATH
c) MAVEN_HOME
d) CLASSPATH
Answer
Answer: c [Reason:] MAVEN_HOME should be set to the bin folder of maven installation.
6. Which of the below is a source code management tool?
a) Jenkins
b) Maven
c) Git
d) Hudson
Answer
Answer: c [Reason:] Source code management tools help is version control, compare different versions of code, crash management, etc. Git, SVN are popular source code management tools.
7. Can we run Junits as a part of Jenkins job?
a) True
b) False
Answer
Answer: a [Reason:] As a part of jenkins job, we can run junits, fitnesse, test coverage reports, call shell or bat scripts, etc.
8. Which command can be used to check maven version?
a) mvn -ver
b) maven -ver
c) maven -version
d) mvn -version
Answer
Answer: d [Reason:] mvn -version can be used to check the version of installed maven from command prompt.
9. Which of the following is not true for Ant ?
a) It is a tool box
b) It provides lifecycle management
c) It is procedural
d) It doesnt have formal conventions
Answer
Answer: b [Reason:] Ant doesnt provide lifecycle management. Maven provides lifecycle.
10. Which maven plugin creates the project structure?
a) dependency
b) properties
c) archetype
d) execution
Answer
Answer: c [Reason:] Archetype is the maven plugin which creates the project structure.
Java MCQ Set 5
1. Autocloseable was introduced in which Java version?
a) java SE 7
b) java SE 8
c) java SE 6
d) java SE 4
Answer
Answer: a [Reason:] Java 7 introduced autocloseable iterface.
2. What is the alternate of using finally to close resource?
a) catch block
b) autocloseable interface to be implemented
c) try block
d) throw Exception
Answer
Answer: b [Reason:] Autocloseable interface provides close() method to close this resource and any other underlying resources.
3. Which of the below is a child interface of Autocloseable?
a) Closeable
b) Close
c) Auto
d) Cloneable
Answer
Answer: a [Reason:] A closeable interface extends autocloseable interface. A Closeable is a source or destination of data that can be closed.
4. It is a good practise to not throw which exception in close() method of autocloseable?
a) IOException
b) CustomException
c) InterruptedException
d) CloseException
Answer
Answer: c [Reason:] InterruptedException interacts with a thread’s interrupted status and runtime misbehavior is likely to occur if an InterruptedException is suppressed.
5. What is the output of below snippet?
-
try (InputStream is = ...)
-
{
-
// do stuff with is...
-
}
-
catch (IOException e)
-
{
-
// handle exception
-
}
a) Runtime Error
b) IOException
c) Compilation Error
d) Runs successfully
Answer
Answer: d [Reason:] Using java 7 and above, AutoCloseable objects can be opened in the try-block (within the ()) and will be automatically closed instead of using the finally block.
6. What is the difference between AutoCloseable and Closeable?
a) Closeable is an iterface and AutoCloseable is a concrete class
b) Closeable throws IOException; AutoCloseable throws Exception
c) Closeable is a concept; AutoCloseable is an implementation
d) Closeable throws Exception; AutoCloseable throws IOException
Answer
Answer: b [Reason:] Closeable extends AutoCloseable and both are interfaces. Closeable throws IOException and AutoCloseable throws Exception.
7. What is the use of Flushable interface?
a) Flushes this stream by writing any buffered output to the underlying stream
b) Flushes this stream and starts reading again
c) Flushes this connection and closes it
d) Flushes this stream and throws FlushException
Answer
Answer: a [Reason:] Flushable interface provides flush() method which Flushes this stream by writing any buffered output to the underlying stream.
8. Which version of java added Flushable interface?
a) java SE 7
b) java SE 8
c) java SE 6
d) java SE 5
Answer
Answer: d [Reason:] Flushable and Closeable interface are added in java SE 5.
9. Does close() implicitly flush() the stream?
a) True
b) False
Answer
Answer: a [Reason:] close() closes the stream but it flushes it first.
10. AutoCloseable and Flushable are part of which package?
a) Autocloseable java.lang; Flushable java.io
b) Autocloseable java.io; Flushable java.lang
c) Autocloseable and Flushable java.io
d) Autocloseable and Flushable java.lang
Answer
Answer: a [Reason:] Autocloseable is a part of java.lang; Flushable is a part of java.io.