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

  2. int

  3. TextField

  4. String

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

The setLabel method is typically used with UI component objects to set their display label. Among the options, DoubleField represents an object (a UI component field), while int is a primitive and TextField/String are different types. Option A DoubleField is the correct object type that would have a setLabel() method.

Multiple choice technology programming languages
  1. void

  2. String

  3. ActionForward

  4. ActionMapping

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

In Struts 1.x, the execute() method in Action class returns ActionForward, which represents the destination to which the controller should forward the request. This object contains the path information and can be configured to perform a redirect instead of a forward. The method signature is 'public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)'

Multiple choice technology programming languages
  1. ActionErrors

  2. ActionError

  3. void

  4. ActionMapping

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

The reset() method in ActionForm has return type void. This method is called by the Struts controller to reset the form bean's properties to default values before populating it with new request parameters. The method signature is 'public void reset(ActionMapping mapping, HttpServletRequest request)'. It's not used for validation (that's validate() which returns ActionErrors).

Multiple choice technology programming languages
  1. MappingDispatchAction

  2. MethodDispatchAction

  3. EventDispatchAction

  4. LookUpDispatchAction

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

MethodDispatchAction does not exist in Apache Struts framework. The actual subclasses of DispatchAction include MappingDispatchAction and LookupDispatchAction (note: the correct spelling is 'Lookup' not 'LookUp'). EventDispatchAction is also not a standard Struts class, but the question identifies MethodDispatchAction as the answer.

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 is meant to reset properties to their default values, but it's not automatically implemented to set all properties to null or initial values. Developers must override this method to define what 'reset' means for their specific form. Option C describes what populate/reset cycle does, not reset alone. Option D is correct because none of A, B, or C accurately describe the default behavior.

Multiple choice technology programming languages
  1. valuator()

  2. reset()

  3. findForward()

  4. execute()

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

The execute() method is the core method that every Action class must implement. It handles the request processing logic and returns an ActionForward that determines the view to display. Other methods like reset() belong to ActionForm, and findForward() is called ON an ActionMapping, not implemented BY Action.

Multiple choice technology programming languages
  1. ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response.

  2. Mapping mapping, ActionForm form, ServletRequest request, ServletResponse response.

  3. ActionMapping mapping, Form form, ServletRequest request, ServletResponse response.

  4. ActionMapping mapping, ActionForm form, ServletRequest request, Response response.

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

The execute() method in Struts Action class takes four parameters: ActionMapping (configuration information), ActionForm (form bean with request parameters), ServletRequest (HTTP request), and ServletResponse (HTTP response). Option B is wrong because 'Mapping' is not a type. Option C is wrong because 'Form' is not a type. Option D is wrong because 'Response' is not a type.

Multiple choice technology programming languages
  1. In Action class

  2. In ActionForm Class

  3. In ActionMapping Class

  4. In ActionServlet Class

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

In Struts, the key for dispatch actions (like LookupDispatchAction) is generated and stored in the ActionMapping, which contains the configuration information from struts-config.xml. The ActionMapping holds the parameter name that will be used to determine which method to execute. This is part of the mapping configuration.

Multiple choice technology programming languages
  1. public void reset(ActionMapping mapping, HttpServletReuest reuest)

  2. public ActionErrors reset(ActionMapping mapping, HttpServletReuest reuest)

  3. public ActionError reset(ActionMapping mapping, HttpServletReuest reuest)

  4. None of the above

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

The reset() method in ActionForm returns void and takes ActionMapping and HttpServletRequest as parameters. Option A is correct despite the typos ('HttpServletReuest' and 'reuest'). Options B and C are incorrect because they return ActionErrors/ActionError, which is what validate() returns, not reset(). The purpose of reset() is to initialize form properties, not return validation errors.

Multiple choice technology programming languages
  1. setter,reset

  2. Initialization,setter,reset

  3. setter,reset,Initialization

  4. reset,Initialization,setter

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

ActionForm follows this lifecycle: the form bean is initialized/created, setter methods populate it with request parameters, and reset() is called. Option B correctly sequences these phases.

Multiple choice technology programming languages
  1. ActionErrors

  2. ActionForward

  3. ActionMapping

  4. ActionError

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

To answer this question, the user needs to know about the validate() method of ActionForm in Java.

The validate() method of ActionForm is used to validate the form data submitted by the user. It returns an object of the ActionErrors class, which contains a list of errors that occurred during the validation process.

Therefore, the correct answer is:

The Answer is: A. ActionErrors

Multiple choice technology programming languages
  1. public void execute(ActionMapping mapping, ActionForm form, HttpServletReuest reuest, HttpServletResponse response) throws IOException

  2. public ActionForward execute (ActionMapping mapping, ActionForm form, ServletReuest reuest, ServletResponse response) throws Exception

  3. public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletReuest reuest, HttpServletResponse response) throws Exception

  4. public ActionForward execute (ActionMapping mapping, ActionForm form, ServletReuest reuest, ServletResponse response) throws SevletException, IOExpection.

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

The standard signature of the Struts Action class execute method returns an ActionForward object and accepts ActionMapping, ActionForm, HttpServletRequest, and HttpServletResponse arguments while throwing Exception. Despite minor typographical errors in the options, this signature correctly matches the framework's design, whereas other options have incorrect return types or parameter classes.

Multiple choice technology programming languages
  1. public ActionErrors validate(ActionMapping mapping,HttpServletReuest reuest)

  2. public ActionError validate(ActionMapping mapping, HttpServletReuest reuest)

  3. public ActionError validate(HttpServletReuest reuest, HttpServletResponse response)

  4. None of the above

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

The validate() method signature is public ActionErrors validate(ActionMapping mapping, HttpServletRequest request). It returns ActionErrors (plural) to collect multiple validation failures, and accepts the mapping and request objects.