Computer Knowledge

Java Core Classes and Threads

1,473 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. getInitParameterNames()

  2. getInitParameter(String name)

  3. getServletName()

  4. getServletContext()

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

The getInitParameter(String name) method of a Servlet returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. Other methods like getServletContext() do not return null.

Multiple choice technology programming languages
  1. A. Arrays.sort(s);

  2. B. s = new TreeSet(s);

  3. C. Collections.sort(s);

  4. D. s = new SortedSet(s);

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

To sort the keys in the props HashMap, the user needs to know about the different data structures available in Java that can help to sort a collection of keys. The user also needs to know about the methods provided by the Java Collections framework that can be used to perform sorting on collections.

Option A: Arrays.sort(s); is incorrect. The Arrays.sort() method is used to sort arrays, not sets or maps. It will result in a compilation error.

Option B: s = new TreeSet(s); is correct. A TreeSet is a sorted set that orders its elements based on their natural ordering or based on a comparator provided at the time of creation. By creating a new TreeSet using the Set of keys from the props HashMap, the keys will be automatically sorted.

Option C: Collections.sort(s); is incorrect. The Collections.sort() method is used to sort lists, not sets or maps. It will result in a compilation error.

Option D: s = new SortedSet(s); is incorrect. SortedSet is an interface and cannot be instantiated. Moreover, the Set obtained from the props HashMap is already sorted.

Therefore, the correct answer is:

The Answer is: B. s = new TreeSet(s);

Multiple choice technology programming languages
  1. addSize

  2. getCust

  3. deleteRep

  4. putDimensions

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

JavaBeans getter methods follow the pattern get where the property name starts lowercase. getCust() correctly accesses a property named cust. The other options don't follow JavaBeans conventions: addSize sounds like a bulk operation, deleteRep and putDimensions don't use the get prefix for accessors.

Multiple choice technology web technology
  1. A required input was not set or mapped and so did not exist at run-time

  2. The "switch" variable of a Branch operation in the Flow was NULL at run-

  3. The Flow executed an Exit operation with the "signal failure" option

  4. A Loop operation in the Flow service has no input array defined

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

A NullPointerException in Flow tracing most commonly occurs when trying to access a pipeline variable that doesn't exist because a required input wasn't set or mapped. Options B, C, and D cause different errors (branch on NULL, exit signal failure, or no loop array), not necessarily NPE.

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
A Correct answer
Explanation

In Java, a top-level class cannot be private - only public, abstract, and final are allowed. The code attempts to declare "private class AQuestion" which violates this rule. Therefore, the code does not compile. If it were a valid inner class, the overload resolution would select the more specific String method for null argument.

Multiple choice technology web technology
  1. Cookie class can not take parameters in it's constructor

  2. The request object is used for creating cookies

  3. Although no error will be reported the use of the <jsp:include/> action means that the response object can't be used to create cookies

  4. The <jsp:include/> action must be placed inside the script block

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

The action flushes the response buffer before including the target resource. Once headers are sent (which happens during the flush), you cannot set cookies because cookies require HTTP headers. Any attempt to add cookies via response.addCookie() after a jsp:include will fail or be ignored.

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