Sobes.tech
Junior — Middle

Have you used the Thread class object to perform parallel tasks in Java?

sobes.tech AI

Answer from AI

Yes, in Java, the Thread class can be used to perform parallel tasks. An object of Thread is created, and code for execution in a separate thread is passed to it.

Example of creating and starting a thread:

class MyThread extends Thread {
    public void run() {
        System.out.println("Thread started");
    }
}

MyThread t = new MyThread();
t.start(); // starts execution in a new thread

You can also implement the Runnable interface and pass it to a Thread.

In Android, using Thread is possible, but often higher-level mechanisms (such as AsyncTask, Handler, Executor) are used to better manage the lifecycle and interaction with the UI.

Have you used the Thread class object to perform… - sobes.tech