Thursday, June 17, 2010

Here are some java questions I have been asked in interviews recently:

Explain what the following JVM args are used for:

-Xss

-Xmx

-Xms

-XX:PermSize

-XX:NewSize

-server vs -client

What is the difference between the heap and the stack? Explain what is present on the heap and stack when the following method is called:

public void f(int i){
Integer a = i ;
double d = i ;
}

Answer: The primitive int 'i' is boxed into an Integer object and placed on the heap. So you have a "new Integer(i)" object present on the heap, and variables a, d and i on the stack (as well as the method f). [Further Reading]

What are the main collections found in the Collections API?

What is the difference between a List and a Set?

How does a HashMap work?

Given the following classes: Collection, Set, Map, List, ArrayList, Vector, LinkedList, Stack, HashMap, TreeMap, HashSet, TreeSet state which ones are interfaces, concrete classes and those that can be cast to Collection.

i) What is the size of the set and map? What is the result of map.get(new Person("David"))?
ii) Delete the equals method and repeat i)
iii) Delete the hashCode method and repeat i)
iv) Delete both the equals and hashCode methods and repeat i)

Answers:
i) 3, 3, DAVID
ii) 4, 4, null
iii) 4, 4, null
iv) 4, 4, null

Describe the different kinds of exceptions?

What happens when a RuntimeException is thrown but not caught by anything?

hi,nice questions and answers.thaks for ur efforts.i have seen a good website for Core Java interview questions and answers.you can download it in pdf.cheers.all the best for your interview preparation.here is the linkCore Java interview questions and answers

Subscribe to fahd.blog

Hi, I'm Fahd, a software developer at an investment bank in London. I am passionate about technology and work mainly with open source software, specialising in Java applications and Unix-based operating systems.

This blog is a place for me to share useful code snippets to solve problems that I have come across, and to write about ideas and experiences as a programmer.

All code on this blog has been written by me, unless stated otherwise, and you are free to use, share and adapt it for any purpose, under the terms of the GNU General Public License.

I love hearing back from my readers, so please feel free to leave comments! Thanks for reading and happy programming :-)