JAVA: Question Set – 03

JAVA: Question Set – 03

State the importance of the Comparable interface in Java.

The Comparable interface is used to order objects of the user-defined data type. It contains only one method known as the ‘compareTo(Object ob)’ method. The compareTo(Object ob) method is used to make a comparison of the object passed as a parameter and the current object. Based on the comparison, it returns either a positive, negative, or zero value.

What is a race condition in Java?

A race condition is a concurrent issue that is because of the parallel execution of the program by multiple threads. It is usually caused in the critical section. A race condition occurs when two threads operate on the same object and their operation interleaves on each other.

How is the Java platform independent?

The meaning of platform-independent is that we can run the same code on multiple platforms. Java is platform-independent because of bytecode and JVM. The java compiler is used to convert our code to bytecode. Because of this bytecode, Java is platform-independent. Bytecode can run on any platform which makes Java platform-independent.

Elaborate on the use of JTA or Java Transaction API.

The Java Transaction API (JTA) is an API that allows users to perform distributed transactions. It allows the users to start, commit, and roll back transactions. Basically, it is used to manage various types of transactions.

What is the Spring Framework in Java?

It is a lightweight Java application framework that is used to build Java applications. The infrastructure is handled by Spring so that the developer can focus on the application. Spring improves the efficiency as developers only have to write business logic.

What are the different states of the thread lifecycle?

There are 5 states of a thread: New, Active, Blocked/Waiting, Timed Waiting, and Terminated.

  • New- A thread is said to be in the New State when it is created. The execution hasn’t started yet.
  • Active- A thread moves to an Active state when it invokes the start() method.
  • Waiting/Blocked- Whenever a thread is inactive temporarily, it is either in the Waiting state or Blocked state.
  • Timed Waiting- To avoid Starvation, a thread is put in a Timed Waiting state.
  • Terminated state- In this state, the thread has been terminated and it is not there in the system.

Explain the meaning of the Daemon thread in Java.

The Daemon thread in Java is a low-priority thread. The Daemon thread performs background operations such as garbage collection, action listeners, and freeing unused memory. It is also called the service provider thread that provides services to the user thread.

Does Java support Multiple Inheritance? Justify.

No, Java does not support multiple inheritance to avoid issues arising due to ambiguity. An example of such an issue is the Diamond problem where you cannot extend more than one class. Multiple inheritance can be achieved by using interfaces.