Java Thread Instantiation and Usage

CoolRhinoceros avatar
CoolRhinoceros
·
·
Download

Start Quiz

Study Flashcards

18 Questions

What is the correct way to execute a thread in Java?

By calling the start() method

What happens when you call the start() method on a thread that has already been started?

An IllegalThreadStateException is thrown

What is the default priority of a newly created thread in Java?

The same priority as the thread that created it

What is the primary thread that starts when a Java program is executed?

The main thread

What is the purpose of the run() method in a Java thread?

To execute the thread's code

What kind of scheduling algorithm is used in Java's runtime system?

Preemptive scheduling

What is a consequence of a thread being unable to gain regular access to shared resources?

Thread starvation

Which method of the Thread class is used to invoke the run() method?

start()

How can a Java program be made to use threading?

By extending the Thread class

What is the purpose of the setPriority() method in the Thread class?

To set the thread's priority

What is the purpose of the join() method in the Thread class?

To wait for the thread to finish

What is the name of the process in which each thread is given a period of time to run, and then all the other threads of equal priority get their turn at the CPU?

Time slicing

What is the result of instantiating a Thread using the default constructor?

Thread-0

Which Java Thread constructor allows you to specify the thread's name?

Thread(String name)

What happens in the run() method of a Java Thread?

It carries out the thread's task.

In which method do we usually call start() for a Java Thread object?

start()

What is printed with the statement 'System.out.println( 'In run! ' );' in the MyThread class?

In run!

What is the purpose of calling the start() method in a Java Thread?

To begin the execution of the thread

Learn how to instantiate a Thread in Java using default and String-based constructors, and explore how to put the thread to work. Understand the process of creating and working with threads in Java programming.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Java Threads Quiz
5 questions

Java Threads Quiz

SlickCarnelian3616 avatar
SlickCarnelian3616
Java Fundamentals Quiz
3 questions

Java Fundamentals Quiz

ProfuseJudgment avatar
ProfuseJudgment
Multi-threading in Java Networking
16 questions
Java Threads - Définition et lancement
10 questions
Use Quizgecko on...
Browser
Browser