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
A
Correct answer
Explanation
Java's garbage collector automatically reclaims memory from objects that are no longer reachable. An object becomes eligible for garbage collection when there are no live references to it in the running program. This is a fundamental memory management feature in Java.
-
getParent()
-
getAncestor()
-
findAncestor()
-
findParent()
A
Correct answer
Explanation
In JSP custom tag handlers, getParent() returns the closest enclosing tag handler. This is part of the Tag and BodyTag interfaces. getAncestor(), findAncestor(), and findParent() are not standard methods in the JSP tag handler API. The getParent() method allows a nested tag to communicate with its parent tag, which is essential for cooperative tag handler patterns.
-
System.gc();
-
System.free();
-
System.setGarbageCollection();
-
System.out.gc();
A
Correct answer
Explanation
System.gc() suggests to the JVM that garbage collection should run. Note that this is only a suggestion - the JVM may ignore it. System.free(), System.setGarbageCollection(), and System.out.gc() are not valid Java methods. The gc() method is in the System class, not in PrintStream (which System.out is).
-
An exception is thrown if you attempt to add an element with a duplicate value
-
The add method returns false if you attempt to add an element with a duplicate value
-
A set may contain elements that return duplicate values from a call to the equals method
-
Duplicate values will cause an error at compile time
B
Correct answer
Explanation
When adding a duplicate element to a Set, the add() method returns false but does not throw an exception. Sets are designed to contain only unique elements - duplicates are simply ignored. The add() method's return value indicates whether the element was actually added (true if it was a new element, false if it was a duplicate). No compile-time or runtime error occurs.
-
f1.getBar() ==null
-
b2.getFoo == null
-
b1.getFoo == null
-
none of the above
A,B
Correct answer
Explanation
In a unidirectional relationship Foo→Bar, only Foo knows about Bar (Foo has a getBar() method, Bar has NO getFoo() method). After f2.setBar(f1.getBar()), f2 now points to b1. Since the relationship is unidirectional from Foo to Bar, b1 has NO reference to any Foo. b1.getFoo() doesn't exist (not that it's null - the method doesn't exist). For the unidirectional case, b2.getFoo() also doesn't exist - but the question implies b2 now has no incoming reference from f2.
-
JProbe tracks calls to the methods in your application
-
Encapsulates data when your application calls the specified native methods
-
Triggers provide a way to tie JProbe actions to your program’s execution
-
None
C
Correct answer
Explanation
Triggers in JProbe allow developers to control profiling actions dynamically by tying them to specific events in the program's execution, such as entering or exiting a method. The distractors describe general profiling behavior or native method encapsulation rather than the specific automation purpose of triggers.
-
Heap View
-
Instance View
-
Leak Doctor View
-
Allocation View
C
Correct answer
Explanation
Leak Doctor View is specifically designed in JProbe to help identify memory leaks by tracking object allocations, garbage collection cycles, and objects that persist longer than expected. It analyzes reference chains and helps pinpoint why objects are not being garbage collected. Heap View shows overall memory distribution, Instance View lists individual objects, and Allocation View tracks where objects were created - none specifically target leak detection like Leak Doctor.
A
Correct answer
Explanation
Overriding methods in Java can throw any unchecked (runtime) exceptions regardless of what the overridden method declares. This includes RuntimeException, Error, and their subclasses. Checked exceptions are more restricted - overriding methods cannot throw broader checked exceptions than the overridden method.
-
GetList
-
GetItem
-
GetItemsCount
-
GetRoProperty
D
Correct answer
Explanation
GetRoProperty is a generic QTP method that retrieves any runtime property of an object, including 'items count' for a WebList. The other options (GetList, GetItem, GetItemsCount) are not standard QTP methods. GetRoProperty('items count') returns the number of items as a string or number.
-
A collection object
-
A string true/false
-
Number of objects matching the description
-
Boolean True/False
A
Correct answer
Explanation
The ChildObjects method returns a collection object containing all child objects matching the description properties you specify. It returns a Collection object (not a simple count or boolean), which you can then iterate through using .Count and .Item(index). This is essential for dynamic object handling when you don't know exactly how many objects exist.
-
Property-Map-Value calls a Rule-Obj-MapValue once, and Property-Map-ValuePair calls it twice
-
Property-Map-Value can call a Rule-Obj-MapValue and pass a single row input, and Property-Map-Value-Pair can call a Rule-Obj-Map Value and pass two row inputs
-
Property-Map-Value can call a Rule-Obj-MapValue and pass a single row input, and Property-Map-Value-Pair can call a Rule-Obj-Map Value and pass a single row input and single column input
-
Property-Map-Value can call a Rule-Obj-MapValue and pass a single row input, and Property-Map-Value-Pair can call a Rule-Obj-Map Value and pass multiple row inputs
C
Correct answer
Explanation
Property-Map-Value passes a single row input to a Rule-Obj-MapValue. Property-Map-ValuePair passes a single row input AND a single column input to the Rule-Obj-MapValue, allowing lookup based on two dimensions. This is the key difference between the two methods.
-
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.