Computer Knowledge
Java Core Classes and Threads
1,473 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
-
Use the Java method
-
AtSetValue(PropertyName, Value)
-
Use the Property-Set method
-
{PropertyName INPUT}
C
Correct answer
Explanation
The Property-Set method is the standard and recommended way to update property values in PEGA activity steps, providing proper framework integration. Java methods break abstraction, AtSetValue is not a standard PEGA method, and {PropertyName INPUT} is a reference syntax not a method for setting values.
-
java.lang.Thread
-
java.lang.Object
-
java.lang.Runnable
-
java.lang.ThreadGroup
B
Correct answer
Explanation
wait() and notify() are defined in java.lang.Object class, making them available to all objects since every class inherits from Object. They are not in Thread, Runnable, or ThreadGroup classes.
-
NamedValueCollection
-
HashTable
-
SortedList
-
I don't know
B
Correct answer
Explanation
HashTable allows data retrieval by unique key and is the standard .NET collection for key-value pairs. NamedValueCollection is for multiple values per key, SortedList maintains sort order, and the question specifically asks for unique key retrieval which HashTable provides.
-
No difference
-
S.ToString() handles null values
-
Convert.ToString(S) handles null values
-
I don't know.
C
Correct answer
Explanation
The key difference is null handling. If S is null, S.ToString() throws a NullReferenceException because you're calling a method on a null reference. Convert.ToString(S) handles null gracefully and returns an empty string or null without throwing an exception. This makes Convert.ToString safer when null values are possible.
-
Yes, but the actual collection is not deterministic
-
No.
-
Yes, and the actual collection is deterministic
-
I don't know.
A
Correct answer
Explanation
Garbage collection can be requested explicitly using methods like System.gc() in languages like Java, but the runtime environment determines when and if actual collection occurs, making it non-deterministic.
-
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.
-
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.