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

Which JavaScript function is used to get the value of an input field?

  1. getValue()

  2. getInputValue()

  3. getElementById()

  4. querySelector()

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

The querySelector() function is used to get the value of an input field. It takes a CSS selector as an argument and returns the first element that matches the selector.

Multiple choice

Which JavaScript function is used to add an event listener to an element?

  1. addEventListener()

  2. attachEvent()

  3. onclick()

  4. onmouseover()

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

The addEventListener() function is used to add an event listener to an element. It takes two arguments: the event type and the event handler function.

Multiple choice

Which of the following is a best practice for handling user input in mobile apps?

  1. Always validate user input

  2. Sanitize user input before processing

  3. Encode user input before storing it

  4. All of the above

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

To protect against input-based attacks, it's essential to validate, sanitize, and encode user input before processing or storing it.

Multiple choice

What is the correct syntax for accessing a property of an object in JavaScript?

  1. objectName.propertyName

  2. objectName['propertyName']

  3. Both of the above

  4. None of the above

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

In JavaScript, you can access a property of an object using the dot (.) operator or the square bracket ([]) notation. The dot operator is used when the property name is a valid JavaScript identifier, while the square bracket notation is used when the property name is not a valid JavaScript identifier.

Multiple choice

What is the correct syntax for calling a method of an object in JavaScript?

  1. objectName.methodName()

  2. objectName'methodName'

  3. Both of the above

  4. None of the above

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

In JavaScript, you can call a method of an object using the dot (.) operator or the square bracket ([]) notation. The dot operator is used when the method name is a valid JavaScript identifier, while the square bracket notation is used when the method name is not a valid JavaScript identifier.

Multiple choice

What is the bind() method in JavaScript?

  1. It creates a new function that, when called, has its this keyword set to the provided value.

  2. It creates a new function that, when called, has its arguments pre-filled with the provided values.

  3. It creates a new function that, when called, has its return value set to the provided value.

  4. None of the above

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

The bind() method in JavaScript creates a new function that, when called, has its this keyword set to the provided value. This is useful for creating functions that can be called with a specific context.

Multiple choice

What is the apply() method in JavaScript?

  1. It calls a function with a given this value and arguments provided as an array.

  2. It calls a function with a given this value and arguments provided as individual parameters.

  3. It calls a function with a given this value and no arguments.

  4. None of the above

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

The apply() method in JavaScript calls a function with a given this value and arguments provided as an array. This is useful for calling functions with a specific context and arguments.

Multiple choice

What is the call() method in JavaScript?

  1. It calls a function with a given this value and arguments provided as individual parameters.

  2. It calls a function with a given this value and arguments provided as an array.

  3. It calls a function with a given this value and no arguments.

  4. None of the above

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

The call() method in JavaScript calls a function with a given this value and arguments provided as individual parameters. This is useful for calling functions with a specific context and arguments.

Multiple choice

What is the difference between the bind(), apply(), and call() methods in JavaScript?

  1. The bind() method creates a new function, while the apply() and call() methods call an existing function.

  2. The apply() method takes an array of arguments, while the call() method takes individual arguments.

  3. The bind() method can only be used with arrow functions, while the apply() and call() methods can be used with any function.

  4. None of the above

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

The bind() method creates a new function that, when called, has its this keyword set to the provided value. The apply() and call() methods call an existing function with a given this value and arguments.

Multiple choice

What is the syntax for using the @Input decorator in Angular?

  1. @Input() name: string;

  2. @Input name: string;

  3. @Input('name') name: string;

  4. None of the above

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

To use the @Input decorator in Angular, you specify the name of the property that you want to receive data for in the @Input() decorator. The property must be defined in the component class.

Multiple choice

What is the syntax for using the @Output decorator in Angular?

  1. @Output() name: EventEmitter<string>;

  2. @Output name: EventEmitter<string>;

  3. @Output('name') name: EventEmitter<string>;

  4. None of the above

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

To use the @Output decorator in Angular, you specify the name of the event that you want to emit in the @Output() decorator. The event must be defined in the component class.

Multiple choice

What is the most common way to handle events 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

The onClick() event handler is a built-in event handler in React that is used to handle click events. It is the most common way to handle events in React.

Multiple choice

How do you prevent the default behavior of an event in React?

  1. Using the preventDefault() method

  2. Using the stopPropagation() method

  3. Using the cancelBubble property

  4. Using the return false statement

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

The preventDefault() method is used to prevent the default behavior of an event in React. It is the most common way to prevent the default behavior of an event.

Multiple choice

How do you stop the propagation of an event in React?

  1. Using the preventDefault() method

  2. Using the stopPropagation() method

  3. Using the cancelBubble property

  4. Using the return false statement

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

The stopPropagation() method is used to stop the propagation of an event in React. It prevents the event from bubbling up to the parent elements.

Multiple choice

How do you add an event listener to an element 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
A Correct answer
Explanation

The addEventListener() method is used to add an event listener to an element in React. It is the most common way to add an event listener to an element.