Java Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Java Programming MCQ (Multiple Choice Questions)

 Que-  What is the use of try & catch?

a. It allows us to manually handle the exception

b. It allows to fix errors

c. It prevents automatic terminating of the program in cases when an exception occurs

d. All of the mentioned


Answer- All of the mentioned


Que-  Which of these keywords are used for the block to be examined for exceptions?

a. try

b. catch

c. throw

d. check


Answer- try


Que-  Which of these keywords are used for the block to handle the exceptions generated by try block?

a. try

b. catch

c. throw

d. check


Answer- catch


Que-  Which of these keywords are used for generating an exception manually?

a. try

b. catch

c. throw

d. check


Answer- throw


Que-  Which of these statements is incorrect?

a. try block need not to be followed by catch block

b. try block can be followed by finally block instead of catch block

c. try can be followed by both catch and finally block

d. try need not to be followed by anything


Answer- try need not to be followed by anything


Que-  Which of these classes is used to define exceptions?

a. Exception

b. Throwable

c. Abstract

d. System


Answer- Exception


Que-  Which of these methods return description of an exception?

a. getException()

b. getMessage()

c. obtainDescription()

d. obtainException()


Answer- getMessage()


Que-  Which of these methods is used to print stack trace?

a. obtainStackTrace()

b. printStackTrace()

c. getStackTrace()

d. displayStackTrace()


Answer- printStackTrace()


Que-  Which of these methods return localized description of an exception?

a. getLocalizedMessage()

b. getMessage()

c. obtainLocalizedMessage()

d. printLocalizedMessage()


Answer- getLocalizedMessage()


Que-  Which of these classes is super class of Exception class?

a. Throwable

b. System

c. RunTime

d. Class


Answer- Throwable


Que-  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. 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


Answer- It's a process in which two or more parts of same process run simultaneously


Que-  Which of these are types of multitasking?

a. Process based

b. Thread based

c. Process and Thread based

d. None of the mentioned


Answer- Process and Thread based


Que-  Thread priority in Java is?

a. Integer

b. Float

c. double

d. long


Answer- Integer


Que-  What will happen if two thread of the same priority are called to be processed simultaneously?

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


Answer- It is dependent on the operating system


Que-  Which of these statements is incorrect?

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


Answer- A thread can exist only in two states, running and blocked


Que-  What requires less resources?

a. Thread

b. Process

c. Thread and Process

d. Neither Thread nor Process


Answer- Thread


Que-  What does not prevent JVM from terminating?

a. Process

b. Daemon Thread

c. User Thread

d. JVM Thread


Answer- Daemon Thread


Que-  What decides thread priority?

a. Process

b. Process scheduler

c. Thread

d. Thread scheduler


Answer- Thread scheduler


Que-  What is true about time slicing?

a. Time slicing is OS service that allocates CPU time to available runnable thread

b. Time slicing is the process to divide the available CPU time to available runnable thread

c. Time slicing depends on its implementation in OS

d. Time slicing allocates more resources to thread


Answer- Time slicing is the process to divide the available CPU time to available runnable thread


Que-  Deadlock is a situation when thread is waiting for other thread to release acquired object.

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-TRUE


Que-  What should not be done to avoid deadlock?

a. Avoid using multiple threads

b. Avoid hold several locks at once

c. Execute foreign code while holding a lock

d. Use interruptible locks


Answer- Execute foreign code while holding a lock


Que-  What is true about threading?

a. run() method calls start() method and runs the code

b. run() method creates new thread

c. run() method can be called directly without start() method being called

d. start() method creates new thread and calls code written in run() method


Answer- start() method creates new thread and calls code written in run() method


Que-  Which of the following is a correct constructor for thread?

a. Thread(Runnable a, String str)

b. Thread(int priority)

c. Thread(Runnable a, int priority)

d. Thread(Runnable a, ThreadGroup t)


Answer- Thread(Runnable a, String str)


Que-  Which of the following stops execution of a thread?

a. Calling SetPriority() method on a Thread object

b. Calling notify() method on an object

c. Calling wait() method on an object

d. Calling read() method on an InputStream object


Answer- Calling notify() method on an object


Que-  Which of the following will ensure the thread will be in running state?

a. yield()

b. notify()

c. wait()

d. Thread.killThread()


Answer- wait()


Que-  Which of this method can be used to make the main thread to be executed last among all the threads?

a. stop()

b. sleep()

c. join()

d. call()


Answer- sleep()


Que-  Which of this method is used to find out that a thread is still running or not?

a. run()

b. Alive()

c. isAlive()

d. checkRun()


Answer- isAlive()


Que-  What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY?

a. 0 & 256

b. 0 & 1

c. 1 & 10

d. 1 & 256


Answer- 1 & 10


Que-  Which of these method waits for the thread to terminate?

a. sleep()

b. isAlive()

c. join()

d. stop()


Answer- join()


Que-  Which of these method is used to explicitly set the priority of a thread?

a. set()

b. make()

c. setPriority()

d. makePriority()


Answer- setPriority()


Que-  What is synchronization in reference to a thread?

a. It's a process of handling situations when two or more threads need access to a shared resource

b. It's a process by which many thread are able to access same shared resource simultaneously

c. It's a process by which a method is able to access many different threads simultaneously

d. It's a method that allow too many threads to access any information require


Answer- It's a process of handling situations when two or more threads need access to a shared resource

Previous Post Next Post