Java Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Java Programming MCQ (Multiple Choice Questions)

 Que-  Which of these class allows us to get real time data about private and protected member of a class?

a. java.io

b. GetInformation

c. ReflectPermission

d. MembersPermission


Answer- ReflectPermission


Que-  Which of this package is used for invoking a method remotely?

a. java.rmi

b. java.awt

c. java.util

d. java.applet


Answer- java.rmi


Que-  Why are generics used?

a. Generics make code more fast

b. Generics make code more optimised and readable

c. Generics add stability to your code by making more of your bugs detectable at compile time

d. Generics add stability to your code by making more of your bugs detectable at runtime


Answer- Generics add stability to your code by making more of your bugs detectable at compile time


Que-  Which of these type parameters is used for a generic class to return and accept any type of object?

a. K

b. N

c. T

d. V


Answer- T


Que-  Which of these type parameters is used for a generic class to return and accept a number?

a. K

b. N

c. T

d. V


Answer- N


Que-  Which of these is an correct way of defining generic class?

a. class name(T1, T2, …, Tn) { /* … */ }

b. class name<T1, T2, …, Tn> { /* … */ }

c. class name[T1, T2, …, Tn] { /* … */ }

d. class name{T1, T2, …, Tn} { /* … */ }


Answer- class name<T1, T2, …, Tn> { /* … */ }


Que-  Which of the following is an incorrect statement regarding the use of generics and parameterized types in Java?

a. Generics provide type safety by shifting more type checking responsibilities to the compiler

b. Generics and parameterized types eliminate the need for down casts when using Java Collections

c. When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes

d. All of the mentioned


Answer- When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes


Que-  Which of the following reference types cannot be generic?

a. Anonymous inner class

b. Interface

c. Inner class

d. All of the mentioned


Answer- Anonymous inner class


Que-  JUnits are used for which type of testing?

a. Unit Testing

b. Integration Testing

c. System Testing

d. Blackbox Testing


Answer- Unit Testing


Que-  Which of the below statement about JUnit is false?

a. It is an open source framework

b. It provides an annotation to identify test methods

c. It provides test runners for running test

d. They cannot be run automatically


Answer- They cannot be run automatically


Que-  Which of the below is an incorrect annotation with respect to JUnits?

a. @Test

b. @BeforeClass

c. @Junit

d. @AfterEach


Answer- @Junit


Que-  Which of these is not a mocking framework?

a. EasyMock

b. Mockito

c. PowerMock

d. MockJava


Answer- MockJava


Que-  Which method is used to verify the actual and expected results in Junits?

a. assert()

b. equals()

c. ==

d. isEqual()


Answer- assert()


Que-  What does assertSame() method use for assertion?

a. equals() method

b. isEqual() method

c. ==

d. compare() method


Answer- ==


Que-  How to let junits know that they need to be run using PowerMock?

a. @PowerMock

b. @RunWith(PowerMock)

c. @RunWith(Junits)

d. @RunWith(PowerMockRunner.class)


Answer- @RunWith(PowerMockRunner.class)


Que-  How can we simulate if then behavior in Junits?

a. if{..} else{..}

b. if(..){..} else{..}

c. Mockito.when(…).thenReturn(…);

d. Mockito.if(..).then(..);


Answer- Mockito.when(…).thenReturn(…);


Que-  What is used to inject mock fields into the tested object automatically?

a. @InjectMocks

b. @Inject

c. @InjectMockObject

d. @Mock


Answer- @InjectMocks


Que-  Which of the following is not introduced with Java 8?

a. Stream API

b. Serialization

c. Spliterator

d. Lambda Expression


Answer- Serialization


Que-  What is the purpose of BooleanSupplier function interface?

a. represents supplier of Boolean-valued results

b. returns Boolean-valued result

c. There is no such function interface

d. returns null if Boolean is passed as argument


Answer- represents supplier of Boolean-valued results


Que-  What is the return type of lambda expression?

a. String

b. Object

c. void

d. Function


Answer- Function


Que-  Which is the new method introduced in java 8 to iterate over a collection?

a. for (String i : StringList)

b. foreach (String i : StringList)

c. StringList.forEach()

d. List.for()


Answer- StringList.forEach()


Que-  What are the two types of Streams offered by java 8?

a. sequential and parallel

b. sequential and random

c. parallel and random

d. random and synchronized


Answer- sequential and parallel


Que-  Which feature of java 8 enables us to create a work stealing thread pool using all available processors at its target?

a. workPool

b. newWorkStealingPool

c. threadPool

d. workThreadPool


Answer- newWorkStealingPool


Que-  What does Files.lines(Path path) do?

a. It reads all the files at the path specified as a String

b. It reads all the lines from a file as a Stream

c. It reads the filenames at the path specified

d. It counts the number of lines for files at the path specified


Answer- It reads all the lines from a file as a Stream


Que-  What is Optional object used for?

a. Optional is used for optional runtime argument

b. Optional is used for optional spring profile

c. Optional is used to represent null with absent value

d. Optional means it's not mandatory for method to return object


Answer- Optional is used to represent null with absent value


Que-  What is the substitute of Rhino javascript engine in Java 8?

a. Nashorn

b. V8

c. Inscript

d. Narcissus


Answer- Nashorn


Que-  What does SAM stand for in the context of Functional Interface?

a. Single Ambivalue Method

b. Single Abstract Method

c. Simple Active Markup

d. Simple Abstract Markup


Answer- Single Abstract Method


Que-  Which method is used to create a directory with fileattributes?

a. Path.create()

b. Path.createDirectory()

c. Files.createDirectory(path, fileAttributes)

d. Files.create(fileAttributes)


Answer- Files.createDirectory(path, fileAttributes)


Que-  Which method can be used to check fileAccessiblity?

a. isReadable(path)

b. isWritable(path)

c. isExecutable(path)

d. isReadable(path), isWritable(path), and isExecutable(path)


Answer- isReadable(path), isWritable(path), and isExecutable(path)


Que-  How can we delete all files in a directory?

a. Files.delete(path)

b. Files.deleteDir()

c. Directory.delete()

d. Directory.delete(path)


Answer- Files.delete(path)


Que-  How to copy the file from one location to other?

a. Files.copy(source, target)

b. Path.copy(source, target)

c. source.copy(target)

d. Files.createCopy(target)


Answer- Files.copy(source, target)


Que-  How can we get the size of specified file?

a. capacity(path)

b. size(path)

c. length(path)

d. Path.size()


Answer- size(path)


Que-  How to read entire file in one line using java 8?

a. Files.readAllLines()

b. Files.read()

c. Files.readFile()

d. Files.lines()


Answer- Files.readAllLines()


Que-  How can we create a symbolic link to file?

a. createLink()

b. createSymLink()

c. createSymbolicLink()

d. createTempLink()


Answer- createSymbolicLink()


Que-  How can we filter lines based on content?

a. lines.filter()

b. filter(lines)

c. lines.contains(filter)

d. lines.select()


Answer- lines.filter()


Que-  Which jar provides FileUtils which contains methods for file operations?

a. file

b. apache commons

c. file commons

d. dir


Answer- apache commons


Que-  Which feature of java 7 allows to not explicitly close IO resource?

a. try catch finally

b. IOException

c. AutoCloseable

d. Streams


Answer- AutoCloseable


Que-  Which of the following is not a core interface of Hibernate?

a. Configuration

b. Criteria

c. SessionManagement

d. Session


Answer- SessionManagement


Que-  SessionFactory is a thread-safe object.

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-TRUE


Que-  Which of the following methods returns proxy object?

a. loadDatabase()

b. getDatabase()

c. load()

d. get()


Answer- load()


Que-  Which of the following methods hits database always?

a. load()

b. loadDatabase()

c. getDatabase()

d. get()


Answer- get()


Que-  Which of the following method is used inside session only?

a. merge()

b. update()

c. end()

d. kill()


Answer- update()


Que-  Which of the following is not a state of object in Hibernate?

a. Attached()

b. Detached()

c. Persistent()

d. Transient()


Answer- Attached()


Que-  Which of the following is not an inheritance mapping strategies?

a. Table per hierarchy

b. Table per concrete class

c. Table per subclass

d. Table per class


Answer- Table per class

Previous Post Next Post