InterviewSolution
Saved Bookmarks
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.
| 301. |
When destroy() method of a filter is called?(a) The destroy() method is called only once at the end of the life cycle of a filter(b) The destroy() method is called after the filter has executed doFilter method(c) The destroy() method is called only once at the begining of the life cycle of a filter(d) The destroyer() method is called after the filter has executed |
|
Answer» Right choice is (a) The destroy() method is called only once at the end of the life cycle of a filter Easiest explanation: destroy() is an end of life cycle method so it is called at the end of life cycle. |
|
| 302. |
Which file is used to specify the packaging cycle?(a) build.xml(b) pom.xml(c) dependency.xml(d) version.xml |
|
Answer» Correct answer is (a) build.xml Explanation: Project structure is specified in build.xml. |
|
| 303. |
Which attribute is used to specify initialization method?(a) init(b) init-method(c) initialization(d) initialization-method |
|
Answer» The correct choice is (b) init-method Best explanation: init-method is used to specify the initialization method. |
|
| 304. |
Which attribute is used to specify destroy method?(a) destroy(b) destroy-method(c) destruction(d) destruction-method |
|
Answer» Right option is (b) destroy-method Easy explanation: destroy-method is used to specify the destruction method. |
|
| 305. |
Which of the below is invalid identifier with the main method?(a) public(b) static(c) private(d) final |
|
Answer» Correct option is (c) private Easy explanation: main method cannot be private as it is invoked by external method. Other identifier are valid with main method. |
|
| 306. |
How is Date stored in database?(a) java.sql.Date(b) java.util.Date(c) java.sql.DateTime(d) java.util.DateTime |
|
Answer» The correct choice is (a) java.sql.Date Easy explanation: java.sql.Date is the datatype of Date stored in database. |
|
| 307. |
What would be the behaviour if this() and super() used in a method?(a) Runtime error(b) Throws exception(c) compile time error(d) Runs successfully |
|
Answer» Right answer is (c) compile time error The explanation: this() and super() cannot be used in a method. This throws compile time error. |
|
| 308. |
What is the extension of java code files?(a) .class(b) .java(c) .txt(d) .js |
|
Answer» The correct option is (b) .java For explanation: Java files have .java extension. |
|
| 309. |
Which of these methods of a Thread class is used to suspend a thread for a period of time?(a) sleep()(b) terminate()(c) suspend()(d) stop() |
|
Answer» Right option is (a) sleep() The best explanation: None. |
|
| 310. |
Which one of the following contains date information?(a) java.sql.TimeStamp(b) java.sql.Time(c) java.io.Time(d) java.io.TimeStamp |
|
Answer» Right answer is (a) java.sql.TimeStamp Best explanation: java.sql.Time contains only time. Whereas, java.sql.TimeStamp contains both time and date. |
|
| 311. |
What is true about private constructor?(a) Private constructor ensures only one instance of a class exist at any point of time(b) Private constructor ensures multiple instances of a class exist at any point of time(c) Private constructor eases the instantiation of a class(d) Private constructor allows creating objects in other classes |
|
Answer» The correct option is (a) Private constructor ensures only one instance of a class exist at any point of time For explanation: Object of private constructor can only be created within class. Private constructor is used in singleton pattern. |
|
| 312. |
Which of these is not abstract?(a) Thread(b) AbstractList(c) List(d) None of the Mentioned |
|
Answer» Correct choice is (a) Thread To explain I would say: Thread is not an abstract class. |
|
| 313. |
Which of the following is advantage of using PreparedStatement in Java?(a) Slow performance(b) Encourages SQL injection(c) Prevents SQL injection(d) More memory usage |
|
Answer» Correct choice is (c) Prevents SQL injection Easiest explanation: PreparedStatement in Java improves performance and also prevents from SQL injection. |
|
| 314. |
How private method can be called using reflection?(a) getDeclaredFields(b) getDeclaredMethods(c) getMethods(d) getFields |
|
Answer» Correct choice is (b) getDeclaredMethods Easiest explanation: getDeclaredMethods gives instance of java.lang.reflect.Method. |
|
| 315. |
Which of this interface is implemented by Thread class?(a) Runnable(b) Connections(c) Set(d) MapConnections |
|
Answer» Right answer is (a) Runnable The explanation is: None. |
|
| 316. |
What is the extension of compiled java classes?(a) .class(b) .java(c) .txt(d) .js |
|
Answer» Correct answer is (a) .class For explanation I would say: The compiled java files have .class extension. |
|
| 317. |
Which of these keywords are used to define an abstract class?(a) abst(b) abstract(c) Abstract(d) abstract class |
|
Answer» The correct answer is (b) abstract The best I can explain: None. |
|
| 318. |
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» The correct option is (b) Closeable throws IOException; AutoCloseable throws Exception Explanation: Closeable extends AutoCloseable and both are interfaces. Closeable throws IOException and AutoCloseable throws Exception. |
|
| 319. |
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» Right choice is (c) Examine a class’s field at compile time Explanation: Reflection inspects classes, interfaces, fields and methods at a runtime. |
|
| 320. |
How can we identify whether a compilation unit is class or interface from a .class file?(a) Java source file header(b) Extension of compilation unit(c) We cannot differentiate between class and interface(d) The class or interface name should be postfixed with unit type |
|
Answer» Right choice is (a) Java source file header Explanation: The Java source file contains a header that declares the type of class or interface, its visibility with respect to other classes, its name and any superclass it may extend, or interface it implements. |
|
| 321. |
Which of these interface handle sequences?(a) Set(b) List(c) Comparator(d) Collection |
|
Answer» Right choice is (b) List To explain: None. |
|
| 322. |
Which of the following is not a marker interface?(a) Serializable(b) Cloneable(c) Remote(d) Reader |
|
Answer» Right choice is (d) Reader The best explanation: Reader is not a marker interface. Serializable, Cloneable and Remote interfaces are marker interface. |
|
| 323. |
Which of the below is a child interface of Autocloseable?(a) Closeable(b) Close(c) Auto(d) Cloneable |
|
Answer» Right answer is (a) Closeable For explanation I would say: A closeable interface extends autocloseable interface. A Closeable is a source or destination of data that can be closed. |
|
| 324. |
Which of these keywords is used to make a class?(a) class(b) struct(c) int(d) none of the mentioned |
|
Answer» The correct choice is (a) class Easy explanation: None. |
|
| 325. |
Which of these is a Basic interface that all other interface inherits?(a) Set(b) Array(c) List(d) Collection |
|
Answer» The correct option is (d) Collection For explanation I would say: Collection interface is inherited by all other interfaces like Set, Array, Map etc. It defines core methods that all the collections like set, map, arrays etc will have |
|
| 326. |
What is JVM?(a) Bootstrap(b) Interpreter(c) Extension(d) Compiler |
|
Answer» Right option is (b) Interpreter Best explanation: JVM is Interpreter. It reads .class files which is the byte code generated by compiler line by line and converts it into native OS code. |
|
| 327. |
What is -Xms and -Xmx while starting jvm?(a) Initial; Maximum memory(b) Maximum; Initial memory(c) Maximum memory(d) Initial memory |
|
Answer» Correct option is (a) Initial; Maximum memory The best explanation: JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. java -Xmx2048m -Xms256m. |
|
| 328. |
Which of these keywords can be used to prevent inheritance of a class?(a) super(b) constant(c) class(d) final |
|
Answer» The correct choice is (d) final For explanation I would say: Declaring a class final implicitly declared all of its methods final, and makes the class inheritable. |
|
| 329. |
Which of these keywords is used to prevent content of a variable from being modified?(a) final(b) last(c) constant(d) static |
|
Answer» Correct choice is (a) final Easiest explanation: A variable can be declared final, doing so prevents its content from being modified. Final variables must be initialized when it is declared. |
|
| 330. |
Which of these standard collection classes implements a linked list data structure?(a) AbstractList(b) LinkedList(c) HashSet(d) AbstractSet |
|
Answer» Correct choice is (b) LinkedList Best explanation: None. |
|
| 331. |
What is the difference between TreeSet and SortedSet?(a) TreeSet is more efficient than SortedSet(b) SortedSet is more efficient than TreeSet(c) TreeSet is an interface; SortedSet is a concrete class(d) SortedSet is an interface; TreeSet is a concrete class |
|
Answer» The correct answer is (d) SortedSet is an interface; TreeSet is a concrete class Explanation: SortedSet is an interface. It maintains an ordered set of elements. TreeSet is an implementation of SortedSet. |
|
| 332. |
Which of these is an incorrect form of using method max() to obtain a maximum element?(a) max(Collection c)(b) max(Collection c, Comparator comp)(c) max(Comparator comp)(d) max(List c) |
|
Answer» The correct choice is (c) max(Comparator comp) To explain: Its illegal to call max() only with comparator, we need to give the collection to be searched into. |
|
| 333. |
What is deserialization?(a) Turning object in memory into stream of bytes(b) Turning stream of bytes into an object in memory(c) Turning object in memory into stream of bits(d) Turning stream of bits into an object in memory |
|
Answer» The correct choice is (b) Turning stream of bytes into an object in memory Explanation: Deserialization is the reverse process of serialization which is turning stream of bytes into an object in memory. |
|
| 334. |
What does Collections.emptySet() return?(a) Immutable Set(b) Mutable Set(c) The type of Set depends on the parameter passed to the emptySet() method(d) Null object |
|
Answer» Correct option is (a) Immutable Set To explain I would say: Immutable Set is useful in multithreaded environment. One does not need to declare generic type collection. It is inferred by the context of method call. |
|
| 335. |
When two threads access the same ArrayList object what is the outcome of the program?(a) Both are able to access the object(b) ConcurrentModificationException is thrown(c) One thread is able to access the object and second thread gets Null Pointer exception(d) One thread is able to access the object and second thread will wait till control is passed to the second one |
|
Answer» Right choice is (b) ConcurrentModificationException is thrown To explain I would say: ArrayList is not synchronized. Vector is the synchronized data structure. |
|
| 336. |
What happens if two threads simultaneously modify TreeSet?(a) ConcurrentModificationException is thrown(b) Both threads can perform action successfully(c) FailFastException is thrown(d) IteratorModificationException is thrown |
|
Answer» Correct choice is (a) ConcurrentModificationException is thrown Best explanation: TreeSet provides fail-fast iterator. Hence when concurrently modifying TreeSet it throws ConcurrentModificationException. |
|
| 337. |
Which of the following methods is not used while Serialization and DeSerialization?(a) readObject()(b) readExternal()(c) readWriteObject()(d) writeObject() |
|
Answer» The correct choice is (c) readWriteObject() Easy explanation: Using readObject(), writeObject(), readExternal() and writeExternal() methods Serialization and DeSerialization are implemented. |
|
| 338. |
Which of these method is used to add an element to the start of a LinkedList object?(a) add()(b) first()(c) AddFirst()(d) addFirst() |
|
Answer» The correct choice is (d) addFirst() To elaborate: None. |
|
| 339. |
Which of this method is used to change an element in a LinkedList Object?(a) change()(b) set()(c) redo()(d) add() |
|
Answer» The correct answer is (b) set() Easy explanation: An element in a LinkedList object can be changed by first using get() to obtain the index or location of that object and the passing that location to method set() along with its new value. |
|
| 340. |
What decides thread priority?(a) Process(b) Process scheduler(c) Thread(d) Thread scheduler |
|
Answer» The correct option is (d) Thread scheduler Explanation: Thread scheduler decides the priority of the thread execution. This cannot guarantee that higher priority thread will be executed first, it depends on thread scheduler implementation that is OS dependent. |
|
| 341. |
What will happen if two thread of the same priority are called to be processed simultaneously?(a) Anyone will be executed first lexographically(b) Both of them will be executed simultaneously(c) None of them will be executed(d) It is dependent on the operating system |
|
Answer» The correct answer is (d) It is dependent on the operating system The explanation: In cases where two or more thread with same priority are competing for CPU cycles, different operating system handle this situation differently. Some execute them in time sliced manner some depending on the thread they call. |
|
| 342. |
Which of these method waits for the thread to terminate?(a) sleep()(b) isAlive()(c) join()(d) stop() |
|
Answer» Correct answer is (c) join() For explanation I would say: None. |
|
| 343. |
Which of these method of HashSet class is used to add elements to its object?(a) add()(b) Add()(c) addFirst()(d) insert() |
|
Answer» The correct option is (a) add() For explanation: None. |
|
| 344. |
What are the initial capacity and load factor of HashSet?(a) 10, 1.0(b) 32, 0.75(c) 16, 0.75(d) 32, 1.0 |
|
Answer» Right answer is (c) 16, 0.75 For explanation I would say: We should not set the initial capacity too high and load factor too low if iteration performance is needed. |
|
| 345. |
Which of this method can be used to make the main thread to be executed last among all the threads?(a) stop()(b) sleep()(c) join()(d) call() |
|
Answer» Correct choice is (b) sleep() Explanation: By calling sleep() within main(), with long enough delay to ensure that all child threads terminate prior to the main thread. |
|
| 346. |
Which of these method of Object class can clone an object?(a) Objectcopy()(b) copy()(c) Object clone()(d) clone() |
|
Answer» The correct choice is (c) Object clone() The explanation: None. |
|
| 347. |
Which version of Java introduced annotation?(a) Java 5(b) Java 6(c) Java 7(d) Java 8 |
|
Answer» The correct answer is (a) Java 5 To explain I would say: Annotation were introduced with Java 5 version. |
|
| 348. |
How can we take input text from user in HTML page?(a) input tag(b) inoutBufferedReader tag(c) meta tag(d) scanner tag |
|
Answer» Right option is (a) input tag Easy explanation: HTML provides various user input options like input, radio, text, etc. |
|
| 349. |
Which of these packages contain all the collection classes?(a) java.lang(b) java.util(c) java.net(d) java.awt |
|
Answer» Correct answer is (b) java.util To explain I would say: None. |
|
| 350. |
What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY?(a) 0 & 256(b) 0 & 1(c) 1 & 10(d) 1 & 256 |
|
Answer» Correct option is (c) 1 & 10 Explanation: None. |
|