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

  2. Synchronous

  3. Synchronous and Asynchronous

  4. None of above

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

In general API design (such as Java Servlet sessions, JMS session methods, or database sessions), session methods are synchronous blocking operations. While asynchronous messaging exists, a session's execution context is synchronous by default unless explicitly specified.

Multiple choice technology testing
  1. Step Over

  2. Step Out

  3. Step Into

  4. Step Till

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

Step Over executes the current line and if it calls a method, runs the entire method without showing internal steps. Step Into would enter the method's code, Step Out returns from the current method to its caller, and Step Till is not a standard debugging command.

Multiple choice technology databases
  1. queue

  2. callback

  3. interval

  4. transport

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

Creating a timer event requires a queue (to manage event dispatching), a callback function (to execute when the timer fires), and an interval (the time between timer events). Transport is not required for timers - they are local timing objects that don't involve network communication.

Multiple choice technology programming languages
  1. Set ThrowOnUnmappableChar = True

  2. Set ThrowOnmappableChar = True

  3. Set ThrowOnmappableChar = False

  4. Set ThrowOnUnmappableChar = False

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

Setting ThrowOnUnmappableChar to true causes marshaling operations to throw an exception when a Unicode character cannot be mapped to an ANSI character. Setting it to false silently replaces unmappable characters with a default '?' character.

Multiple choice technology programming languages
  1. The code does not compile

  2. The code compiles cleanly and shows “Object Version

  3. The code compiles cleanly and shows “String Version”

  4. The code throws an Exception at Runtime

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

When method overloading exists with null argument, Java chooses the most specific method. Since String extends Object, the String version is more specific than Object version. The compiler resolves null to the String overload at compile-time. The code compiles cleanly and prints 'String Version'. This is a classic Java overload resolution rule.

Multiple choice technology programming languages
  1. new

  2. break

  3. default

  4. goto

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

Java has 50 reserved keywords including 'new' (instantiation), 'break' (loop exit), and 'default' (switch/annotation default). 'goto' is a reserved keyword but not used in Java - it's reserved for potential future use but has no functionality. Option D is incorrect because goto is indeed a reserved keyword in Java.

Multiple choice technology programming languages
  1. final

  2. finally

  3. finalize

  4. finalised

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

In Java, 'final' is a keyword for variables/methods/classes that cannot be changed/extended. 'finally' is a keyword used in try-catch blocks for code that always executes. 'finalize()' is a method name (deprecated) for garbage collection cleanup. However, 'finalised' is NOT part of the Java language - it's a common misspelling. The correct answer is D because it's the only option that is not a valid Java keyword or method.

Multiple choice technology programming languages
  1. Vector

  2. ArrayList

  3. Hashtable

  4. HashMap

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

Vector is a legacy class (introduced in JDK 1.0) that implements a synchronized resizable array as part of the List interface. Every method in Vector is synchronized, making it thread-safe but slower than non-synchronized alternatives. ArrayList is the unsynchronized modern alternative. Hashtable is synchronized but implements Map, not List. HashMap is unsynchronized and also implements Map.

Multiple choice technology programming languages
  1. Boxing and UnBoxing

  2. Generics

  3. Enhanced for

  4. Iterator

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

Java 1.5 (Tiger) introduced autoboxing/unboxing for automatic primitive-wrapper conversion, generics for type-safe collections, and the enhanced for-loop for cleaner iteration. The Iterator interface existed since Java 1.2, so it was not a new feature in Java 1.5. The claimed answer correctly identifies A, B, and C.

Multiple choice technology programming languages
  1. Wait

  2. notify

  3. notifyAll

  4. Sleep

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

Java's Object class provides wait(), notify(), and notifyAll() for inter-thread communication using the monitor pattern. These methods must be called within synchronized code. The sleep() method pauses a thread but is not used for communication. The claimed answer A, B, C is correct.

Multiple choice technology programming languages
  1. String

  2. StringBuffer

  3. Both

  4. None

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

StringBuffer is mutable and more efficient for multiple concatenations in loops because it modifies a single buffer. String is immutable - each concatenation creates a new object. For repeated concatenation, StringBuffer (or StringBuilder in newer Java) is preferred. The claimed answer B is correct.

Multiple choice technology programming languages
  1. sizeOf ()

  2. size()

  3. getSize()

  4. No such method in java to find size of an object directly.

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

Java does not provide any built-in method like sizeof(), size(), or getSize() to directly find the size of an object. The size of an object in memory is implementation-dependent and not exposed through standard APIs. While Java provides methods to find the size of collections and arrays, there is no direct way to get the memory footprint of an object instance.