1.If Runnable interface is better than Thread
class, than why we are using Thread class? What is the need for Thread class?
I think Runnable Interface is used to create a
Thread when the class is extending another class because we don’t have multiple
inheritance facility in java.
for eg:
class A{
}
class B extends A implements Runnable{
}
we can’t extend 2 classes( A and Thread ) so we
use Runnable in this situation.
For one thing, when you’re extending the Thread
class. (Duh!) Perhaps you’re adding add’l features you intend to support for
threads of a given flavor; so, extending Thread is the
natural way to do
it.
2.Why we are calling System.gc() method to
garbage collection of unused object, if garbage collection is automatically
done in Java by daemon thread in background process with regular interval?
the VM runs the garbage collector when it’s needed, but
if you want to free memory IMMEDIATELY, then you explicitly call System.gc().
3.What is the significance of Marker
interface? Why are we using, even though it has no method?
a Marker interface (like Cloneable) is there to mark the
class that implements it as able to perform a given functionality.
For example when you call clone() on a class that does not implements
Cloneable, you get an exception.
The marker methods specifies the functionality of a class
depending upon the need. For example if a method needs to be serialised then it
should implement serialiazable which doesnt have any methods to define, but an
indication for the JVM that this class instatiates objects which can be
inserted into an byte stream
4.Why we are always doing rs.next() in first
line of while loop in retrieving data from database through result set?
Ans:
Always the Recordset points to the previous to
the First record therfore we need to move the pointer to the first record.
5.Please give me the details of
synchronization? And which are the methods and elements used in it and why only
that methods and variables?
6.Why we are not using Java in real time
based application, but instead we are using C or C++?
Yes.Comments given by S.Jithendra is true..and i want to
add one more issue to it.
The data in the real time applications has to be refreshed fast but in java,we
cant say when the garbage collector is going to run..so this makes application
to take much memory than required..where as in c,c++ programmer can handle
memory management..
7.Detail difference between 4 types of driver
and their use in different different applications?
8.Is Java code with native methods
platform-independent?
no, native code is usually C code that is compiled for
the target system. Native code is not interpreted as bytecode by the virtual
machine but executed like any C program for instance.
9.Why is the compiler platform-independent, while
JVM is platform-dependent?
Java Compiler is platform independent because
what the compiler does is only to convert the source code (the .java file) to
java bytecodes (.class file), and these bytecodes are platform independent
lower level representation of the higher level Java codes. Next to actually
execute the bytecodes, the java virtual machine has to interpret the bytecodes,
using the help of the platform (that is both the Operating System and the
architecture). This makes the JVM becomes platform dependent.
To give you small example to explain why JVM
depends on the platform:
Suppose you have written a java code..
i++
The bytecode might turn out to be something that simply says “increment i”
Now when executing by the JVM, suppose it is on a machine that has a code for
directly incrementing a value in its instruction set (ie architecture), then
the JVM mite use that to directly increment the value by 1. If in someother
machine, it is not there, the JVM has to do i = i + 1 on that machine, instead
of directly incrementing.
10.
Mention
different type of compilers and interpreters in Java?