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 web technology
  1. 15

  2. 30

  3. 60

  4. 90

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

The default executionTimeout in ASP.NET is 90 seconds, meaning requests have up to 90 seconds to complete before ASP.NET terminates them. The other values (15, 30, 60 seconds) are all less than the actual default and would need to be explicitly configured.

Multiple choice technology web technology
  1. using ToArray method

  2. using FileContent property

  3. using ToString method

  4. None of the above

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

The FileContent property of a file upload control directly returns the file contents as a byte array/stream object. ToArray() would require additional steps, ToString() would convert to string representation, and the FileContent property is the most direct method provided.

Multiple choice technology programming languages
  1. By invoking the method get (..., String type) on the ResultSet, where type is the database

  2. By invoking the method get (..., Type type) on the ResultSet, where Type is an object

  3. By invoking the method getValue (...), and cast the result to the desired java type.

  4. By invoking the special getter methods on the ResultSet: getString (...), get Boolean (...),

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

ResultSet provides type-specific getter methods like getString(), getInt(), getBoolean() to retrieve column values by column name or index. The methods handle type conversion automatically. Options A, B, and C describe non-existent methods - there is no generic get() or getValue() method in ResultSet.

Multiple choice technology programming languages
  1. You must catch the checked SQLException which is thrown by the method which executes

  2. You must catch the unchecked SQLWarningException which is thrown by the method

  3. You must invoke the getWarnings() method on the Statement object (or a sub interface

  4. You must query the ResultSet object about possible warnings generated by the database

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

SQL warnings in JDBC do not throw exceptions. Developers must call getWarnings() on the Statement, Connection, or ResultSet object to check for them. Distractors suggesting catching exceptions are wrong since warnings are silent.

Multiple choice technology packaged enterprise solutions
  1. WMAlert(strMessage, strDebug)

  2. WMAlert ( strDebug, strMessage)

  3. WMCAlert(strMessage, strDebug)

  4. WMCAlert ( strDebug, strMessage)

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

The ClarifyCRM web framework utilizes the WMAlert function, which accepts the message string as the first argument and the debug string as the second argument: WMAlert(strMessage, strDebug). The other variations reverse the arguments or use incorrect function prefixes.

Multiple choice technology programming languages
  1. The element will be successfully added

  2. ArrayIndexOutOfBounds Exception

  3. The Vector allocates space to accommodate up to 17 elements

  4. The element will be successfully deleted

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

Java's Vector class is dynamically resizable and automatically grows its capacity when needed. Unlike fixed-size arrays, Vector will successfully add elements beyond its initial capacity by internally allocating more space, so adding a 6th element to a Vector initialized with capacity 5 will succeed without throwing an exception.

Multiple choice technology programming languages
  1. True

  2. False

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

The Runnable interface requires only the run() method to be implemented. The start() method belongs to the Thread class, not Runnable. When implementing Runnable, you override run() with your task logic, then pass the Runnable to a Thread which calls start() to invoke run() in a new thread.

Multiple choice technology programming languages
  1. True

  2. False

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

The wait() method explicitly releases the object lock before putting the thread to wait. The thread must wait for another thread to call notify() or notifyAll() on the same object, then reacquire the lock before resuming execution. This mechanism enables inter-thread communication by allowing other threads to access the synchronized object while one thread waits.

Multiple choice technology programming languages
  1. A

  2. B

  3. C

  4. D

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

Throwing IllegalArgumentException is the standard practice in Java to signal that a method argument is invalid (null) when it is required to be non-null.

Multiple choice technology programming languages
  1. addSize

  2. getCust

  3. deleteRep

  4. isColorado

  5. putDimensions

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

JavaBeans naming convention requires getters to use 'get' prefix (or 'is' for boolean properties) and setters to use 'set' prefix. getCust() correctly uses the 'get' prefix for a getter method. isColorado() correctly uses the 'is' prefix for a boolean getter. addSize(), deleteRep(), and putDimensions() don't follow JavaBeans patterns.

Multiple choice technology web technology
  1. The before() method will print 1 2

  2. The before() method will print 1 2 3

  3. The before() method will print three numbers, but the order cannot be determined

  4. The before() method will not compile

  5. The before() method will throw an exception at runtime

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

TreeSet stores elements in sorted order and requires elements to be mutually comparable. When you add String "2" then Integer 3, TreeSet attempts to compare them using natural ordering, which causes ClassCastException at runtime because String and Integer are not mutually comparable. The TreeSet.iterator() triggers the comparison during traversal.

Multiple choice technology web technology
  1. java.util.HashSet

  2. java.util.LinkedHashSet

  3. java.util.List

  4. java.util.ArrayList

  5. java.util.Vector

  6. java.util.PriorityQueue

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

java.util.ArrayList implements the List interface, allowing dynamic resizing and providing fast O(1) indexed access (random access) to its elements. Unlike Vector, the methods of ArrayList are not synchronized, making it faster but not thread-safe.

Multiple choice technology web technology
  1. 2 2 3 3

  2. 2 2 3 4

  3. 4 3 3 4

  4. 2 2 3 3 3

  5. 4 3 3 3 3

  6. 2 2 3 3 4

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

At line 16, pq.peek() returns '2'. Next, '1' is offered, '3' is added, and '1' is removed, leaving '2', '3', '4'. Line 20 polls and prints '2'. At line 21, pq.remove('2') returns false (as '2' was already polled), preventing the print inside the if-condition. Finally, line 22 polls '3' and peeks at '4'.