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. Create new session if the session does not already exist

  2. Returns null if session does not already exist

  3. Returns false

  4. Destroy the session

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

Calling request.getSession(false) retrieves the current active session associated with the request. If no session exists, it returns null instead of creating a new one, which is useful for checking session validity without overhead.

Multiple choice technology web technology
  1. ExecuteNonQuery

  2. ExecuteQuery

  3. ExecuteReader

  4. ExecuteScalar

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

Command object methods: ExecuteNonQuery (INSERT/UPDATE/DELETE, returns rows affected), ExecuteReader (returns DataReader for SELECT), ExecuteScalar (returns single value like COUNT/aggregate). ExecuteQuery does not exist in ADO.NET.

Multiple choice technology platforms and products
  1. public DNAList init(DNA dnaIn) throws BMException;

  2. public DNAList execute(DNAList dnaIn) throws BMException;

  3. public DNA execute(DNA dnaIn) throws BMException;

  4. public DNA start(DNAList dnaIn) throws BMException;

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

The com.bluemartini.dna.Callback interface requires implementation of the execute() method, which takes a DNAList input parameter and returns a DNAList. This is the standard callback pattern for custom business logic execution in Blue Martini's DNA framework.

Multiple choice technology programming languages
  1. java.util.Collection

  2. java.lang.Collection

  3. java.util.Collections

  4. java.lang.Collections

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

Collection is in java.util package. java.lang is for core classes like String, Object. java.util.Collections (plural) is a utility class, not the Collection interface.

Multiple choice technology programming languages
  1. HashSet

  2. Vector

  3. HashMap

  4. TreeMap

  5. None of the above

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

The question requires storing currencies (keys) with USD prices (values) in a thread-safe manner. HashSet and HashMap are not synchronized. Vector is synchronized but is a List, not a Map. TreeMap is not inherently synchronized. Hashtable would be the correct synchronized Map choice, but it's not listed. Therefore 'None of the above' is correct.

Multiple choice technology programming languages
  1. java.util.HashSet

  2. java.util.LinkedHashMap

  3. java.util.Hashtable

  4. java.util.Vector

  5. none of these

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

The question asks for a collection that maintains entries by last-accessed order. HashSet doesn't maintain any access order. Hashtable is synchronized but doesn't track access order. Vector maintains insertion order, not access order. LinkedHashMap with accessOrder=true would be correct, but plain LinkedHashMap (default) maintains insertion order, not access order. Hence none of these are correct.

Multiple choice technology programming languages
  1. Throw AssertionError

  2. Throw IllegalStateException

  3. Throw IllegalArgumentException

  4. Throw InvalidArgumentException

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

In Java, IllegalArgumentException is the standard runtime exception thrown to indicate that a method has been passed an illegal or inappropriate argument. AssertionError is for internal invariants, and IllegalStateException is for invalid object states.

Multiple choice technology programming languages
  1. Exactly 10 seconds after the start method is called, "Time's Up!" will be printed.

  2. Exactly 10 seconds after "Start!" is printed, "Time's Up!" will be printed.

  3. The delay between "Start!" being printed and "Time's Up!" will be 10 seconds plus or minus one tick of the system clock.

  4. If "Time's Up!" is printed you can be sure that at least 10 seconds have elapsed since "Start!" was printed.

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

Thread.sleep(10000) guarantees that the thread will sleep for at least 10,000 milliseconds (10 seconds) before resuming, unless interrupted. It does not guarantee an exact execution time due to OS scheduling overhead, but it ensures at least 10 seconds have elapsed.