Java MCQs on Basics of multithreading of Java Programming Language.
1. What is multithreaded programming? Answer: b 2. Which of these are types of multitasking? Answer: c 3. Thread priority in Java is? Answer: a 4. What will happen if two thread of the same priority are called to be processed simultaneously? Answer: d 5. Which of these statements is incorrect? Answer: d 6. What will be the output of the following Java code? a) Thread[5,main] 7. What is the priority of the thread in the following Java Program? a) 4 8. What is the name of the thread in the following Java Program? a) main
a) It’s a process in which two different processes run simultaneously
b) It’s a process in which two or more parts of same process run simultaneously
c) It’s a process in which many different process are able to access same information
d) It’s a process in which a single process can access information from many sources
Clarification: Multithreaded programming a process in which two or more parts of the same process run simultaneously.
a) Process based
b) Thread based
c) Process and Thread based
d) None of the mentioned
Clarification: There are two types of multitasking: Process based multitasking and Thread based multitasking.
a) Integer
b) Float
c) double
d) long
Clarification: Java assigns to each thread a priority that determines hoe that thread should be treated with respect to others. Thread priority is integers that specify relative priority of one thread to another.
a) Anyone will be executed first lexographically
b) Both of them will be executed simultaneously
c) None of them will be executed
d) It is dependent on the operating system
Clarification: In cases where two or more thread with same priority are competing for CPU cycles, different operating system handle this situation differently. Some execute them in time sliced manner some depending on the thread they call.
a) By multithreading CPU idle time is minimized, and we can take maximum use of it
b) By multitasking CPU idle time is minimized, and we can take maximum use of it
c) Two thread in Java can have the same priority
d) A thread can exist only in two states, running and blocked
Clarification: Thread exist in several states, a thread can be running, suspended, blocked, terminated & ready to run.
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,5,main]
Clarification: None.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[main,5,main]
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}
b) 5
c) 0
d) 1
Clarification: The output of program is Thread[main,5,main], in this priority assigned to the thread is 5. It’s the default value. Since we have not named the thread they are named by the group to they belong i:e main method.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[main,5,main]
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}
b) Thread
c) System
d) None of the mentioned
Clarification: The output of program is Thread[main,5,main], Since we have not explicitly named the thread they are named by the group to they belong i:e main method. Hence they are named ‘main’.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[main,5,main]