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

How do you remove an event listener from an element in React?

  1. Using the removeEventListener() method

  2. Using the onClick() event handler

  3. Using the onEvent() method

  4. Using the handleEvent() method

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

The removeEventListener() method is used to remove an event listener from an element in React. It is the most common way to remove an event listener from an element.

Multiple choice

Which of the following is not a valid way to define an event handler in the component class in React?

  1. Using the onClick() method

  2. Using the onChange() method

  3. Using the onSubmit() method

  4. Using the handleEvent() method

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

handleEvent() method is not a valid way to define an event handler in the component class in React. The valid ways to define an event handler in the component class are using the onClick(), onChange(), and onSubmit() methods.

Multiple choice

Which of the following is not a valid way to implement event delegation in React?

  1. Using the addEventListener() method

  2. Using the onClick() event handler

  3. Using the onEvent() method

  4. Using the handleEvent() method

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

onClick() event handler is not a valid way to implement event delegation in React. The valid ways to implement event delegation in React are using the addEventListener(), onEvent(), and handleEvent() methods.

Multiple choice

Which of the following is a valid way to initialize state in a React component?

  1. Using the useState hook

  2. Using the setState method

  3. Using the constructor method

  4. Using the componentDidMount method

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

The useState hook is the preferred way to initialize state in a React component. It allows you to declare a state variable and its initial value in a single line of code.

Multiple choice

Which lifecycle method is called when a React component is about to be updated?

  1. componentDidMount

  2. componentWillMount

  3. componentDidUpdate

  4. componentWillUpdate

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

The componentWillUpdate lifecycle method is called when a React component is about to be updated. It is a good place to perform tasks such as updating the state of the component based on the new props.

Multiple choice

Which lifecycle method is called when a React component has been updated?

  1. componentDidMount

  2. componentWillMount

  3. componentDidUpdate

  4. componentWillUpdate

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

The componentDidUpdate lifecycle method is called when a React component has been updated. It is a good place to perform tasks such as updating the UI of the component based on the new state.

Multiple choice

Which lifecycle method is called when a React component is about to be unmounted?

  1. componentDidMount

  2. componentWillMount

  3. componentDidUpdate

  4. componentWillUnmount

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

The componentWillUnmount lifecycle method is called when a React component is about to be unmounted. It is a good place to perform tasks such as cleaning up event listeners or timers.

Multiple choice

Which lifecycle method is called when a React component receives new props?

  1. componentDidMount

  2. componentWillMount

  3. componentDidUpdate

  4. componentWillReceiveProps

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

The componentWillReceiveProps lifecycle method is called when a React component receives new props. It is a good place to perform tasks such as updating the state of the component based on the new props.

Multiple choice

Which lifecycle method is called when a React component is about to be destroyed?

  1. componentDidMount

  2. componentWillMount

  3. componentDidUpdate

  4. componentWillUnmount

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

The componentWillUnmount lifecycle method is called when a React component is about to be destroyed. It is a good place to perform tasks such as cleaning up event listeners or timers.

Multiple choice

Which of the following is not a valid lifecycle method in React?

  1. componentDidMount

  2. componentWillMount

  3. componentDidUpdate

  4. componentWillUpdate

  5. componentWillReceiveProps

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

componentWillReceiveProps is not a valid lifecycle method in React. It was deprecated in React 16.3 and should no longer be used.

Multiple choice

What is the purpose of the useCallback hook in React?

  1. To memoize a callback function

  2. To update the state of a React component

  3. To fetch data from an API

  4. To set up event listeners

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

The useCallback hook is used to memoize a callback function. This means that the callback function will only be recreated if one of its dependencies changes.

Multiple choice

What is the purpose of the useMemo hook in React?

  1. To memoize a value

  2. To update the state of a React component

  3. To fetch data from an API

  4. To set up event listeners

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

The useMemo hook is used to memoize a value. This means that the value will only be recalculated if one of its dependencies changes.

Multiple choice

Which of the following is not a built-in method of JavaScript arrays?

  1. push()

  2. pop()

  3. shift()

  4. filter()

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

The filter() method is not a built-in method of JavaScript arrays. It is a method of the Array.prototype object, which is added to all arrays by default.

Multiple choice

What is the purpose of the join() method in JavaScript arrays?

  1. To join all the elements of an array into a single string

  2. To add an element to the end of an array

  3. To remove the last element from an array

  4. To sort the elements of an array

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

The join() method joins all the elements of an array into a single string, separated by a specified separator.

Multiple choice

Which of the following is not a built-in method of JavaScript objects?

  1. hasOwnProperty()

  2. toLocaleString()

  3. valueOf()

  4. forEach()

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

The forEach() method is not a built-in method of JavaScript objects. It is a method of the Object.prototype object, which is added to all objects by default.