Java Threads - online test

Java Threads - online test


1) The life cycle of the thread is controlled by ?

A) JVM
B) JDK
C) JRE
D) None of the above
View Answer / Hide Answer

ANSWER: A) JVM




2) In how many states Threads can be explained ?

A) 4
B) 5
C) 3
D) 2
View Answer / Hide Answer

ANSWER: B) 5




3) In which state the thread is still alive, but is currently not eligible to run?

A) Non-Runnable
B) Terminated
C) Runnable
D) Running
View Answer / Hide Answer

ANSWER: A) Non-Runnable




4) In Which state after invocation of start() method, but the thread Scheduler has not selected it to be the running thread?

A) Running
B) Runnable
C) Terminated
D) Non-Runnable
View Answer / Hide Answer

ANSWER: B) Runnable




5) These two ways are used to?

By extending Thread class
By implementing Runnable interface.

A) Joining a thread
B) Naming a thread
C) Create a thread
D) sleeping a thread
View Answer / Hide Answer

ANSWER: C) Create a thread




6) Which method is used in thread class to starts the execution of the thread.JVM calls the run() method on the thread?

A) public void start()
B) public void run()
C) public void stop()
D) public coid suspend()
View Answer / Hide Answer

ANSWER: A) public void start()




7) Which method is used in thread class to tests if the current thread has been interrupted?

A) public static boolean interrupted()
B) public boolean isInterrupted()
C) public void interrupt()
D) public boolean isAlive()
View Answer / Hide Answer

ANSWER: A) public static boolean interrupted()




8) Which method in thread class causes the currently executing thread object to temporarily pause and allow other threads to execute?

A) public boolean isAlive()
B) public int getId()
C) public void yield()
D) public boolean isDaemon()
View Answer / Hide Answer

ANSWER: C) public void yield()




9) Thread class constructor allocates a new thread object?

A) True
B) False
View Answer / Hide Answer

ANSWER: A) True




10) Many threads at a time can run in a single process?

A) True
B) False
View Answer / Hide Answer

ANSWER: B) False




11) Under Which scheduling the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence?

A) Under time slicing
B) Under Preemptive scheduling
C) Under Pretime slicing
D) None of the above
View Answer / Hide Answer

ANSWER: B) Under Preemptive scheduling




12) How many methods does a thread class provides for sleeping a thread?

A) 3
B) 1
C) 4
D) 2
View Answer / Hide Answer

ANSWER: D) 2




13) Can we start a thread twice?

A) Yes
B) No
View Answer / Hide Answer

ANSWER: B) No




14) What if we call run() method directly instead start() method?

A) Each thread starts in a separate call stack.
B) Invoking the run() method from main thread, the run() method goes onto the current call stack rather than at the beginning of a new call stack
C) Both A & B
D) None of the above
View Answer / Hide Answer

ANSWER: C) Both A & B




15) Which method waits for a thread to die?

A) stop()
B) start()
C) terminate()
D) join()
View Answer / Hide Answer

ANSWER: D) join()




16) Which method returns a reference to the currently executing thread object?

A) currentThread()
B) runningThread()
C) runnableThread()
D) None of the above
View Answer / Hide Answer

ANSWER: A) currentThread()




17) In Naming a thread which method is used to change the name of a thread?

A) public String getName()
B) public void setName(String name).
C) public void getName()
D) public String setName(String name)
View Answer / Hide Answer

ANSWER: B) public void setName(String name)




18) Default priority value of a thread class for NORM_PRIORITY is?

A) 1
B) 10
C) 5
D) 4
View Answer / Hide Answer

ANSWER: C) 5




19) This is an example for priority of a thread give the output for the following program ?
class Multi10 extends Thread{
public void run(){
System.out.println("running thread name is:"+Thread.currentThread().getName());
System.out.println("running thread priority is:"+Thread.currentThread().getPriority());

}
public static void main(String args[]){
Multi10 m1=new Multi10();
Multi10 m2=new Multi10();
m1.setPriority(Thread.MIN_PRIORITY);
m2.setPriority(Thread.MAX_PRIORITY);
m1.start();
m2.start();

}
}
A) running thread name is:Thread-0
running thread priority is:1
running thread name is:Thread-1
running thread priority is:5
B) running thread name is:Thread-0
running thread priority is:10
running thread name is:Thread-1
running thread priority is:1
C) running thread name is:Thread-0
running thread priority is:5
running thread name is:Thread-1
running thread priority is:1
D) None of the above
View Answer / Hide Answer

ANSWER: B)




20) Daemon thread provides services to user threads for background supporting tasks,It has no role in life than to serve user threads?

A) True
B) False
View Answer / Hide Answer

ANSWER: A) True




21) If you want to make a user thread as Daemon, it must not be started otherwise it will throw IllegalThreadStateException?

A) True
B) False
View Answer / Hide Answer

ANSWER: A) True




22) In which Thread pool is used where container creates a thread pool to process the request?

A) Servlet
B) JSp
C) Both A & B
D) None of the above
View Answer / Hide Answer

ANSWER: C) Both A & B




23) Which is the capability of control the access of multiple threads to any shared resource?

A) Serialization
B) Synchronization
C) Internationalization
D) None of the above
View Answer / Hide Answer

ANSWER: B) Synchronization




24) Mutual exclusive and inter-thread communication are two types of Synchorization for ?

A) Thread Synchronization
B) Process Synchronization
C) Object Synchronization
D) None of the above
View Answer / Hide Answer

ANSWER: A) Thread Synchronization




25) Which helps to keep threads from interfering with one another while sharing data. This can be done by three ways in java:

1.by synchronized method
2.by synchronized block
3.by static synchronization

A) Inter-thread communication
B) Mutual Exclusive
C) Initial-thread communication
D) None of the above
View Answer / Hide Answer

ANSWER: B) Mutual Exclusive




26) The following two methods in Synchronization block is correct or not?
Synchronized block is not used to lock an object for any shared resource.
Scope of synchronized block is larger than the method.

A) True
B) False
View Answer / Hide Answer

ANSWER: A) True




27) If you make any static method as synchronized, the lock will be on the?

A) class not on object
B) object
C) class
D) object not on class
View Answer / Hide Answer

ANSWER: A) class not on object




28) Both threads are waiting for each other to release the lock, the condition is called deadlock?

A) True
B) False
View Answer / Hide Answer

ANSWER: A) True




29) In which mechanism a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed?

A) Inter-thread communication
B) Initial-thread communication
C) Mutual Exclusive
D) None of the above
View Answer / Hide Answer

ANSWER: A) Inter-thread communication




30) In inter-thread communication in java the following method is used for public final void wait(long timeout)throws InterruptedException?

A) waits until object is notified
B) waits for the specified amount of time
C) waits until object is released
D) None of the above
View Answer / Hide Answer

ANSWER: B) waits for the specified amount of time




31) Which method returns the interrupted flag afterthat it sets the flag to false if it is true?

A) isInterrupted()
B) static interrupted()
C) non static interrupted()
D) Both A & C
View Answer / Hide Answer

ANSWER: B) static interrupted()




32) In Reentrant Monitor It eliminates the possibility of single thread deadlocking?

A) True
B) False
View Answer / Hide Answer

ANSWER: A) True


Post your comment

    Discussion

  • RE: Java Threads - online test -Ravi Kumar (09/17/16)
  • 26) The following two methods in Synchronization block is correct or not?
    Synchronized block is not used to lock an object for any shared resource.
    Scope of synchronized block is larger than the method.

    A) True
    B) False
    View Answer / Hide Answer

    ANSWER: A) True


    Here Ans is false; Both statement is wrong
  • RE: Java Threads - online test -sanket shirke (06/30/16)
  • @tejas provide description
  • RE: Java Threads - online test -Tejas Kiran Rathi (06/22/16)
  • Ans for Question 26 is False. Please correct it.
  • RE: Java Threads - online test -basith (07/14/15)
  • questions are easy....