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
-
Yes, but the actual collection is not deterministic
-
No.
-
Yes, and the actual collection is deterministic
-
I don't know.
-
Yes
-
No
-
May be
-
I don't know
B
Correct answer
Explanation
When a StackOverflowException occurs, the process is terminated immediately because the stack is corrupted. Unlike most exceptions, finally blocks do NOT execute for StackOverflowException. This is because there's no stack space left to execute the finally block - the runtime cannot safely continue execution.
-
Validator
-
Converters
-
Exception handler
-
Event listeners
C
Correct answer
Explanation
JSF provides validators for input validation, converters for type conversion between strings and objects, and event listeners for handling component events. Exception handling in JSF is typically managed through error-page configuration and custom exception factory rather than being a first-class framework-provided component.
-
nothing happen, excution will continue.
-
it will be handled by compiler, and excution stops.
-
the exception will be rethrown
-
terminate() function will be called and execution stops.
D
Correct answer
Explanation
When an exception is thrown and not caught by any handler, C++ calls std::terminate(). This function typically calls std::abort(), which immediately stops program execution. This prevents undefined behavior from propagating.
-
Line 46 will compile if the enclosing method throws a TestException.
-
Class A will not compile.
-
Line 46 will compile if enclosed in a try block, where TestException is caught
-
Line 45 can throw the unchecked exception TestException.
A,C
Correct answer
Explanation
TestException is a checked exception (extends Exception). Line 46 calls a method that throws TestException, so it must either: (A) be in a method that declares throws TestException, or (C) be wrapped in a try-catch block. Option A is true - if the enclosing method throws TestException, line 46 compiles. Option C is true - try-catch handles it. Option D is false because TestException is checked, not unchecked.
-
Extend the java.lang.Throwable class
-
Extend the java.lang.Thread class
-
Extend the java.lang.Runnable
-
Implement the Runnable interface
B,D
Correct answer
Explanation
Threads in Java can be created by extending the Thread class and overriding its run() method, or by implementing the Runnable interface and passing an instance to a Thread constructor. Runnable is an interface (not a class), so you implement it, not extend it. Throwable is for exceptions, not threads.
-
Thread class
-
Runnable Interface
-
Applet
-
Throwable
A,B
Correct answer
Explanation
The run() method is defined as an abstract method in the java.lang.Runnable interface to represent a task's entry point. The java.lang.Thread class implements Runnable and provides a concrete implementation of run(). Neither Applet nor Throwable declares the run() method as part of their standard contracts.
-
String
-
Thread object
-
Primitive data type variables
-
object of a class which implements Runnable
-
A thread gets a default priority
-
cause the currently running thread to move back to runnable so that a thread of the same priority can have a chance.
-
Guaranteed to cause the current thread to stop executing for at least the specified sleep duration
-
Guaranteed to cause the current thread to stop executing until the thread it joins with completes
D
Correct answer
Explanation
join() makes the current thread wait until the specified thread completes execution. The other options describe priority behavior (A), yielding (B), and sleep behavior (C) - none match join()
-
A thread can acquire more than one lock
-
Each object has just one lock.
-
all methods in a class must be synchronized
-
methods,variables can be synchronized,
A,B
Correct answer
Explanation
In Java synchronization, a single thread can acquire multiple locks concurrently, and every object is associated with exactly one monitor lock. It is incorrect to claim that all class methods must be synchronized, as developers selectively synchronize code. Variables cannot be synchronized directly; only methods and blocks can use the synchronized keyword.
-
(a) Activity-End
-
(b) End-Activity
-
(c) Exit-Activity
-
none of the above
C
Correct answer
Explanation
The Exit-Activity method terminates the current activity and returns control to the calling activity or flow. This is the standard way to exit an activity programmatically. Activity-End and End-Activity are not valid method names in Process Commander's activity model. The Exit-Activity method properly manages the call stack and control transfer.
-
(a) Forward chaining
-
(b) Backward chaining
-
Goal Seek
-
none of the above
B
Correct answer
Explanation
Property-Seek-Value is the method used to invoke backward chaining in Process Commander. Backward chaining works from a goal or desired value backward to find the facts needed to satisfy that goal. When a property's value is sought using this method, the system triggers backward chaining to derive the value through dependency resolution. Forward chaining works in the opposite direction.
-
public static void main(String[] args)
-
public static void main()
-
public void main(String[] args)
-
public void static main(String[] args)
A,B,C
Correct answer
Explanation
Java main method must be static, but public is not strictly required (though runtime looks for public). Variations: A is standard, B is valid static main without args (compile-time valid, though JVM won't call it), C is valid non-public static main, D is invalid syntax (void must come before method name, not after).
B
Correct answer
Explanation
The final keyword on a method explicitly prevents subclasses from overriding it. This is used when you want to ensure a method's implementation remains unchanged in the inheritance hierarchy.