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
-
The capability of an object to exist after the program that created it has stopped running.
-
The ability of a class to support multiple threads.
-
An Error-Handling technique.
-
None of the above.
A
Correct answer
Explanation
Persistence means data survives beyond the execution of the program that created it. Objects can be stored to disk or database and reconstructed later, allowing data to exist between program runs. Thread support, error handling, and other options are unrelated to the core concept of persistence.
-
Call System.gc()
-
Garbage collection cannot be forced.
-
Call System.gc(), passing in a reference to the object to be garbage-collected.
-
Call Runtime.gc()
B
Correct answer
Explanation
Java garbage collection cannot be forced - calling System.gc() or Runtime.gc() only suggests to the JVM that garbage collection should run, but the JVM may ignore the request. Garbage collection runs automatically based on heap pressure and JVM algorithms. This is a fundamental Java concept developers must understand.
-
get(1);
-
get(2);
-
get(“Chance”);
-
None of the above.
A
Correct answer
Explanation
Initially: [Tinker(0), Evers(1), Chance(2)]. After removeElement('Evers'): [Tinker(0), Chance(1)]. Calling get(1) returns 'Chance' at index 1. get(2) would throw IndexOutOfBoundsException. get('Chance') is invalid syntax - Vector.get() expects int index, not object.
-
String [] strArr = [“element 1”, “element 2];
-
String [] strArr = {“element 1”, “element 2”};
-
String [] strArr = (“element 1”, “element2”);
-
String [] strArr = new String [“element 1” , “element 2”];
B
Correct answer
Explanation
In Java, array initialization uses curly braces: String[] strArr = {"element 1", "element 2"}; Option A uses square brackets incorrectly. Option C uses parentheses (invalid for arrays). Option D incorrectly uses 'new String[]' with initialization values - should be 'new String[]{...}' or just {...}.
-
StringBuilder
-
StringBuffer
-
Both (1) and (2)
-
None of the above
B
Correct answer
Explanation
StringBuffer is synchronized (thread-safe) while StringBuilder is not. StringBuffer's methods are synchronized, making it safe for use in multi-threaded environments, though slower than StringBuilder. StringBuilder was introduced in Java 5 as a non-synchronized alternative for single-threaded contexts.
-
User Defined Exception
-
Predefined Internal Exception --- NO_DATA_FOUND
-
Predefined Internal Exception --- VALUE_ERROR
-
OTHERS Exception
D
Correct answer
Explanation
The WHEN OTHERS exception handler is a catch-all block that handles any exceptions not explicitly caught by preceding handlers. Because it catches everything, it must be the last handler in a PL/SQL exception block.
-
The current block is always searched first for a handler
-
If the exception handler is NOT found in the current block, enclosing block if any is searched for the exception handler.
-
If the exception handler is found, then it's executed. Control is passed to the enclosing block if one exists OR to the calling environment if there is no enclosing block.
-
If the exception handler is NOT found, then exception is returned back to the calling environment
-
All of above
E
Correct answer
Explanation
Exception propagation checks the current block first. If unhandled, it bubbles up to the enclosing block, and eventually to the calling environment. Once handled, execution continues in the enclosing block or calling environment.
-
GetCount
-
Count
-
RowCount
-
GetRowCount
D
Correct answer
Explanation
In QTP/UFT DataTable object, the GetRowCount method is used to retrieve the number of rows in a sheet. Common alternatives like GetCount, Count, or RowCount do not exist or serve different purposes in the DataTable object model.
-
value, time out
-
property name, value, time out in milliseconds
-
property name, value, time out in seconds
-
property, time out
B
Correct answer
Explanation
The WaitProperty method in QTP/UFT takes three parameters: the property name to check, the expected value, and the timeout in milliseconds. It waits for the specified property to attain the expected value within the given timeout period.
-
Wait – makes a wait for the specified seconds with optional milliseconds
-
Wait – makes a wait for the specified seconds only
-
Wait – makes a wait for the specified seconds with mandatory milliseconds
-
None of the statements are true
A
Correct answer
Explanation
The Wait method in QTP/UFT creates a pause for the specified number of seconds. While seconds are the primary parameter, the method can also accept optional milliseconds for more precise timing control, though this is less commonly used.
-
GetTOProperty
-
SetTOProperty
-
GetROProperty
-
None
C
Correct answer
Explanation
GetROProperty (Get Run-time Object Property) retrieves the actual value of an object's property during test execution, such as user input. GetTOProperty only retrieves the property value stored in the Test Object repository.
A
Correct answer
Explanation
JDO stands for Java Data Objects, a standard interface-based Java model abstraction for persisting Java objects into databases. This definition is correct.
B
Correct answer
Explanation
JVM stands for Java Virtual Machine, not Java Virtual Method. It's an abstract computing machine that enables a computer to run Java programs as well as programs written in other languages compiled to Java bytecode. The False option is correct as 'Machine' replaces 'Method'.
-
pyIterationNumber
-
pyForEach
-
pyForEachCount
-
pyCount
C
Correct answer
Explanation
During loop execution over a list, Pega automatically stores the current iteration index in the standard parameter pyForEachCount. The other parameters like pyIterationNumber, pyForEach, and pyCount do not exist as standard loop counters in Pega's engine API, making them incorrect.
-
Use Ob-Open-By-Handle and use the LockInfoPage
-
Run a RDB method against the database to see who holds the lock
-
Use the tools.getLockManager().isLocked method in a java step
-
None
C
Correct answer
Explanation
The tools.getLockManager().isLocked() method checks lock status without attempting to acquire the lock, making it ideal for this diagnostic purpose. The other options either require acquiring locks or use inefficient database queries.