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

Multiple choice technology programming languages
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. getParent()

  2. getAncestor()

  3. findAncestor()

  4. findParent()

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. System.gc();

  2. System.free();

  3. System.setGarbageCollection();

  4. System.out.gc();

Reveal answer Fill a bubble to check yourself
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).

Multiple choice technology programming languages
  1. An exception is thrown if you attempt to add an element with a duplicate value

  2. The add method returns false if you attempt to add an element with a duplicate value

  3. A set may contain elements that return duplicate values from a call to the equals method

  4. Duplicate values will cause an error at compile time

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. f1.getBar() ==null

  2. b2.getFoo == null

  3. b1.getFoo == null

  4. none of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology testing
  1. JProbe tracks calls to the methods in your application

  2. Encapsulates data when your application calls the specified native methods

  3. Triggers provide a way to tie JProbe actions to your program’s execution

  4. None

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology testing
  1. Heap View

  2. Instance View

  3. Leak Doctor View

  4. Allocation View

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology testing
  1. GetList

  2. GetItem

  3. GetItemsCount

  4. GetRoProperty

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology testing
  1. A collection object

  2. A string true/false

  3. Number of objects matching the description

  4. Boolean True/False

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology platforms and products
  1. Property-Map-Value calls a Rule-Obj-MapValue once, and Property-Map-ValuePair calls it twice

  2. 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

  3. 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

  4. 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

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology platforms and products
  1. Use the Java method

  2. AtSetValue(PropertyName, Value)

  3. Use the Property-Set method

  4. {PropertyName INPUT}

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. NamedValueCollection

  2. HashTable

  3. SortedList

  4. I don't know

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. No difference

  2. S.ToString() handles null values

  3. Convert.ToString(S) handles null values

  4. I don't know.

Reveal answer Fill a bubble to check yourself
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.