Some Important Faqs On Java
Some Important Faqs On Java
Some Important Faqs On Java
This means one object having multiple parents, which is not truly
supported in java but supported in C++. But overall design of java
suggests that we can implement multiple inheritances in java using
interfaces.
A non-static inner class may have object instances that are associated
with instances of the class's outer class. A static inner class does not
have any object instances.
Inner class is class, which is defined inside a class as private class and
always bears a reference to the outer class.
o Inner classes can be nested within the body of a method.
Scope of inner class is the entire enclosing class in which the inner
class is nested.
Inner classes can access attributes and methods in nesting class.
Each inner class is compiled into a separate. class file
labeled:NestingClass$InnerClass.
Inner classes can contain methods that return handles to inner class
instances.
Major advantage of inner classes is the ability to create adaptor
classes that implement an interface.
o Make all inner classes private to ensure hidden implementation.
o Rather than handle classes returning inner classes, they return
interfaces.
Inner classes frequently used with event handling in applets.
6. What is a transient variable?
o The variable, which cannot be serialized, is known as transient
variable.
7. What are wrapped classes?
o Wrapped classes are classes that allow primitive types to be accessed
as objects.
8. What is an immutable object and what are its advantages?
Advantage:
Overridden methods must have the same name, argument list, and
return type.
The overriding method may not limit the access of the method it
overrides.
The overriding method may not throw any exceptions that may not be
thrown by the overridden method.
13.
null. Method variables or local variables are eligible for Garbage collection
when they go out of scope.
Garbage Collection cannot be forced explicitly. JVM may do garbage
collection if it is running short of memory.The call System.gc() does NOT
force the garbage collection but only suggests that the JVM may make an
effort to do garbage collection.
22. Does garbage collection guarantee that a program will not run out of
memory?
Garbage collection does not guarantee that a program will not run
out of memory. It is possible for programs to use up memory
resources faster than they are garbage collected. It is also possible
for programs to create objects that are not subject to garbage
collection.
27. Is it possible to know from the content of a class file whether it is a java
class file or not?
The first four bytes of every java class file is a magic number
0xCAFEBABE. So it is very easy to identify whether it is a java
class file or not.
28. Name the process thru which JVM makes the types available to the
running program?
The Java Virtual Machine makes types available to the running
program through a process of loading, linking, and initialization.
31. What are steps involved in loading of a class file into JVM?
32. Is it possible to detect a malformed class file during early loading by the
class loader?
No it is not possible. If a class loader encounters a missing or
malformed class file during early loading, it must wait to report that
error until the class is first active use by the program.
33. What are the different stages of linking after the class is loaded?
Verification, prepare and resolve are the three phases of linking.
34. What is verification stage and what are steps involved during verification?
It ensures that the types obey the semantics of java language and
doesnt violate the integrity of JVM.
The entire process of detecting any kind of problem with loaded
types is placed under the category of verification.
Verification of symbolic references and converting them to direct
references.
The Java Virtual Machine allocates memory for the class variables
and sets them to default initial values. The class variables are not
initialized to their proper initial values until the initialization phase.
Java Virtual Machine implementations may also allocate memory
for data structures that are intended to improve the performance of
the running program.
36. What happens during Resolution Phase?
39. What is the difference between instance method and class method ?
44. What happens when there are more than one highest priority threads
having same priority?
In that case only one of the thread is picked up. It is up to the
thread Scheduler to arbitrate between threads of same priority.
There is no guarantee that all the same priority threads will be fairly
treated.
46. What are the methods which can only be called from within a
Synchronized method or block ?
Notify (): unblocks one randomly selected thread among the
threads that called wait() on this object.
NoitifyAll() : unblocks the threads that called wait() on this object.
Wait (): causes the thread to wait until it is notified.
47. What is the difference between yield and sleep methods of Thread?
52. What is the difference between a Green thread and Native thread
Green Threads" are the default threads that are provided in the
JDK, while the "Native Threads" are the one provided by the native
Operating System.
Normally "Native Threads" provide better performance because
they are controlled by the kernel of the system, allowing the JVM to
better use the resources offered by the system itself.
For example, in a multiprocessor system "Green Threads" will
never be able to use Solaris or Linux or Windows specified kernel
calls to optimize the use of the processors.