Java Multithreading Mcq, java mcq


1. What is multithreaded programming?
A) It is a process in which two different processes run simultaneously
b) It is a process in which two or more parts of the same process run simultaneously
C) It is a process in which many different processes are able to access the same information
d) It is a process in which a single process can get information from many sources
Answer: B
Explanation: Multithreaded programming is a process in which two or more parts of the same process run simultaneously.

2. Which of the following is multitasking?
A) is process based
b) thread based
c) Process and thread based
d) none of the mentioned
Answer: C
Explanation: There are two types of multitasking: process based multitasking and thread based multitasking

3. Is thread priority in Java?
A) integer
B) float
C) double
D) long
Answer: A
Explanation: Java gives a priority to each thread that determines that the spade should be considered in relation to that thread. Thread priority is integer that assigns priority to one thread relative to another.

4. What if two threads of the same priority are asked to be processed simultaneously?
A) Anyone will be executed literally first
B) Both of them will be executed simultaneously
c) none of them will be executed
d) It depends on the operating system
Answer: D
Explanation: In cases where two or more threads with the same priority are competing for CPU cycles, different operating systems handle this situation differently. Some execute them sliced ​​in time, some they say based on thread.

5. Which of the following statements is incorrect?
a) Idle time is minimized by multithreading of CPU, and we can use it to the maximum
b) CPU idle time is minimized by multitasking, and we can use it to the maximum
C) In Java, two threads can have same priority
d) A thread can only exist in two states, running and blocking
Answer: D
Explanation: The thread exists in several states, a thread may be running, suspended, blocked, terminated and ready to run.

6. What will be the output of the following Java code?
Class multithreaded_programming
{
public static void main (String [] args[])
{
Thread t = thread.currentThread ();
Println (t);
}
}
a) thread [5, main]
B) thread [main, 5]
C) thread [main, 0]
D) Thread [main, 5, main]
Answer: D
Explanation: None.
Output: $ javac multithreaded_programing.java $ java multithreaded_programing thread [main, 5, main]

7. What is the priority of thread in the following Java programs?
Class multithreaded_programming
{
public static void main (String [] args[])
{
Thread t = thread.currentThread ();
Println (t);
}
}
a) 4
B) 5
C) 0
D) 1
Answer: B
Explanation: The output of the program is thread [main, 5, main], in this priority assigned to thread 5. This is the default value. Since we have not named the group they have named from the group which is i: e main method.
Output: $ javac multithreaded_programing.java $ java multithreaded_programing thread [main, 5, main]


8. Can this method be used to execute the main thread last in all threads?
A blockage
B) sleep ()
C) join ()
D) call ()
Answer: B
Explanation: By calling sleep () within the main (prior), to ensure that all of the child's threads terminate before the main thread.

9. This method is used to detect whether a thread is still running?
a) run ()
B) alive ()
C) is inactive ()
D) checkrun ()
Answer: C
Explanation: The eyelive () method returns true if the thread on which it is called is still running. This is otherwise incorrect.

10. What is the default value of priority variables MIN_PRIORITY and MAX_PRIORITY?
a) 0 & 256
B) 0 and 1
C) 1 and 10
d) 1 and 256
Answer: C
Explanation: None.

11. Which of the following methods wait for the thread to finish?
A) sleep ()
B) passive ()
C) join ()
D) Stop ()
Answer: C
Explanation: None.

12. Which method is used to explicitly determine the priority of a thread?
A) One set ()
B) make B ()
C) setparity ()
D) Makeperity ()
Answer: C
Explanation: The default value of priority given to a thread is 5 but we can explicitly change that value between allowed values ​​1 and 10, this method is done using setPerity ().

13. What is synchronization in terms of a formula?
A) is a process of handling situations when two or more threads require access to a shared resource
B) It is a process by which multiple threads are able to access the same shared resource
C) It is a process by which a method is able to access many different threads simultaneously.
D) This is a method that allows multiple threads to require any information.
Answer: A
Explanation: When two or more threads need to access the same shared resource, they need some way to ensure that the resource is used.
Previous Post Next Post