Monday, June 15, 2015

Threads Interview Question In Core Java

10:06 AM

Threads Interview Question In Core Java



Threads

Q - What is the definition of multi-threaded programming according to Patrick Naughton?
A - According to The Java Handbook, by Patrick Naughton,
"Multi-threaded programming is a conceptual paradigm for programming where you divide programs into two or more processes which can be run in parallel."
Q - Multithreading refers to two or more programs executing, "apparently" concurrently, under control of the operating system. The programs need have no relationship with each other, other than the fact that you want to start and run them all concurrently. True or False? If false, explain why.
A - False. That is a description of multiprocessing, not multithreading. Multithreading refers to two or more tasks executing, "apparently" concurrently, within a single program.
Q - According to current terminology, the term blocked means that the thread is waiting for something to happen and is not consuming computer resources. True or False? If false, explain why.
A - True.
Q - What are the two ways to create threaded programs in Java?
A - In Java, there are two ways to create threaded programs:
     Implement the Runnable interface
     Extend the Thread class
Q - What two steps are required to spawn a thread in Java?
A - The two steps necessary to spawn a thread in Java are:
     instantiate an object of type Thread and  invoke its run() method.
Q - How do you start a thread actually running in Java?
A - Invoke the start() method on object of the Thread class or of a subclass of the Thread class.
Q - It is always possible to extend the Thread class in your Java applications and applets. True or False? If false, explain why.
A - False. Sometimes it is not possible to extend the Thread class, because you must extend some other class and Java does not support multiple inheritance.
Q - Although multithreaded programming in Java is possible, it is also possible to write Java programs that do not involve threads: True or False? If false, explain why.
A - False. The main method itself runs in a thread which is started by the interpreter.
Q - What is the name of the method that can be used to determine if a thread is alive?
A - The name of the method is isAlive().
Q - Once you start two or more threads running, unless you specify otherwise, they run synchronously and independently of one another: True or False? If false, explain why.
A - False. Once you start two or more threads running, unless you specify otherwise, they run asynchronously and independently of one another

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 Java Tutorials. All rights resevered. Designed by Templateism

Back To Top