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 web technology
  1. validate()

  2. reset()

  3. validate() & reset ()

  4. none of these

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

ActionForm defines two key lifecycle methods: validate() for validating form inputs and reset() for resetting form properties to default values. Both methods are called by the controller at appropriate times - validate() before action execution and reset() before form population.

Multiple choice technology web technology
  1. Declarative Exception

  2. programmatic Exception

  3. both declarative and programmatic exception

  4. none of these

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

Struts supports both declarative exception handling (configured in struts-config.xml via global-exceptions and exception tags) and programmatic exception handling (using try-catch in Action classes or extending ExceptionHandler). Both approaches are valid and commonly used.

Multiple choice technology programming languages
  1. wait(), toString() only

  2. notify(), notifyall() only

  3. run(), stop()

  4. wait(),toString(),notify(), notifyall() and finalize()

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

The Object class in Java has methods like wait(), notify(), notifyAll(), toString(), equals(), hashCode(), and finalize(). Option D correctly lists wait(), toString(), notify(), notifyAll(), and finalize() - though it's not exhaustive (it misses equals() and hashCode()). Among the given options, D is the most complete and correct.

Multiple choice technology programming languages
  1. wait(), toString() only

  2. notify(), notifyall() only

  3. run(), stop()

  4. wait(),toString(),notify(), notifyall() and finalize()

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

The Java java.lang.Object class contains methods like wait(), toString(), notify(), notifyAll(), and finalize(). Methods like run() and stop() belong to the Thread or Runnable interfaces, not the Object class.

Multiple choice technology programming languages
  1. NullPointerException

  2. NumberFormatException

  3. ExceptionInInitializerError

  4. IllegalArgumentException

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

NullPointerException and ExceptionInInitializerError are standard exceptions thrown directly by the JVM. NumberFormatException and IllegalArgumentException are typically thrown by Java runtime library code (such as Integer.parseInt) rather than the JVM itself.

Multiple choice technology programming languages
  1. Option 1

  2. Option 2

  3. Option 1 & 2

  4. Option 3

  5. Option 2 & 3

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

Java requires that package statements must come before import statements, and both must appear before any class definitions. Option 1 violates this rule by placing import before package. Options 2 and 3 follow the correct order: package, then import, then class.

Multiple choice technology programming languages
  1. mid(2,s);

  2. charAt(2);

  3. s.indexOf('v');

  4. indexOf(s,'v');

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

The indexOf method returns the position of a specified character or substring within a string. For the string "Java", indexOf('v') returns 2 because it's zero-indexed (J=0, a=1, v=2). Option A and B reference non-existent methods, and option D has incorrect parameter order.

Multiple choice technology programming languages
  1. Sets all properties to their initial value

  2. Sets all properties to null

  3. Repopulates all properties from the request parameters

  4. None of the above

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

The reset() method in ActionForm does NOT set properties to initial values (A), does NOT set them to null (B), and does NOT repopulate from request parameters (C) - that's what populate() does. The default reset() implementation is typically empty, and subclasses override it to set specific default values, making 'None of the above' correct.

Multiple choice technology programming languages
  1. A blank page will be displayed.

  2. A page with the text Welcome is displayed

  3. An exception will be thrown because the implicit out object is not used

  4. An exception will be thrown because PrintWriter can be used in servlets only

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

The JSP page will display 'Welcome' because the code uses request.getWriter() which is valid in JSP. While JSP provides an implicit 'out' object, using PrintWriter directly is also allowed. The code correctly obtains a PrintWriter from the request object and writes 'Welcome' to it. There's no rule preventing PrintWriter usage in JSP - it's a valid Java object.

Multiple choice technology programming languages
  1. 33,123

  2. 123,33

  3. 6,6

  4. Compilation Error

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

Java evaluates arithmetic expressions from left to right. In 1+2+"3", the integers 1 and 2 are added to get 3, which is concatenated with "3" to yield "33". In "1"+2+3, the string "1" is concatenated with 2 and then 3, producing "123".