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.
0 comments:
Post a Comment