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. Array: can store primitive ArrayList: Stores object only

  2. Array: fix size ArrayList: resizable

  3. Array: can have multi dimensional ArrayList: can have multi dimensional

  4. Array: lang ArrayList: Collection framework

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

Arrays are fixed-size, built-in language structures that can store primitives directly. ArrayList is a resizable class within the Collections Framework that only stores objects, utilizing autoboxing for primitives. Additionally, arrays natively support multi-dimensional syntax, whereas ArrayList does not, and Arrays are part of Java language basics while ArrayList is in java.util.

Multiple choice technology programming languages
  1. incSize(int minCapacity)

  2. ensureCapacity(int minCapacity)

  3. incCapicity(int minCapacity)

  4. All of the Above

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

ArrayList uses ensureCapacity(int minCapacity) to request internal capacity expansion before adding elements. This is an optimization to avoid multiple internal array resizes. Option A's 'incSize' and option C's 'incCapicity' (misspelled) don't exist in the API.

Multiple choice technology programming languages
  1. Returns String

  2. Returns an Array

  3. Returns a shallow copy of this ArrayList instance

  4. Returns Void

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

The clone() method in ArrayList returns a shallow copy - the ArrayList object itself is new, but the elements are references to the same objects (not deep copies). It doesn't return a String, Array, or void.

Multiple choice technology web technology
  1. Object

  2. Plain text

  3. xml

  4. e4x

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

When the class in Adobe Flex returns complex data (like XML or JSON), the default resultFormat is 'object'. This means the response is automatically parsed and converted into an ActionScript object structure. Other formats like 'xml', 'e4x', or 'text' must be explicitly specified if needed.

Multiple choice technology web technology
  1. Use the property called “data” in event Object

  2. Use the property called “payload” in event Object

  3. Create a Custom Event and have your own public variable to hold the data to be passed to the handler

  4. No way to do that.

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

The standard and most flexible way to pass custom data to an event handler is to create a custom Event class with public properties to hold the data. The base Event object does not have built-in properties like 'data' or 'payload' for arbitrary data. By extending Event and adding your own properties, you can type-safely pass any data needed by the handler.

Multiple choice technology programming languages
  1. True

  2. False

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

NullPointerException is an unchecked exception in Java because it inherits from RuntimeException. Checked exceptions must be declared in a method's throws clause or handled in a try-catch block, whereas unchecked exceptions represent programming errors occurring at runtime that do not require explicit handling.

Multiple choice technology programming languages
  1. True

  2. False

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

The statement "Declarations must appear at the start of the body of a Java method" is false.

In Java, variable declarations can appear anywhere within the body of a method, as long as they are declared before they are used. This allows for more flexibility in the design of a program and allows the programmer to declare variables closer to the point of their actual use, making the code more readable and easier to maintain.

Therefore, the correct answer is:

The Answer is: B. False

Multiple choice technology architecture
  1. doComplete()

  2. doCancel()

  3. doInit()

  4. doUpdate()

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

The doInit() method is the standard lifecycle method invoked when a page is first loaded or initialized in the PS Framework. doComplete() is called after successful form submission, doCancel() handles cancellation actions, and doUpdate() is for update operations during page lifecycle.

Multiple choice technology programming languages
  1. 3

  2. 1

  3. 2

  4. 0

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

Only one String object is created by 'new String("Cheese")'. The 'String strA;' declaration only creates a reference variable (null initially), not an object. In practice, this code would use a string literal instead, but technically only the 'new' keyword creates an object.

Multiple choice technology
  1. JB (jump back)

  2. JA (jump above)

  3. JO (jump if overflow)

  4. JMP (unconditional jump)

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

Standard conditional jump instructions in assembly include JA (Jump if Above), JO (Jump if Overflow), and JMP (unconditional jump). 'JB' is not a standard assembly mnemonic - the correct instruction for 'jump back' would be something like JMP with a negative offset or a loop instruction. The question asks which is NOT a jump instruction, and JB is indeed the invalid one.

Multiple choice technology
  1. Query length is limited in POST, not limited in GET.

  2. POST is secured whereas data is been submitted as part of URL in GET (not secured).

  3. By using POST method, we cannot submit the form.

  4. none

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

POST is more secure than GET because POST data is sent in the HTTP request body, not visible in the URL. GET appends form data to the URL, making it visible in browser history and server logs, and has length limitations (typically 2048 characters). POST can send much larger data and is the standard method for sensitive information like passwords. Option A incorrectly reverses the length limitations, and Option C is false.

Multiple choice technology
  1. HttpSession

  2. HttpServletResponse

  3. HttpServletRequest

  4. none

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

The HttpServletResponse interface provides the getWriter() method, which returns a PrintWriter object for sending character text data to the client. This is the standard way to write response content in servlets. HttpServletRequest (request) handles incoming data, HttpSession manages user sessions, and PrintWriter itself is the class returned, not the source of it. The leading period appears to be a typo but doesn't affect the question.

Multiple choice technology
  1. getAttribute()

  2. getParameter()

  3. getInitParameter()

  4. none

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

getAttribute() retrieves object-level attributes stored in the request scope. This is different from getParameter() which retrieves string form parameters from the query string or POST body, and getInitParameter() which retrieves servlet initialization parameters from web.xml. Attributes are typically set by the application using setAttribute() to share data between components, while parameters come from client requests.