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. All implementations of the List interface provide fast random access.

  2. A LinkedList provides faster random access than an ArrayList.

  3. The LinkedList implements the RandomAccess interface.

  4. The RandomAccess interface declares the next and hasNext methods.

  5. None of the above.

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

Statement A is false - only implementations of RandomAccess (ArrayList, Vector) provide fast random access. Statement B is false - LinkedList has slower random access than ArrayList. Statement C is false - LinkedList does NOT implement RandomAccess. Statement D is false - RandomAccess is a marker interface with no methods. Thus 'None of the above' (E) is correct.

Multiple choice technology web technology
  1. Sets all properties to null values

  2. b. Sets all properties to their default values

  3. c. Repopulates the properties with their original values from request parameter

  4. d. None of the above

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

The default Reset method in Struts ActionForm does not set properties to null or default values. Instead, it resets the form to its initial state by repopulating properties with original values from the request parameters. However, this description is not exactly what the default reset() does - the default reset() method is actually empty and does nothing. Options B and C have formatting issues with 'b.' and 'c.' prefixes, making 'None of the above' the best choice.

Multiple choice technology web technology
  1. Object Oriented

  2. Write Once, Run Anywhere

  3. Compiled Programming language

  4. None of the above

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

While Java is object-oriented, its defining characteristic is 'Write Once, Run Anywhere' - the ability to compile to bytecode that runs on any platform with a JVM. This portability across different operating systems and hardware is Java's core advantage. Java is also compiled (to bytecode) but WORA is more distinctive.

Multiple choice technology programming languages
  1. True

  2. False

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

Java features automatic garbage collection for memory management. The JVM automatically reclaims memory from objects that are no longer reachable, handling the entire object lifecycle from allocation to deallocation. This eliminates manual memory management and common memory leaks.

Multiple choice technology programming languages
  1. a class that initializes the applet

  2. A required method in an applet

  3. A place to declare variablesA place to declare variables

  4. none of the above

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

To understand the purpose of this bit of code, the user needs to know that this is a method definition in Java. The method name "init" suggests that this code is related to initializing something, but more context is needed to determine what that something is.

Now, let's go through each option and explain why it is right or wrong:

A. A class that initializes the applet: This option is incorrect because this code does not define a class. It defines a method called "init". While this method may be used to initialize an applet, it is not itself a class.

B. A required method in an applet: This option is correct. In Java, "init" is a required method in applets. This method is called by the Java Virtual Machine (JVM) when the applet starts. It is used to perform any necessary initialization before the applet can be displayed.

C. A place to declare variables: This option is incorrect because this code does not declare any variables. It defines a method, which may use variables, but it does not itself declare any.

D. None of the above: This option is incorrect because option B is correct. "init" is a required method in applets.

Therefore, the answer is: B

Multiple choice technology testing
  1. GetVisibleText

  2. GetROProperty

  3. SetROProperty

  4. GetTOProperty

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

GetROProperty (Get Run-Time Object Property) in QTP/UFT retrieves the current property value of an object during test execution. This differs from GetTOProperty which retrieves test object properties from the Object Repository. RO properties reflect the actual state of the application at runtime.

Multiple choice technology testing
  1. True

  2. False

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

The statement claims that .Object method is not applicable in Firefox, which is false. Firefox supports standard JavaScript object methods like those on Object.prototype (toString, hasOwnProperty, etc.). The question likely refers to a proprietary IE-specific method, but as written, False is the correct answer.

Multiple choice technology web technology
  1. Vector is synchronized whereas arraylist is not

  2. ArrayList is synchronized whereas Vector is not

  3. Both are same

  4. None of the Above

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

Vector is a legacy Java collection class that is synchronized (thread-safe), whereas ArrayList is not synchronized, making ArrayList faster but not safe for unsynchronized multi-threaded access.

Multiple choice technology web technology
  1. Yes

  2. No

  3. Cannot be determined

  4. None of the above

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

When System.exit(0) is called, the JVM terminates immediately. This bypasses all normal flow control including the finally block - the finally block will NOT execute. System.exit() halts the JVM completely, so no further code runs. Option A is incorrect because finally is only guaranteed for normal control flow and exceptions, not JVM termination. Option C is incorrect - the behavior is deterministic and well-defined.

Multiple choice technology web technology
  1. destroy()

  2. start()

  3. run()

  4. none of the above

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

In Java, every Thread must implement the run() method, which contains the code that executes in the thread. The start() method is called to begin execution but is not implemented by subclasses - run() is the method you override with your thread's logic.