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
Which JavaScript function is used to get the value of an input field?
-
getValue()
-
getInputValue()
-
getElementById()
-
querySelector()
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.
Which JavaScript function is used to add an event listener to an element?
-
addEventListener()
-
attachEvent()
-
onclick()
-
onmouseover()
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.
Which of the following is a best practice for handling user input in mobile apps?
-
Always validate user input
-
Sanitize user input before processing
-
Encode user input before storing it
-
All of the above
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.
What is the correct syntax for accessing a property of an object in JavaScript?
-
objectName.propertyName
-
objectName['propertyName']
-
Both of the above
-
None of the above
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.
What is the correct syntax for calling a method of an object in JavaScript?
-
objectName.methodName()
-
objectName'methodName'
-
Both of the above
-
None of the above
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.
What is the bind() method in JavaScript?
-
It creates a new function that, when called, has its this keyword set to the provided value.
-
It creates a new function that, when called, has its arguments pre-filled with the provided values.
-
It creates a new function that, when called, has its return value set to the provided value.
-
None of the above
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.
What is the apply() method in JavaScript?
-
It calls a function with a given this value and arguments provided as an array.
-
It calls a function with a given this value and arguments provided as individual parameters.
-
It calls a function with a given this value and no arguments.
-
None of the above
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.
What is the call() method in JavaScript?
-
It calls a function with a given this value and arguments provided as individual parameters.
-
It calls a function with a given this value and arguments provided as an array.
-
It calls a function with a given this value and no arguments.
-
None of the above
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.
What is the difference between the bind(), apply(), and call() methods in JavaScript?
-
The bind() method creates a new function, while the apply() and call() methods call an existing function.
-
The apply() method takes an array of arguments, while the call() method takes individual arguments.
-
The bind() method can only be used with arrow functions, while the apply() and call() methods can be used with any function.
-
None of the above
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.
What is the syntax for using the @Input decorator in Angular?
-
@Input() name: string;
-
@Input name: string;
-
@Input('name') name: string;
-
None of the above
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.
What is the syntax for using the @Output decorator in Angular?
-
@Output() name: EventEmitter<string>;
-
@Output name: EventEmitter<string>;
-
@Output('name') name: EventEmitter<string>;
-
None of the above
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.
What is the most common way to handle events in React?
-
Using the addEventListener() method
-
Using the onClick() event handler
-
Using the onEvent() method
-
Using the handleEvent() method
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.
How do you prevent the default behavior of an event in React?
-
Using the preventDefault() method
-
Using the stopPropagation() method
-
Using the cancelBubble property
-
Using the return false statement
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.
How do you stop the propagation of an event in React?
-
Using the preventDefault() method
-
Using the stopPropagation() method
-
Using the cancelBubble property
-
Using the return false statement
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.
How do you add an event listener to an element in React?
-
Using the addEventListener() method
-
Using the onClick() event handler
-
Using the onEvent() method
-
Using the handleEvent() method
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.