Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

151.

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» Correct option is (b) N

Easy explanation: N is used for Number.
152.

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» Correct option is (d) Foo object

To explain: Class.forName(“myreflection.Foo”) returns the class object of Foo and getInstance() would return a new object.
153.

What is the return type of lambda expression?(a) String(b) Object(c) void(d) Function

Answer» Correct answer is (d) Function

To explain: Lambda expression enables us to pass functionality as an argument to another method, such as what action should be taken when someone clicks a button.
154.

Which of these occupy first  0 to 127 in Unicode character set used for characters in Java?(a) ASCII(b) ISO-LATIN-1(c) None of the mentioned(d) ASCII and ISO-LATIN1

Answer» The correct option is (d) ASCII and ISO-LATIN1

To explain: First 0 to 127 character set in Unicode are same as those of ISO-LATIN-1 and ASCII.
155.

String in Java is a?(a) class(b) object(c) variable(d) character array

Answer» Correct answer is (a) class

The explanation: None.
156.

What does public int end(int group) return?(a) offset from last character of the subsequent group(b) offset from first character of the subsequent group(c) offset from last character matched(d) offset from first character matched

Answer» Correct option is (a) offset from last character of the subsequent group

To elaborate: public int end(int group) returns offset from the last character of the subsequent group.
157.

Which of the following matches end of the string using regular expression in java?(a) z(b) \(c) *(d)

Answer» Correct answer is (a) z

Explanation: z is used to match end of the entire string in regular expression in java.
158.

Which of the following matches nonword character using regular expression in java?(a) w(b) W(c) s(d) S

Answer» Right answer is (b) W

The explanation is: W matches nonword characters. [0-9], [A-Z] and _ (underscore) are word characters. All other than these characters are nonword characters.
159.

Which of the below is true about java class structure?(a) The class name should start with lowercase(b) The class should have thousands of lines of code(c) The class should only contain those attribute and functionality  which it should; hence keeping it short(d) The class attributes and methods should be public

Answer» Right option is (c) The class should only contain those attribute and functionality  which it should; hence keeping it short

For explanation I would say: Class name should always start with upper case and contain those attribute and functionality which it should (Single Responsibility Principle); hence keeping it short. The attributes should be usually private with get and set methods.
160.

Which of these formatting strings of SimpleDateFormat class is used to print AM or PM in time?(a) a(b) b(c) c(d) d

Answer» Right answer is (a) a

Easiest explanation: By using format string “a” we can print AM/PM in time.
161.

What is the significance of Matcher class for regular expression in java?(a) interpretes pattern in the string(b) Performs match in the string(c) interpreted both pattern and performs match operations in the string(d) None of the mentioned.

Answer» The correct answer is (c) interpreted both pattern and performs match operations in the string

Easiest explanation: macther() method is invoked using matcher object which interpretes pattern and performs match operations in the input string.
162.

Which of the following is not a class of java.util.regex?(a) Pattern class(b) matcher class(c) PatternSyntaxException(d) Regex class

Answer» Correct answer is (d) Regex class

Explanation: java.util.regex consists 3 classes. PatternSyntaxException indicates syntax error in regex.
163.

How can we move from one desired step to another step?(a) breakpoints(b) System.out.println(c) logger.log(d) logger.error

Answer» The correct answer is (a) breakpoints

For explanation: Breakpoints are inserted in code. We can move from one point to another in the execution of a program.
164.

Which part stores the program arguments and startup parameters?(a) debug configuration(b) run configuration(c) launch configuration(d) project configuration

Answer» The correct choice is (c) launch configuration

The explanation is: Launch configuration stores the startup class, program arguments and vm arguments.
165.

Which of these methods can randomize all elements in a list?(a) rand()(b) randomize()(c) shuffle()(d) ambiguous()

Answer» Right answer is (c) shuffle()

Easy explanation: shuffle – randomizes all the elements in a list.
166.

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» Right answer is (a) Files.copy(source, target)

The explanation is: Files.copy(source, target) is used to copy a file from one location to another. There are various options available like REPLACE_EXISTING, COPY_ATTRIBUTES and NOFOLLOW_LINKS.
167.

While finding the correct location for saving key value pair, how many times the key is hashed?(a) 1(b) 2(c) 3(d) unlimited till bucket is found

Answer» The correct choice is (b) 2

Explanation: The key is hashed twice; first by hashCode() of Object class and then by internal hashing method of HashMap class.
168.

Which of these methods is used to notify observer the change in observed object?(a) update()(b) notify()(c) check()(d) observed()

Answer» Right choice is (a) update()

The best explanation: None.
169.

Which of these is the method which is executed first before execution of any other thing takes place in a program?(a) main method(b) finalize method(c) static method(d) private method

Answer» Right answer is (c) static method

For explanation I would say: If a static method is present in the program then it will be executed first, then main will be executed.
170.

What is the premise of equality for IdentityHashMap?(a) Reference equality(b) Name equality(c) Hashcode equality(d) Length equality

Answer» Right option is (a) Reference equality

The explanation is: IdentityHashMap is rarely used as it violates the basic contract of implementing equals() and hashcode() method.
171.

What happens if we put a key object in a HashMap which exists?(a) The new object replaces the older object(b) The new object is discarded(c) The old object is removed from the map(d) It throws an exception as the key already exists in the map

Answer» Correct answer is (a) The new object replaces the older object

To explain I would say: HashMap always contains unique keys. If same key is inserted again, the new object replaces the previous object.
172.

If two threads access the same hashmap at the same time, what would happen?(a) ConcurrentModificationException(b) NullPointerException(c) ClassNotFoundException(d) RuntimeException

Answer» Right option is (a) ConcurrentModificationException

The best I can explain: The code will throw ConcurrentModificationException if two threads access the same hashmap at the same time.
173.

Which key helps to step out of the caller of currently executed method?(a) F3(b) F5(c) F7(d) F8

Answer» Correct choice is (c) F7

To elaborate: F7 steps out to the caller of the currently executed method. This finishes the execution of the current method and returns to the caller of this method.
174.

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» Right option is (d) They cannot be run automatically

Easy explanation: JUnits test can be run automatically and they check their own results and provide immediate feedback.
175.

JUnits are used for which type of testing?(a) Unit Testing(b) Integration Testing(c) System Testing(d) Blackbox Testing

Answer» The correct option is (a) Unit Testing

For explanation I would say: JUnit is a testing framework for unit testing. It uses java as a programming platform. It is managed by junit.org community.
176.

Using which annotation non visible or private method can be tested?(a) @VisibleForTesting(b) @NonVisibleForTesting(c) @Visible(d) @NonVisible

Answer» Right choice is (a) @VisibleForTesting

The explanation: Using @VisibleForTesting annotation private or non visible method can be tested.
177.

Which one of the following is not an annotation used by Junit with Junit4?(a) @Test(b) @BeforeClass(c) @AfterClass(d) @Ignored

Answer» Correct answer is (d) @Ignored

Explanation: @Test, @Before, @BeforeClass, @After, @AfterClass and @Ignores are the annotations used by Junit with Junit4.
178.

Which of the following is a method having same name as that of its class?(a) finalize(b) delete(c) class(d) constructor

Answer» The correct choice is (d) constructor

The explanation: A constructor is a method that initializes an object immediately upon creation. It has the same name as that of class in which it resides.
179.

Which one of the following is not ID generating strategy using @GeneratedValue annotation?(a) Auto(b) Manual(c) Identity(d) Sequence

Answer» The correct choice is (b) Manual

For explanation: Auto, Table, Identity and Sequence are the ID generating strategies using @GeneratedValue annotation.
180.

What is the worst case complexity of accessing an element in ArrayList?(a) O(n)(b) O(1)(c) O(nlogn)(d) O(2)

Answer» Right option is (b) O(1)

To explain I would say: ArrayList has O(1) complexity for accessing an element in ArrayList. O(n) is the complexity for accessing an element from LinkedList.
181.

What is used to get class name in reflection?(a) getClass().getName()(b) getClass().getFields()(c) getClass().getDeclaredFields()(d) new getClass()

Answer» Right answer is (a) getClass().getName()

Explanation: getClass().getName() is used to get a class name from object in reflection.
182.

What is the default clone of HashSet?(a) Deep clone(b) Shallow clone(c) Plain clone(d) Hollow clone

Answer» The correct option is (b) Shallow clone

Explanation: Default clone() method uses shallow copy. The internal elements are not cloned. A shallow copy only copies the reference object.
183.

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» The correct answer is (c) obj.getClass().getMethod()

For explanation: obj.getClass().getMethod is used to invoke a method on unknown object obj.
184.

How can we connect to database in a web application?(a) oracle sql developer(b) toad(c) JDBC template(d) mysql

Answer» Correct option is (c) JDBC template

Easy explanation: JDBC template can be used to connect to database and fire queries against it.
185.

“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» The correct choice is (d) javax.servlet.jsp.JspWriter

Explanation: JspWriter object is referenced by the implicit variable out which is initialized automatically using methods in the PageContext object.
186.

Which keyword is used by the method to refer to the object that invoked it?(a) import(b) catch(c) abstract(d) this

Answer» The correct answer is (d) this

The best I can explain: this keyword can be used inside any method to refer to the current object. this is always a reference to the object on which the method was invoked.
187.

Which attribute uniquely identification element?(a) ID(b) Class(c) Name(d) Scope

Answer» Right option is (a) ID

The explanation is: ID attribute is used to uniquely identify action element.
188.

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» Right option is (b) It provides lifecycle management

The explanation is: Ant doesn’t provide lifecycle management. Maven provides lifecycle.
189.

Which of the following is not pre defined annotation in Java?(a) @Deprecated(b) @Overriden(c) @SafeVarags(d) @FunctionInterface

Answer» The correct answer is (b) @Overriden

The best explanation: @Overriden is not a pre defined annotation in Java. @Depricated, @Override, @SuppressWarnings, @SafeVarags and @FunctionInterface are the pre defined annotations.
190.

What requires less resources?(a) Thread(b) Process(c) Thread and Process(d) Neither Thread nor Process

Answer» Right answer is (a) Thread

Best explanation: Thread is a lightweight and requires less resources to create and exist in the process. Thread shares the process resources.
191.

Which of these methods can be used to delete the last element in a LinkedList object?(a) remove()(b) delete()(c) removeLast()(d) deleteLast()

Answer» Correct answer is (c) removeLast()

For explanation I would say: removeLast() and removeFirst() methods are used to remove elements in end and beginning of a linked list.
192.

Which of the following methods is used to avoid serialization of new class whose super class already implements Serialization?(a) writeObject()(b) readWriteObject()(c) writeReadObject()(d) unSerializaedObject()

Answer» Correct answer is (a) writeObject()

Explanation: writeObject() and readObject() methods should be implemented to avoid Java serialization.
193.

Which file separator should be used by MANIFEST file?(a) /(b)(c) –(d) //

Answer» Correct option is (a) /

The best I can explain: MANIFEST file uses classes using / file separator.
194.

How can we remove an object from ArrayList?(a) remove() method(b) using Iterator(c) remove() method and using Iterator(d) delete() method

Answer» The correct option is (c) remove() method and using Iterator

The best explanation: There are 2 ways to remove an object from ArrayList. We can use overloaded method remove(int index) or remove(Object obj). We can also use an Iterator to remove the object.
195.

What should not be done to avoid deadlock?(a) Avoid using multiple threads(b) Avoid hold several locks at once(c) Execute foreign code while holding a lock(d) Use interruptible locks

Answer» Correct choice is (c) Execute foreign code while holding a lock

The best explanation: To avoid deadlock situation in Java programming do not execute foreign code while holding a lock.
196.

What is true about time slicing?(a) Time slicing is OS service that allocates CPU time to available runnable thread(b) Time slicing is the process to divide the available CPU time to available runnable thread(c) Time slicing depends on its implementation in OS(d) Time slicing allocates more resources to thread

Answer» The correct answer is (b) Time slicing is the process to divide the available CPU time to available runnable thread

To explain: Time slicing is the process to divide the available CPU time to available runnable thread.
197.

Which of the following is not a feature of Beans?(a) Introspection(b) Events(c) Persistence(d) Serialization

Answer» Correct choice is (d) Serialization

Best explanation: Serialization is not the feature of Java Beans. Introspection, Customization, Events, Properties and Persistence are the features.
198.

Which of the following is not true about Java beans?(a) Implements java.io.Serializable interface(b) Extends java.io.Serializable class(c) Provides no argument constructor(d) Provides setter and getter methods for its properties

Answer» Right choice is (b) Extends java.io.Serializable class

Best explanation: java.io.Serializable is not a class. Instead it is an interface. Hence it cannot be extended.
199.

Which of these is wildcard symbol?(a) ?(b) !(c) %(d) &

Answer» The correct choice is (a) ?

To elaborate: In generic code, the question mark (?), called the wildcard, represents an unknown type.
200.

What does not prevent JVM from terminating?(a) Process(b) Daemon Thread(c) User Thread(d) JVM Thread

Answer» Right option is (b) Daemon Thread

For explanation: Daemon thread runs in the background and does not prevent JVM from terminating. Child of daemon thread is also daemon thread.