Interview Question for Interns


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
2
of 2 vote

1. HashMap is Java's version of a Hash Table based on the Map interface. It maps keys to values using a hash function.

2. Array list is an array with dynamic resizing and shifting, while a linked list is a set of nodes linked together. Arrays are great for accessing data an any index in constant time, but inserts require O(n-index) time, so inserting to the front of an ArrayList is linear time for EACH insert, while it's constant time in a LinkedList. However, accessing data near the middle of a LinkedList takes O(n) time because we have to travel through the nodes to get to it.

3. To my knowledge, collisions are handled internally when you put an item into a HashMap. One issue with HashMap that you won't get with a linking HashTable is that you cannot put a key to map to two different values. For example if you had a key<string> "John Smith" and you wanted 4 different phone number values for it, you could not do that with a HashMap (You can, however, have multiple keys map to a single value.)

4. Runtime Polymorphism is just what it sounds like - Polymorphism that occurs at runtime. So polymorphism basically deals with inheritance. Suppose we have Class Employee, and Subclass Lawyer. Using polymorphism we'd have:

Class Employee {
// Some stuff
}

Class Lawyer extends Employee {
// Some stuff
}
So we can say:

Employee lawMan = new Lawyer(); //right?

Doing this at runtime simply could go many ways. An example would be a method that builds Employees for you taking a string parameter, and something like:
//pseudo code
Some method (String str)
Employee emp;
if (str.equals("Lawyer"))
emp = new Lawyer();

Something like that would happen at runtime.

- kakitayuri February 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I think the collision also means when their hash value collides, which can be handle by a linkedlist storing both value and the original key.

- zyfo2 February 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

if you use ArrayList for assigning multiple values to a single key, then you can assign "John Smith" with 4 different numbers and these numbers will be stored in ArrayList.

- vrd February 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

which company?

- ashok February 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Amazon AWS team...

- A February 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

answers at
javadecodedquestions.blogspot.sg/2012/03/java-interview-with-investment-bank-4.html

- java interview Questions February 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Map implementation will be sortedhashmap, hashmap, treemap

- java interview Questions February 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hey Any one explain diffeferences bettween all maps,sets?

- Anonymous March 14, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More