Java Multiple Choice Questions & Answers on Multithreading Basics for Freshers

1. What is multithreaded programming?

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) Its a process in which many different process are able to access same information.
d) Its a process in which a single process can access information from many sources.

Answer: b

Explanation: multithreaded programming a process in which two or more parts of same process run simultaneously.
2. Which of these are types of multitasking?

a) 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. Which of these packages contain all the Java’s built in exceptions?

a) java.io
b) java.util
c) java.lang
d) java.net
Answer: c

4. Thread priority in Java is?

a) Integer
b) Float
c) double
d) long
Answer: a

Explanation: Java assigns to each thread a priority that determines hoe that thread should be treated with respect to others. Thread priority are integers that specify relative priority of one thread to another.
5. What will happen if two thread of same priority are called to be processed simultaneously?

a) Any one 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.
Answer: d

Explanation: 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.
6. Which of these statements is incorrect?

a) By multithreading CPU’s idle time is minimized, and we can take maximum use of it.
b) By multitasking CPU’s idle time is minimized, and we can take maximum use of it.
c) Two thread in Java can have same priority
d) A thread can exist only in two states, running and blocked.
Answer: d

Explanation: Thread exist in several states, a thread can be running, suspended, blocked, terminated & ready to run.
7. What is the output of this program?
  1.     class multithreaded_programing {
  2.         public static void main(String args[]) {
  3.             Thread t = Thread.currentThread();
  4.             System.out.println(t);        
  5.         }
  6.     }
a) Thread[5,main]
 b) Thread[main,5]
 c) Thread[main,0] 
d) Thread[main,5,main] 

Answer: d
8. What is the priority of the thread in output of this program?
  1.     class multithreaded_programing {
  2.         public static void main(String args[]) {
  3.             Thread t = Thread.currentThread();
  4.             System.out.println(t);        
  5.         }
  6.     }
a) 4
b) 5
c) 0
d) 1
Answer: b

Explanation: The output of program is Thread[main,5,main], in this priority assigned to the thread is 5. Its the default value. Since we have not named the thread they are named by the group to they belong i:e main method.
9. What is the name of the thread in output of this program?
  1.     class multithreaded_programing {
  2.         public static void main(String args[]) {
  3.             Thread t = Thread.currentThread();
  4.             System.out.println(t);        
  5.         }
  6.     }
a) main
b) Thread
c) System
d) None of the mentioned
Answer: a

Explanation: 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’.
10. What is the name of the thread in output of this program?
  1.     class multithreaded_programing {
  2.         public static void main(String args[]) {
  3.             Thread t = Thread.currentThread();
  4.             System.out.println(t.isAlive());        
  5.         }
  6.     }
a) 0
b) 1
c) true
d) false
Answer: c

Explanation: Thread t is seeded to currently program, hence when you run the program the thread becomes active & code ‘t.isAlive’ returns true.

Related

Data Structures Multiple choice Questions and Answers on Doubly Linked List

1. Which of the following is false about a doubly linked list? a) We can navigate in both the directionsb) It requires more space than a singly linked listc) The insertion and deletion of a node ta...

Data Structures Multiple Choice Questions and Answers on Stack using Linked List

1. What is the complexity of searching for a particular element in a Singly Linked List? a) O(n)b) O(1)c) lognd) nlogn Answer: a Explanation: Singly Linked List allows you to traverse in one dire...

Data Structures Multiple Choice Questions and Answers on Circular Linked List

1. What differentiates a circular linked list from a normal linked list? a) You cannot have the ‘next’ pointer point to null in a circular linked listb) It is faster to traverse the circular linked...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item