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 architecture
  1. The capability of an object to exist after the program that created it has stopped running.

  2. The ability of a class to support multiple threads.

  3. An Error-Handling technique.

  4. None of the above.

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

Multiple choice technology architecture
  1. Call System.gc()

  2. Garbage collection cannot be forced.

  3. Call System.gc(), passing in a reference to the object to be garbage-collected.

  4. Call Runtime.gc()

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

Multiple choice technology architecture
  1. get(1);

  2. get(2);

  3. get(“Chance”);

  4. None of the above.

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

Multiple choice technology architecture
  1. String [] strArr = [“element 1”, “element 2];

  2. String [] strArr = {“element 1”, “element 2”};

  3. String [] strArr = (“element 1”, “element2”);

  4. String [] strArr = new String [“element 1” , “element 2”];

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

Multiple choice technology programming languages
  1. StringBuilder

  2. StringBuffer

  3. Both (1) and (2)

  4. None of the above

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

Multiple choice technology databases
  1. User Defined Exception

  2. Predefined Internal Exception --- NO_DATA_FOUND

  3. Predefined Internal Exception --- VALUE_ERROR

  4. OTHERS Exception

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

Multiple choice technology databases
  1. The current block is always searched first for a handler

  2. If the exception handler is NOT found in the current block, enclosing block if any is searched for the exception handler.

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

  4. If the exception handler is NOT found, then exception is returned back to the calling environment

  5. All of above

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

Multiple choice technology testing
  1. value, time out

  2. property name, value, time out in milliseconds

  3. property name, value, time out in seconds

  4. property, time out

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

Multiple choice technology testing
  1. Wait – makes a wait for the specified seconds with optional milliseconds

  2. Wait – makes a wait for the specified seconds only

  3. Wait – makes a wait for the specified seconds with mandatory milliseconds

  4. None of the statements are true

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

Multiple choice technology programming languages
  1. True

  2. False

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

Multiple choice technology packaged enterprise solutions
  1. pyIterationNumber

  2. pyForEach

  3. pyForEachCount

  4. pyCount

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

Multiple choice technology packaged enterprise solutions
  1. Use Ob-Open-By-Handle and use the LockInfoPage

  2. Run a RDB method against the database to see who holds the lock

  3. Use the tools.getLockManager().isLocked method in a java step

  4. None

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