Computer Knowledge
Java Core Classes and Threads
1,935 Questions
Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.
String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules
Java Core Classes and Threads Questions
-
You forgot the hashCode method
-
You didn't handle circular references properly
-
Could be any / both of above
-
None of above
C
Correct answer
Explanation
Hashtable relies on both equals() and hashCode() to store and locate keys. If you override equals() but not hashCode(), equal objects will have different hash codes, preventing Hashtable from finding them. Circular references can also cause infinite loops or incorrect behavior during lookup.
-
Throws an exception.
-
Executes the action method and throws an exception.
-
Executes the action method and renders current view.
-
Controller will be in the same page
C
Correct answer
Explanation
The claimed answer is C. When a commandLink or commandButton action method returns null, JSF executes the action method but then re-renders the current view instead of navigating to a different page. Option A and B are incorrect because no exception is thrown. Option D is misleading - it's not just 'same page', it's explicitly re-rendering the current view after action execution.
A
Correct answer
Explanation
The processDecodesWithoutValidation method in JSF does exactly what its name suggests: it executes the Apply Request Values phase and decodes parameters without running validation. This is useful for scenarios where you want to process submitted data but skip validation logic. The method will handle RuntimeExceptions appropriately, but its key characteristic is bypassing the validation phase for immediate components.
-
call_form
-
new_form
-
open_form
-
both b) & c)
C
Correct answer
Explanation
OPEN_FORM is the correct method when you need to use both the calling form and called form simultaneously. CALL_FORM replaces the calling form and control returns only after the called form exits, while NEW_FORM replaces the calling form completely without returning.
-
Unchecked
-
Checked
-
All of the Above
-
None of the Above
A
Correct answer
Explanation
The Struts 2 exception handling mechanism primarily handles unchecked exceptions (RuntimeException and its subclasses). Checked exceptions need to be caught and handled by the application code or wrapped in runtime exceptions. The exception mapping in struts.xml works with unchecked exceptions.
-
java.lang.Error
-
java.lang.Throwable
-
java.lang.Util
-
java.lang.CheckedException
B
Correct answer
Explanation
In Java's exception hierarchy, Throwable is the base class for all throwable objects. Exception inherits directly from Throwable, while Error is a separate subclass of Throwable for serious system errors that applications typically shouldn't catch.
-
UncheckedException
-
CheckedException
-
Error
-
UnspecifiedException
C
Correct answer
Explanation
StackOverflowError and OutOfMemoryError are both subclasses of java.lang.Error, not Exception. Errors represent serious problems that applications should not typically catch - they indicate JVM-level issues rather than application logic problems.
-
It will go for Garbage Collector
-
It remains in Stack
-
It will not create any object
-
Exception objects will not put load on JVM
A
Correct answer
Explanation
After an exception is handled and no references to the exception object remain, it becomes eligible for garbage collection like any other dereferenced Java object. It does not remain permanently on the stack.
-
UncheckedException
-
CheckedException
-
Error
-
UnspecifiedException
A
Correct answer
Explanation
NullPointerException extends RuntimeException, making it an unchecked exception. This means developers aren't required to catch or declare it - it typically indicates programming errors like attempting to use a null reference where an object is required.
-
GetVisibleText
-
GetROProperty
-
SetROProperty
-
GetTOProperty
B
Correct answer
Explanation
GetROProperty (Get Run-Time Object Property) is the QTP/UFT method used to retrieve the current property value of a test object from the application during a run session. GetTOProperty retrieves properties from the test repository, and SetROProperty is not a valid method.
-
Session.Close ( )
-
Session.Discard ( )
-
Session.Abandon ( )
-
Session.Exit ( )
C
Correct answer
Explanation
Session.Abandon() is the correct method to explicitly terminate a user's session in ASP.NET. It ends the current session, releases session resources, and fires the Session_End event. The other methods (Close, Discard, Exit) do not exist in the Session API.
-
Thread.start()
-
Thread.run()
-
Thread.yield()
-
A dead thread cannot be restarted.
D
Correct answer
Explanation
Once a Java thread completes its execution (exits its run() method) or is terminated, its state becomes 'TERMINATED' (dead). In JVM, you cannot restart a dead thread; attempting to call start() on it again will throw an IllegalThreadStateException.
-
StringBuilder is immutable but StringBuffer is mutable.
-
StringBuffer is immutable but StringBuilder is mutable.
-
StringBuffer is Synchronized but StringBuilder is not.
-
They both are immutable.
C
Correct answer
Explanation
StringBuffer is synchronized (thread-safe) while StringBuilder is not. Both classes are mutable - they can be modified after creation. StringBuilder is faster when you don't need thread safety.
-
Implementing Thread interface.
-
Implementing Cloneable interface.
-
Implementing the Runnable interface.
-
We can not create a Thread, JVM has to create it by it's own.
C
Correct answer
Explanation
A Thread can be created either by extending the Thread class or by implementing the Runnable interface. Option A is wrong because Thread is a class, not an interface. Option D is wrong - we can and do create Threads programmatically.