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
  1. another_variable_name

  2. Int

  3. myIdentifier

  4. variabletrackinghowmanyuserslogin

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

Java variable names should follow lowerCamelCase, starting with a lowercase letter and capitalizing the first letter of each subsequent word. 'myIdentifier' is the correct choice, whereas 'another_variable_name' uses snake_case and 'Int' starts with an uppercase letter.

Multiple choice
  1. public static int main(String args)

  2. public static void main(String arg)

  3. public static final main()

  4. public static void main(String[] args)

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

The standard entry point for any standalone Java application is the main method, which must be declared as 'public static void main(String[] args)'. This signature specifies that the method is accessible from anywhere, does not require an instance of the class to run, returns nothing, and accepts an array of String arguments.

Multiple choice

Which of the following is NOT a common refactoring technique?

  1. Extract method.

  2. Inline method.

  3. Move method.

  4. Rename method.

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

Inlining a method involves copying the code from the method into the caller, effectively removing the method from the codebase. This is generally not considered a good refactoring technique as it can lead to code duplication and make it harder to maintain.

Multiple choice

Which of the following is NOT a common refactoring pattern?

  1. Extract method.

  2. Move method.

  3. Inline method.

  4. Encapsulate field.

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

Inlining a method involves copying the code from the method into the caller, effectively removing the method from the codebase. This is generally not considered a good refactoring pattern as it can lead to code duplication and make it harder to maintain.

Multiple choice

Which of the following is NOT a common refactoring technique for improving the performance of a software application?

  1. Loop unrolling.

  2. Inlining.

  3. Method overriding.

  4. Data structure conversion.

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

Method overriding is not typically used for improving performance. It is a technique used in object-oriented programming to allow a subclass to provide its own implementation of a method inherited from a superclass.

Multiple choice

Which JavaScript method 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() method is used to add an event listener to an element, allowing you to specify the event type (such as 'click' or 'mouseover') and the function to be executed when the event occurs.

Multiple choice

Which JavaScript method is used to remove an element from the DOM?

  1. removeChild()

  2. remove()

  3. delete()

  4. detach()

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

The removeChild() method is used to remove an element from the DOM, allowing you to dynamically remove elements from the web page.

Multiple choice

What is the purpose of a throw statement?

  1. To raise an exception

  2. To catch an exception

  3. To handle an exception

  4. To prevent an exception

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

A throw statement is used to raise an exception. This means that it signals that an error has occurred, and that the program should stop executing.

Multiple choice

What is the best way to handle errors that occur in a thread?

  1. Use a try-catch block

  2. Use a throw statement

  3. Use an assert statement

  4. All of the above

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

The best way to handle errors that occur in a thread is to use a try-catch block.

Multiple choice

Which of the following is not a good practice for error handling in a thread?

  1. Use a try-catch block

  2. Use a throw statement

  3. Use an assert statement

  4. Ignore errors

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

Ignoring errors is not a good practice for error handling in a thread. It can lead to unexpected results and make it difficult to debug the program.

Multiple choice

Which design pattern is commonly used in mobile applications to handle asynchronous tasks?

  1. Singleton

  2. Factory

  3. Observer

  4. AsyncTask

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

AsyncTask is a design pattern commonly used in mobile applications to handle asynchronous tasks. It allows developers to perform long-running operations in the background without blocking the main thread. AsyncTask manages the lifecycle of the background task, including its execution, progress updates, and final result. This pattern helps maintain a responsive user interface while performing intensive tasks in the background.

Multiple choice

Which design pattern is commonly used in mobile applications to handle user input validation?

  1. Factory

  2. Singleton

  3. Observer

  4. Strategy

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

The Strategy design pattern is commonly used in mobile applications to handle user input validation. It allows developers to define a family of algorithms or strategies for performing a specific task, such as validating user input. The Strategy pattern provides a flexible and extensible way to handle different validation scenarios without modifying the core application logic. Developers can easily add or remove validation strategies as needed, making it easier to maintain and adapt the application to changing requirements.

Multiple choice

Which design pattern is used to provide a way to add or remove objects from a collection dynamically?

  1. Factory Method

  2. Strategy

  3. Observer

  4. Composite

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

The Composite pattern composes objects into tree structures to represent part-whole hierarchies. It lets clients treat individual objects and compositions of objects uniformly.

Multiple choice

Which design pattern is used to provide a way to undo or redo actions?

  1. Command

  2. Memento

  3. Observer

  4. Singleton

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

The Command pattern encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

Multiple choice

What is the purpose of the fetch API in JavaScript?

  1. To send HTTP requests

  2. To receive HTTP responses

  3. To parse JSON data

  4. All of the above

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

The fetch API in JavaScript can be used to send HTTP requests, receive HTTP responses, and parse JSON data.