Java interview Question-Part4
1. Explain different way of using
thread?
Thread can be implemented by using thread class or by
runnable interface. Using runnable interface is more advantageous because it
can be used in multiple inheritances.
2. Difference between HashMap and HashTable?
HashMap is similar to HashTable, the only
difference is that they are unsynchronized and they permit NULL. HashMap
doesn’t guarantee that the map order will be maintained.
3. What is the difference between a constructor and a method?
A constructor is member function and it is used to
create object of the class. It assigns the same name as that in the class, and
has no return type. Whereas method is a ordinary member function, which has own
name and return type. They are invoked using dot operator.
4. What is the disadvantage of threads?
The major disadvantage is that
It is operating system dependent.
Execution of thread reduces speed
High possibility of Dead Lock.
5. What is garbage collection? Can it be forced?
Garbage collection is mainly to identify and discard objects which is no longer
used. It is required by the program for alloction of resources and reclaiming
them. Java virtual machine tries to recycle the unused object, but there is no
guarantee that the object is garbage collected.
6. What is Log4j in java?
Log4j is a property file wich
can be used to assign application mode in “DEBUG”, “ERROR” etc.
7.What are the primitive types in Java?
Java support eight types of primitive data types
and they are as follows:-
Short
Int
Byte
Float
Char
long
Boolean
8. How all can free memory?
If a programmer really wants to explicitly request a garbage
collection at some point, System.gc() or Runtime.gc() can be invoked, which
will fire off a garbage collection at that time
9. What are the differences between JIT and Hotspot
JIT is a compiler whereas Hotspot is a collection of techniques, also called as
optimization.
Java hotspot is a core component of the Java platform. It implements JVM
specification and uses shared library.
10. What is the difference between concat and append?
Concat is used to add a string at the end of another
string.But append() is used with String Buffer to append character sequence or
string.When we concatinate a string with another string a new string object is
created.But in case of StrinBuffer APPEND() that is not the case.
11. What is EJB?
EJB stands for Enterprise Java Bean.
It is a server side resident resource manageable, secure, reusable component.
12. What is package? Define with example?
Grouping of related types is said to be package. The type can be a class or enumeration
or interface and annotation. They are provided with access protection. It is a
group of inter-related classes
13. What is the difference between length and length()?
Length() is a method that is
used to determine the length of the string in the class, Whereas length is just
used for array to find the length of the array.
14. What is synchronization and why it is important?
Synchronization occurs when the
programmer want to run two thread at a time which shares some property. Synchronization
is the process that control access to multiple threads to share resources.
15. How to make a class serializable?
Class can be serialized by using the interface or the io.externalizable or
io.serializable. When one class is inheritance to the other, the class is said
to be serializable.
16. Do I need to import java.lang package any time? Why ?
No. It is by
default loaded internally by the JVM.
17. What are the different types of inner classes?
The different type of
inner classes are as follows:-
Local classes
Anonymous classes
Nested top- level classes
Member classes
18. What is a member class?
It is one of inner class which is just like the
other methods and variables and they are restricted to access. The major
difference between member and nested top level class is that it can access
specific instance of the corresponding class.
19. What is the difference between error and exception?
An error that occurs during runtime
is not recoverable whereas in most of the cases an exception can be recovered
if it occurs during run time.
20. What are the different ways to handle exceptions?
The two methods to handle exception are as follows:-
Wrapping the desired code in the try block that is
followed by catch block
List out the desired exception in throw and the caller
of the method handle
the
exception
21. If I write System.exit (0); at the end of the try block, will the
finally block still execute?
When you type System.exit(0) in the
end it indicates the compiler to stop compiling and execute of the program,
thus the finally block will not be executed.
22. How are observer and observable used?
Objects that subclass the Observable
class maintain a list of observers. When an Observable object is updated it
invokes the update() method of each of its observers to notify the observers
that it has changed state. The Observer interface is implemented by objects
that observe Observable objects.
23. How does Java handle integer overflows and underflows?
Java handles
integer overflow and underflows using low order bytes that fit in the size of
the type that is allowed by the operation.
24. What is locale class?
The class is mainly used
to tailor the output of the program with respect to the specification
25. Can applets communicate with each other?
An applet may communicate with other applets that are running in the same
virtual machine. When the applet are from same class it can communicate using
static variable, when the applet are of different class it can communicate
through reference.
---------------------------------------------------------------------------------
Posted By Sundeep aka SunTechie
Sundeep is a Founder of Youth Talent Auzzar, a passionate blogger, a programmer, a developer, CISE and these days he is pursuing his graduation in Engineering with Computer Science dept.
Add Sundeep as a Friend on