Java Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Java Programming MCQ (Multiple Choice Questions)

 Que-  Which one of the following is correct for directive in JSP?

a. <%@directive%>

b. <%!directive%>

c. <%directive%>

d. <%=directive%>


Answer- <%@directive%>


Que-  Which of the following action variable is used to include a file in JSP?

a. jsp:setProperty

b. jsp:getProperty

c. jsp:include

d. jsp:plugin


Answer- jsp:include


Que-  Which attribute uniquely identification element?

a. ID

b. Class

c. Name

d. Scope


Answer- ID


Que-  "out" is implicit object of which class?

a. javax.servlet.jsp.PrintWriter

b. javax.servlet.jsp.SessionWriter

c. javax.servlet.jsp.SessionPrinter

d. javax.servlet.jsp.JspWriter


Answer- javax.servlet.jsp.JspWriter


Que-  Which object stores references to the request and response objects?

a. sessionContext

b. pageContext

c. HttpSession

d. sessionAttribute


Answer- pageContext


Que-  What temporarily redirects response to the browser?

a. <jsp:forward>

b. <%@directive%>

c. response.sendRedirect(URL)

d. response.setRedirect(URL)


Answer- response.sendRedirect(URL)


Que-  Which tag is used to set a value of a JavaBean?

a. <c:set>

b. <c:param>

c. <c:choose>

d. <c:forward>


Answer- <c:set>


Que-  Can <!–comment–> and <%–comment–%> be used alternatively in JSP?

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-FALSE


Que-  Java code is embedded under which tag in JSP?

a. Declaration

b. Scriptlet

c. Expression

d. Comment


Answer- Scriptlet


Que-  Which of the following is not a directive in JSP?

a. page directive

b. include directive

c. taglib directive

d. command directive


Answer- command directive


Que-  What are the components of a marker interface?

a. Fields and methods

b. No fields, only methods

c. Fields, no methods

d. No fields, No methods


Answer- No fields, No methods


Que-  Which of the following is not a marker interface?

a. Serializable

b. Cloneable

c. Remote

d. Reader


Answer- Reader


Que-  What is not the advantage of Reflection?

a. Examine a class's field and method at runtime

b. Construct an object for a class at runtime

c. Examine a class's field at compile time

d. Examine an object's class at runtime


Answer- Examine a class's field at compile time


Que-  How private method can be called using reflection?

a. getDeclaredFields

b. getDeclaredMethods

c. getMethods

d. getFields


Answer- getDeclaredMethods


Que-  How private field can be called using reflection?

a. getDeclaredFields

b. getDeclaredMethods

c. getMethods

d. getFields


Answer- getDeclaredFields


Que-  What is used to get class name in reflection?

a. getClass().getName()

b. getClass().getFields()

c. getClass().getDeclaredFields()

d. new getClass()


Answer- getClass().getName()


Que-  How method can be invoked on unknown object?

a. obj.getClass().getDeclaredMethod()

b. obj.getClass().getDeclaredField()

c. obj.getClass().getMethod()

d. obj.getClass().getObject()


Answer- obj.getClass().getMethod()


Que-  How to get the class object of associated class using Reflection?

a. Class.forName("className")

b. Class.name("className")

c. className.getClass()

d. className.getClassName()


Answer- Class.forName("className")


Que-  What does Class.forName("myreflection.Foo").getInstance() return?

a. An array of Foo objects

b. class object of Foo

c. Calls the getInstance() method of Foo class

d. Foo object


Answer- Foo object


Que-  What does foo.getClass().getMethod("doSomething", null) return?

a. doSomething method instance

b. Method is returned and we can call the method as method.invoke(foo,null);

c. Class object

d. Exception is thrown


Answer- Method is returned and we can call the method as method.invoke(foo,null);


Que-  Autocloseable was introduced in which Java version?

a. java SE 7

b. java SE 8

c. java SE 6

d. java SE 4


Answer- java SE 7


Que-  What is the alternative of using finally to close resource?

a. catch block

b. autocloseable interface to be implemented

c. try block

d. throw Exception


Answer- autocloseable interface to be implemented


Que-  Which of the below is a child interface of Autocloseable?

a. Closeable

b. Close

c. Auto

d. Cloneable


Answer- Closeable


Que-  It is a good practise to not throw which exception in close() method of autocloseable?

a. IOException

b. CustomException

c. InterruptedException

d. CloseException


Answer- InterruptedException


Que-  What is the difference between AutoCloseable and Closeable?

a. Closeable is an interface 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- Closeable throws IOException; AutoCloseable throws Exception


Que-  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- Flushes this stream by writing any buffered output to the underlying stream


Que-  Which version of java added Flushable interface?

a. java SE 7

b. java SE 8

c. java SE 6

d. java SE 5


Answer- java SE 5


Que-  Does close() implicitly flush() the stream.

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-TRUE


Que-  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- Autocloseable java.lang; Flushable java.io


Que-  Which of below is not a dependency management tool?

a. Ant

b. Maven

c. Gradle

d. Jenkins


Answer- Jenkins


Que-  Which of the following is not a maven goal?

a. clean

b. package

c. install

d. debug


Answer- debug


Que-  Which file is used to define dependency in maven?

a. build.xml

b. pom.xml

c. dependency.xml

d. version.xml


Answer- pom.xml


Que-  Which file is used to specify the packaging cycle?

a. build.xml

b. pom.xml

c. dependency.xml

d. version.xml


Answer- build.xml


Que-  Which environment variable is used to specify the path to maven?

a. JAVA_HOME

b. PATH

c. MAVEN_HOME

d. CLASSPATH


Answer- MAVEN_HOME


Que-  Which of the below is a source code management tool?

a. Jenkins

b. Maven

c. Git

d. Hudson


Answer- Git


Que-  Can we run Junits as a part of Jenkins job?

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-TRUE


Que-  Which command can be used to check maven version?

a. mvn -ver

b. maven -ver

c. maven -version

d. mvn -version


Answer- mvn -version


Que-  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 doesn't have formal conventions


Answer- It provides lifecycle management


Que-  Which maven plugin creates the project structure?

a. dependency

b. properties

c. archetype

d. execution


Answer- archetype


Que-  Which version of Java introduced annotation?

a. Java 5

b. Java 6

c. Java 7

d. Java 8


Answer- Java 5


Que-  Annotation type definition looks similar to which of the following?

a. Method

b. Class

c. Interface

d. Field


Answer- Interface


Que-  Which of the following is not pre defined annotation in Java?

a. @Deprecated

b. @Overriden

c. @SafeVarags

d. @FunctionInterface


Answer- @Overriden


Que-  Annotations which are applied to other annotations are called meta annotations.

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-TRUE


Que-  Which one of the following annotations is not used in Hibernate?

a. @Entity

b. @Column

c. @Basic

d. @Query


Answer- @Query


Que-  Which one of the following is not ID generating strategy using @GeneratedValue annotation?

a. Auto

b. Manual

c. Identity

d. Sequence


Answer- Manual


Que-  Which one of the following is not an annotation used by Junit with Junit4?

a. @Test

b. @BeforeClass

c. @AfterClass

d. @Ignored


Answer- @Ignored


Que-  Using which annotation non visible or private method can be tested?

a. @VisibleForTesting

b. @NonVisibleForTesting

c. @Visible

d. @NonVisible


Answer- @VisibleForTesting


Que-  Which of the following annotation is used to avoid execution of Junits?

a. @NoTest

b. @explicit

c. @avoid

d. @ignore


Answer- @ignore


Que-  Which is the Parent class of annotation class?

a. Class

b. Object

c. Main

d. Super


Answer- Object

Previous Post Next Post