Source
When will you use Comparator and Comparable interfaces?
Answer: java.util.Comparator and java.lang.Comparable
java.util.Comparator compares some other classs
instances, while java.lang.Comparable compares itself with
another object.
Source | Example
What is the wait/notify mechanism?
Answer: This deals with concurrent programming. The wait() and
notify() methods are designed to provide a mechanism to allow a
thread to be block until a specific condition is met.
However, java.util.concurrent should be used instead of wait()
and notify() to reduce complexity.
Source | Java API | Java Technical Article
What is the difference between checked and unchecked
exceptions?
You need handle this in dao layer, when doing insert operation
you can call an utility method which will load the context
ServletContextListener. Because, servlets are basically used for
handling request and give the response.
Q. How does JSP handle run-time exceptions?
Ans: You can use isErrorPage=true in page attribute.
Q. What is an EJB Context?
Ans: The EJBContext interface provides an instance with access to
the container-provided runtime context of an enterprise bean
instance.
Q1. Why do you want to work in this industry / company?
Ans: First you should try to convince that this company gives
huge opportunity in many aspect i.e. new technologies
implementation, the policy of company suits you like
professionalism. Also you can mention that you are big fan of
this company and its your dream company. Basically show your
all positive attitude towards company.
Q2. Which location do you want to work in and why?
Ans : Give your own choice. Also mention a valid reason for why
you are interested for that location. The reason should be always
positive and clear. Example :- you can support your family from
this location,
Q3. Describe a problem you faced and how you deal with
it ?
Ans : You can describe any issue you faced during your project
work in the organization. And what the solution you have
implemented for that issue.
Q4. What are the types of class loaders in Java?
Ans : As per my knowledge there are basically 3 types of class
loader like bootstarp classloader,extension class loader and
system class loader.
}
/**
* @param args
*/
public static void main(String[] args) {
InnerClassTest.innerTest innerObj=new
InnerClassTest().new innerTest();
innerObj.age=20;
innerObj.display();
}
}
5) How to retrieve the elements from the collection write
the code ?
Ans : Java provides certain interfaces by using that we can
retrieve the elements from collection.Example Iterator,
ListIterator and Enumeration.
}
6) What is static and instance variables and methods ?
Ans : Static variables are per class but the instance variables are
per object. All object share a single copy of static variable. In case
of static method , no need of object creation for calling static
method. The static method can directly call by using class name.
Instance method need object for calling.
7) What is dynamic loading and static loading of java class
?
Ans : Dynamic class loading is by Class.forName() , which loads
the class dynamically. Also you can use reflection for dynamic
class loading. But, the static class loading is working by using
new keyword.
8) What type of loading is class.forname() ?
Ans : Its dynamically locate and loads the class.
9) What is Hibenate 3 best benfits ?
Ans : There are many benefits of hibernate. But the most benefits
are below :1.
It reduces the developer effort to writing queries.
2.
Its easy to use with relational object which maps with java
class and database relation.
3.
Query tuning is not required and it implements separates
cache which is reason for better performance.
10) I have 100 tables and fields. I want to find one table
name and column names. Write a quey .
Ans : I have used mySQL database for this below query.
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME from
information_schema.COLUMNS where TABLE_NAME='EMPLOYEE';
11) How to define a field name in hibernate using
annotation ?
Ans:- @Column (Its provided by java persistent API).
12) What is Synchronization ?
Ans:- Synchronization is a solution for concurrency issue.
Java provide 'synchronized' keyword for implementing this.
13) The most commonly used classes in collectionsn ?
Ans : ArrayList, LinkedList, HashTable, HashMap and
ConcurrentHashMap, etc.
3. How many types of literals are there in JAVA ?
Ans : The literals means the value you are assigning to variable.
You can specify the below types of literal in java.As per the
primitive data types(int,short,long,float,double,boolean,char ,etc
there is respective literal. Some literal needs to be ended with a
specific character.Read More.
long var=20L; //specify L or l for long literal
int var=20; // If not mentioned any character then its can be
short or int
char var=A;
float var=10.44f; //specify f or F for float literal
double var=10.44;
boolean var=true; //or false
4. What is meant by Garbage collection ?
Ans : Garbage collection is a automatic feature of java for
cleaning the unused object from heap. It helps to developer for
releasing the reserved memory without any extra effort by
developer. It helps developer to save time and extra mental
tension for handling object allocation in memory. When there is
no reference to an object found, it will clean that object from
memory . You can run the garbage collection explicitly by using
System.gc() .
5. Diffference between string s= new string (); and string
s = "Hi Dude"; ?
Ans : Both statements are different to each other. Always new
keyword is used to create object.
String s=new String(); // This statement creates new object in
heap. S is the object here.
String s=Hi Dude ; // This statement do not create object, its
creating reference and its storing in String Constant Pool.S is the
reference here.
6. What is singleton class? where is it used ?
Ans : Singleton design pattern is the most useful pattern in real
time scenario.Singleton pattern will ensure that there is only one
instance of a class is created in the JVM.This implementation
restrict the user to create multiple access point or instance. This
is a creational design pattern. It has many implementation over
java language, but singleton is an anti-pattern or bad
practice.
Ans : HQL stands for Hibernate Query Language. Its fully object
oriented and quite similar with SQL.It supports association and
joins for effective entity relationship.
Which Interface is used to make duplicate of Objects ?
Ans Cloneable interface.
Q11) What are some advantages and disadvantages of
Java Sockets?
Ans The main advantage is its flexible and very efficient during
low network bandwidth. Also its helpful for debugging and some
kind of testing. But, security is the most disadvantages. Its
always recommended to be careful when authenticating.
Q12) When can an object reference be cast to an interface
reference?
Ans Yes its possible, when that interface is implemented by that
class.
Example MyInterface obj=new MyClass();
obj.callMethod();
Q13) How does Java allocate stack and heap Memory?
Ans As we know stack memory is not dynamic and its follows
LIFO order. Java provides similar implementation for memory
allocation. Normally all local variables are created in Stack area
(memory) and objects (reference types) are created in heap
memory (heap area) .Even all primitive types allocated in stack
memory. Heap area is dynamic and handled by JVM runtime.
Heap memory is cleaned by garbage collector at runtime.
Q14) What is memory leak in Java?
Ans Usually memory leak leads to waste of memory. In general
memory leak defines the unavailability of referenced memory. It
causes the Garbage collector to fail to collect that object.
-2
31
2 -1) .
31
that is an object. You need to take one dog which has name dick,age-8,color -white and it must have a unique identification.
And now we can say dick is a dog object. And this dick can bark,
bite and run. These are the behavior that object can do, and in its
implemented by methods.
Q.2. How many contructor & methods are in Object class ?
Ans: There are only one constructor and nine methods in Object
class. Its available inside java.lang package.
Constructor :public Object()
Methods :clone() - This create and return copy of the same object.
equals() - This is used to compare some other object is equal to
this or not.
toString() - Convert and return a string representation.
finalize() - This is called by garbage collector when there are no
more active reference to that object exist.
getClass() - This returns the runtime class of this object.
hashCode() - Returns an hash code for this object and its unique.
notify() - Wakes up a single thread that is waiting on this object's
monitor.
notifyAll() - Wakes up all thread that is waiting on this object's
monitor.
wait() - This will make object to wait , until any other thread
notify this.
Q.3. Why wait() and notify() method is inside Object class
instead of Thread class ?
Ans : Because, wait() and notify() method works with multithreaded environment. This is inside Object class because, we are
doing the monitoring work over an Object . When ever we are
calling these methods , we are calling over object , not on thread.
Q.4. How many ways we can create object in Java ?
Ans : There are basic four way for creating object in java as below
dogObj=(Dog)class.forName("jdeveloperguide.lab.Dog").newtInst
ance();
By using deserialization ObjectInputStreaminStream=new
ObjectInputStream(anInputStream);
DogdogObject=(Dog)inStream.readObject();