Question

Please help with Java test questions, I will post the rest of the question in separate...

Please help with Java test questions, I will post the rest of the question in separate post.

Question 1

Consider the following program:
public class CountDownApp3
{
    public static void main(String[] args)
    {
        Thread t1 = new CountDown();
        Thread t2 = new CountDown();
        t1.start();
        t2.start();
    }

}
Assuming that the CountDown class extends the Thread class, how many threads are used to run this program?

a.

3

b.

2

c.

4

d.

1

Question 2

From which of the following states can a thread not be moved into the Runnable state?

a.

Blocked

b.

New

c.

Waiting

d.

Terminated

  

Question 3

How long will a thread that executes the following statement sleep?
Thread.sleep(50);

a.

none of the above

b.

at most 50 milliseconds

c.

at least 50 milliseconds

d.

exactly 50 milliseconds

Question 4

To acquire a lock on an object, you can call

a.

the notify method

b.

a synchronized method

c.

the lock method

d.

the wait method

  

Question 5

What Java component controls the execution of threads?

a.

thread scheduler

b.

task controller

c.

run scheduler

d.

execution scheduler

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1:
The answer is Option B(2).

There are two threads mentioned in the code snippet(t1 and t2) which are started. So two threads used in the code snippet.


Question 2:
The answer is Option D(Terminated)

Once a Thread has been terminated it cannot be moved into the Runnable state. Whereas The thread can be moved from Blocked, New or waiting state.

Question 3:
The answer is Option D(Exactly 50 Milliseconds)

Thread.sleep() method is used to pause thread execution for a particular period of Time. The time can be specified in Milliseconds. In the above example(Thread.sleep(50)) it will stop the execution for 50 milliseconds.

Question 4:
The answer is Option B(Synchronized Method)

An object can be locked itself after executing the synchronized method.

Question 5:
The answer is Option A(Thread Scheduler)

Thread scheduler will decide which thread to execute. It will ensure that only one thread can be run at a time.

Add a comment
Know the answer?
Add Answer to:
Please help with Java test questions, I will post the rest of the question in separate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • Please help me to solve this problem with java language! write a program that runs a...

    Please help me to solve this problem with java language! write a program that runs a thread which prints a timestamp and then waits a second by doing the following: 1. Implement a class that implements the Runnable interface. (1 point) 2. Place the code for your task into the run method of your class. (6 points) a) To get the date and time, construct a Date object. b) To wait a second, use the sleep method of the Thread...

  • Consider the following codes: public class TestThread extends Thread {     public static void main(String[] args)...

    Consider the following codes: public class TestThread extends Thread {     public static void main(String[] args) {         TestThread thread = new TestThread();     }     @Override     public void run() {         printMyName();     }     private void printMyName() {         System.out.println("Thread is running");     } } Test Stem / Question Choices 1: What method should you invoke to start the thread TestThread? A: start() B: run() C: No. Thread will run automatically when executed. D: TestThread is not...

  • Hello, so I need someone to look over this code and see if im on the...

    Hello, so I need someone to look over this code and see if im on the right path. I feel like im missing something. Here is the assignment: Create a class called Slogans. This class will extend the Thread class. This thread will read from a file several quotes that are on each line. It will pick a quote randomly and display it to the console. It will change quotes every 7 seconds. This will be updated in the final...

  • Please use java Language Part I Implement a thread by extending the Thread class. Your thread...

    Please use java Language Part I Implement a thread by extending the Thread class. Your thread must do the following: (25 pts.) • Print its name and ID at the start. • Print the numbers from 1 to 100 that can be divided by 5. • Wait 1 second before printing a number. Part II Implement a thread by implementing the Runnable interface. Your thread must do the following: (25 pts.) • Print its name and ID at the start....

  • ******Java Programming Hi guys, I really need you help. I created a code for my java...

    ******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...

  • Write a program that will define a runnable frame to have a ball move across the...

    Write a program that will define a runnable frame to have a ball move across the frame left to right. While that is happening, have another frame that will let the user do something like click a button or input into a textfield, but keep the ball moving in the other frame. When the ball reaches the right edge of the frame or when the user takes action - enters in textfield or clicks the button, end the thread. The...

  • I have a multithreaded java sorting program that works as follows: 1. A list of double...

    I have a multithreaded java sorting program that works as follows: 1. A list of double values is divided into two smaller lists of equal size 2. Two separate threads (which we will term sorting threads) sort each sublist using a sorting algorithm of your choice 3. The two sublists are then merged by a third thread merging thread that merges the two sublists into a single sorted list. SIMPLE EXECUTION >java SortParallel 1000 Sorting is done in 8.172561ms when...

  • java  Operating System Scheduler Two scheduling strategies for an operating system scheduler are first come first serve...

    java  Operating System Scheduler Two scheduling strategies for an operating system scheduler are first come first serve (FCFS) and fixed priority pre-emptive scheduling (FPPS). Since queues operate on a first come first serve basis, FCFS is implemented using a queue. Similarly, FPPS is implemented using a priority queue. The operating system scheduler simulation is already provided for you. To use it you simply need to modify the main method to run the simulator using either the LinkedListQueue or the PriorityQueue. Run...

  • According to this cord use LongFifoWait Notify thread methord in CircularArrayLongFifo class. According to this cord...

    According to this cord use LongFifoWait Notify thread methord in CircularArrayLongFifo class. According to this cord use LongFifoWait Notify thread methord in CircularArrayLongFifo class. public class CandidateGenerator { private final LongFifo outputFifo; public CandidateGenerator(LongFifo outputFifo) { this.outputFifo = outputFifo; Runnable r = new Runnable() { @Override public void run() { runWork();}}; Thread t = new Thread(r, "CandidateGenerator"); t.start() } private void runWork() { try { outputFifo.add(2); long number = 3; while ( true ) { outputFifo.add(number); number += 2;} }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT