Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog

Android app on Google Play

Technical Interview Questions
Javascript Interview Questions
J2EE Interview Questions
J2SE Interview Questions
J2ME Interview Questions
JDBC Interview Questions
JMS Interview Questions
C++ Interview Questions
EJB Interview Questions
JSP Interview Questions

Programming Source Codes
Java Source Codes
C Source Codes





Java Interview Questions and Answers

What is the difference between final, finally and finalize?
Short answer:
final - declares constant
finally - relates with exception handling
finalize - helps in garbage collection
If asked to give details, explain:
final field, final method, final class
try/finally, try/catch/finally
protected void finalize() in Object class

What kind of security tools are available in J2SE 5.0?
There are three tools that can be used to protect application working within the scope of security policies set at remote sites.
keytool -- used to manage keystores and certificates.
jarsigner -- used to generate and verify JAR signatures.
policytool -- used for managing policy files.
There are three tools that help obtain, list and manage Kerberos tickets.
kinit -- used to obtain Kerberos V5 tickets.
tklist -- used to list entries in credential cache and key tab.
ktab -- used to help manage entries in the key table.

How to make an array copy from System?
There is a method called arraycopy in the System class. You can do it:
System.arraycopy(sourceArray, srcOffset, destinationArray, destOffset, numOfElements2Copy);
When you use this method, the destinationArray will be filled with the elements of sourceArray at the length specified.

Can we use System.arraycopy() method to copy the same array?
Yes, you can. The source and destination arrays can be the same if you want to copy a subset of the array to another area within that array.

What is shallow copy or shallow clone in array cloning?
Cloning an array invloves creating a new array of the same size and type and copying all the old elements into the new array. But such copy is called shallow copy or shallow clone because any changes to the object would be reflected in both arrays.

When is the ArrayStoreException thrown?
When copying elements between different arrays, if the source or destination arguments are not arrays or their types are not compatible, an ArrayStoreException will be thrown.

How to check two arrays to see if contents have the same types and contain the same elements?
One of options is to use the equals() method of Arrays class.
Arrays.equals(a, b);
If the array types are different, a compile-time error will happen.

Can you call one constructor from another if a class has multiple constructors?
Yes. Use this() syntax.

What are the different types of inner classes?
There are four different types of inner classes in Java. They are: a)Static member classes , a static member class has access to all static methods of the parent, or top-level, class b) Member classes, the member class is instance specific and has access to any and all methods and members, even the parent's this reference c) Local classes, are declared within a block of code and are visible only within that block, just as any other method variable. d) Anonymous classes, is a local class that has no name

In which case would you choose a static inner class?
Interesting one, static inner classes can access the outer class's protected and private fields. This is both a positive and a negative point for us since we can, in essence, violate the encapsulation of the outer class by mucking up the outer class's protected and private fields. The only proper use of that capability is to write white-box tests of the class -- since we can induce cases that might be very hard to induce via normal black-box tests (which don't have access to the internal state of the object). Second advantage,if I can say, is that, we can this static concept to impose restriction on the inner class. Again as discussed in earlier point, an Inner class has access to all the public, private and protected members of the parent class. Suppose you want to restrict the access even to inner class, how would you go ahead? Making the inner class static enforces it to access only the public static members of the outer class( Since, protected and private members are not supposed to be static and that static members can access only other static members). If it has to access any non-static member, it has to create an instance of the outer class which leads to accessing only public members.

What is weak reference in Java
A weak reference is one that does not prevent the referenced object from being garbage collected. You might use them to manage a HashMap to look up a cache of objects. A weak reference is a reference that does not keep the object it refers to alive. A weak reference is not counted as a reference in garbage collection. If the object is not referred to elsewhere as well, it will be garbage collected.

Page Numbers :   1    2    3    4    5    6    7    8    9    10    11    12    13    14    15    16    17    18    19    20    21    22    23    24    25    26    27    28    29    30    31    32    33    34    35    36    37    38    39    40    41

Have a Question ? post your questions here. It will be answered as soon as possible.

Check Struts Interview Questions for more Structs Interview Questions with answers