Morgan Stanley Interview Questions – Set 4
- Please tell me about technologies you have worked on, your current project and your roles and responsibility in it.
HashMapworks internally? explain about hashCode() and equals() methood? (Answer)
hashCode()method internally calls
hash(int h)function. What is the use of
hash()function? What does it do?
What is rehashing? How
HashMapdoes rehashing internally?
Write a java program to implement a custom Map implementation for MarketPlace which internally maintais key-value pairs of stocks and its 10 last updated values.
– If you put key-value in map, it should not overwrite old value, but instead maintain list of values.
– Once size of list reaches to 10, it should remove old value. In short it should maintain insertion order.
– If at 1:00 PM, stock value of Apple is 155.30 USD
– At 1:05 PM, stock value of Apple is 155.50 USD
i.e. MarketPace < Apple, (155.50, 155.30) >
– Write all the utility methods of this custom Map like put(), get(), containsKey(), remove(), size()
– Map should also perform efficietnly and consistently in multithreading environments.
ConcurrentHashMapprovides better performance than
SynchronizedMapis a thread-safe, but it will acquire lock on entire Map in read and write opearations. So at a time only one thread can either read or write in Synchronized Map. Hence it is slower.
ConcurrentHashMapis a thread-safe. Instead of acquireing a lock on entire Map object, it devides map in different segements and each thread can aquire a lock on individual segment. so at a time multiple threads can write in different segments but not in the same segement. Also this lock is required only in write operation. Multiple threads can read concurrently from the same segement.
– For detailed understanding, please read our article Hashtable Vs SynchronizedMap Vs ConcurrentHashMap
What is the difference between
- Which all Spring modules have you used?
- Explain Spring MVC life cycle.
- Explain various bean scopes of Spring?
- What is singleton bean scope?
- If I am having Spring Configuration file as below :
<beans> <bean id="emp1" class="Employee"> ... </bean> <bean id="emp2" class="Employee"> ... </bean> </beans>
If I call
getBean("emp2"), How many Employee class objects will be created in JVM?
- What is the difference between Spring Singleton Bean scope and Singleton design pattern.
- How you will implement Singleton Design Pattern?
- What is double check in lazy intialization singleton pattern implementation?
- What is index in database table? When do we need to create index on table?
- Difference between clustered and non-clustered index
- Design Database table design for Bank's customers and thier account.
- When creating extra mapping table is useful.
- Write a SQL query to find 3rd largest salary
This article is contributed anonymously by one of the CodePumpkin user. If you would also like to contribute your article or share interview experiences, you can create contributor account with CodePumpkin by clicking here or you can send us a mail at firstname.lastname@example.org.
Comments and QueriesIf you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code class="java"> String foo = "bar"; </code></pre>For more information on supported HTML tags in disqus comment, click here.