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. wait(), toString() only

  2. notify(), notifyall() only

  3. run(), stop()

  4. wait(),toString(),notify(), notifyall() and finalize()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The Object class in Java has methods like wait(), notify(), notifyAll(), toString(), equals(), hashCode(), and finalize(). Option D correctly lists wait(), toString(), notify(), notifyAll(), and finalize() - though it's not exhaustive (it misses equals() and hashCode()). Among the given options, D is the most complete and correct.

Multiple choice technology programming languages
  1. wait(), toString() only

  2. notify(), notifyall() only

  3. run(), stop()

  4. wait(),toString(),notify(), notifyall() and finalize()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The Java java.lang.Object class contains methods like wait(), toString(), notify(), notifyAll(), and finalize(). Methods like run() and stop() belong to the Thread or Runnable interfaces, not the Object class.

Multiple choice technology programming languages
  1. NullPointerException

  2. NumberFormatException

  3. ExceptionInInitializerError

  4. IllegalArgumentException

Reveal answer Fill a bubble to check yourself
A,C Correct answer
Explanation

NullPointerException and ExceptionInInitializerError are standard exceptions thrown directly by the JVM. NumberFormatException and IllegalArgumentException are typically thrown by Java runtime library code (such as Integer.parseInt) rather than the JVM itself.

Multiple choice technology
  1. red orange Purple

  2. Green blue Purple

  3. red yellow Green

  4. red yellow Orange

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The ArrayList starts with red, yellow, orange, green, blue, purple. RemoveRange(3,3) removes 3 elements starting at index 3 (0-based): green, blue, and purple. This leaves red, yellow, orange - the first three items that were added before the removal range.

Multiple choice technology
  1. ItemDeleted

  2. ItemDeleting

  3. ItemUpdated

  4. ItemUpdating

Reveal answer Fill a bubble to check yourself
A,C Correct answer
Explanation

SharePoint event receivers use naming conventions: '-ing' suffix (ItemDeleting, ItemUpdating) are synchronous events that run BEFORE the action and can cancel it. '-ed' suffix (ItemDeleted, ItemUpdated) are asynchronous events that run AFTER the action completes.

Multiple choice technology
  1. Use ItemDeleted Event

  2. Use ItemDeleting Event

  3. Use properties.Cancel = true;

  4. Use properties.Cancel = false;

Reveal answer Fill a bubble to check yourself
B,C Correct answer
Explanation

To prevent a document deletion, you must use the ItemDeleting event (option B), which fires before the deletion occurs and can be cancelled. The ItemDeleted event (option A) fires after deletion is complete, making it too late to prevent. Setting properties.Cancel = true (option C) within the ItemDeleting event handler cancels the deletion operation. Setting it to false (option D) would allow the deletion to proceed, which is the opposite of what we want.

Multiple choice technology web technology
  1. Add a TYPE=HIDDEN INPUT to the form

  2. Trap the return keypress and return (null

  3. Add 'return false' to onsubmit="..." in the FORM tag

  4. Instruct the user not to press the Return key.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The issue is that pressing Return in a text field within a form submits the form prematurely, before the user can click the processing button. The correct solution is to add 'return false' to the onsubmit handler in the FORM tag, which prevents the default form submission behavior. Option A (hidden input) doesn't address the issue. Option B (trapping return key) is incomplete. Option D (user instruction) is not a technical solution.

Multiple choice technology web technology
  1. The statement(s) it executes run(s) only once.

  2. It pauses the script in which it is called.

  3. clearTimeOut() won't stop its execution.

  4. The delay is measured in hundredths of a second.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

JavaScript's setTimeout() schedules a function to run once after a specified delay. It does not pause script execution (non-blocking) and its delay is measured in milliseconds, not hundredths of a second. clearTimeout() stops it if called before execution, making the first option true.

Multiple choice technology programming languages
  1. Option 1

  2. Option 2

  3. Option 1 & 2

  4. Option 3

  5. Option 2 & 3

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Java requires that package statements must come before import statements, and both must appear before any class definitions. Option 1 violates this rule by placing import before package. Options 2 and 3 follow the correct order: package, then import, then class.