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

What is the purpose of the Object.keys() method in JavaScript?

  1. To return an array of all the keys in an object

  2. To return an array of all the values in an object

  3. To return the number of keys in an object

  4. To return the number of values in an object

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

The Object.keys() method returns an array of all the keys in an object, in the same order as they were defined.

Multiple choice

Which of the following is not a valid way to access the properties of an object in JavaScript?

  1. object.property

  2. object['property']

  3. object[property]

  4. object.getProperty()

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

The object.getProperty() syntax is not a valid way to access the properties of an object in JavaScript. The correct syntax is object.property, object['property'], or object[property].

Multiple choice

What is the purpose of the Array.from() method in JavaScript?

  1. To convert an array-like object to an array

  2. To convert an array to an array-like object

  3. To create a new array with the same elements as an existing array

  4. To sort the elements of an array

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

The Array.from() method converts an array-like object (such as a string, a NodeList, or an HTMLCollection) to an array.

Multiple choice

Which of the following is not a valid way to iterate over the elements of an array in JavaScript?

  1. for (let i = 0; i < array.length; i++) { ... }

  2. for (const element of array) { ... }

  3. array.forEach((element, index) => { ... })

  4. array.map((element, index) => { ... })

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

The array.map() method is not a valid way to iterate over the elements of an array in JavaScript. It is a method that creates a new array with the results of calling a specified function on each element of the original array.

Multiple choice

What is the purpose of the Object.assign() method in JavaScript?

  1. To copy the properties of one object to another

  2. To merge two objects into a new object

  3. To create a new object with the same properties as an existing object

  4. To delete the properties of an object

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

The Object.assign() method copies the properties of one object to another. It can be used to merge two objects into a new object, or to create a new object with the same properties as an existing object.

Multiple choice

Which of the following is not a valid way to access the elements of an object in JavaScript?

  1. object.property

  2. object['property']

  3. object[property]

  4. object.getProperty()

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

The object.getProperty() syntax is not a valid way to access the properties of an object in JavaScript. The correct syntax is object.property, object['property'], or object[property].

Multiple choice

What is the purpose of the Array.prototype.reduce() method in JavaScript?

  1. To reduce an array to a single value

  2. To reduce an array to a new array

  3. To reduce an array to an object

  4. To reduce an array to a string

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

The Array.prototype.reduce() method reduces an array to a single value. The value is determined by a reduce function that is passed to the method.

Multiple choice

What is the purpose of the Object.freeze() method in JavaScript?

  1. To prevent an object from being modified

  2. To prevent an object from being deleted

  3. To prevent an object from being accessed

  4. To prevent an object from being serialized

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

The Object.freeze() method prevents an object from being modified. Once an object is frozen, its properties cannot be added, removed, or changed.

Multiple choice

Which of the following is not a valid way to iterate over the properties of an object in JavaScript?

  1. for (const property in object) { ... }

  2. for (const [property, value] of Object.entries(object)) { ... }

  3. object.forEach((property, value) => { ... })

  4. object.map((property, value) => { ... })

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

The object.forEach((property, value) =&gt; { ... }) syntax is not a valid way to iterate over the properties of an object in JavaScript. The correct syntax is for (const property in object) { ... }, for (const [property, value] of Object.entries(object)) { ... }, or object.map((property, value) =&gt; { ... }).

Multiple choice

Which lifecycle method is called when a React component is first mounted?

  1. componentDidMount()

  2. componentWillMount()

  3. render()

  4. constructor()

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

The componentDidMount() lifecycle method is called immediately after a component is mounted (inserted into the DOM). It is commonly used to perform side effects such as fetching data, setting up event listeners, or integrating with third-party libraries.

Multiple choice

Which JavaScript method is used to send an asynchronous HTTP request to a server?

  1. fetch()

  2. XMLHttpRequest()

  3. send()

  4. open()

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

The fetch() method is a modern and simplified way to make asynchronous HTTP requests in JavaScript.

Multiple choice

What is the syntax for using the fetch() method?

  1. fetch(url)

  2. fetch(url, options)

  3. fetch(url, data)

  4. fetch(url, headers)

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

The fetch() method takes two arguments: the URL of the resource to fetch and an optional options object.

Multiple choice

What is the default HTTP method used by the fetch() method?

  1. GET

  2. POST

  3. PUT

  4. DELETE

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

The default HTTP method used by the fetch() method is GET, which is used to retrieve data from a server.

Multiple choice

What is the purpose of the JSON.stringify() method?

  1. To convert a JavaScript object to a JSON string

  2. To convert a JSON string to a JavaScript object

  3. To parse a JSON string

  4. To validate a JSON string

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

The JSON.stringify() method converts a JavaScript object or value to a JSON string.

Multiple choice

What is the purpose of the JSON.parse() method?

  1. To convert a JavaScript object to a JSON string

  2. To convert a JSON string to a JavaScript object

  3. To parse a JSON string

  4. To validate a JSON string

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

The JSON.parse() method converts a JSON string to a JavaScript object.