Study Material interview questions
Study Material interview questions
http://javahungry.blogspot.com/2013/08/hashing-how-hash-map-works-in-java-or.html
http://javahungry.blogspot.com/2014/06/how-treemap-works-ten-treemap-java-interview-questions.html
http://javahungry.blogspot.com/2015/02/how-concurrenthashmap-works-in-java-internal-implementation.html
http://javahungry.blogspot.com/2015/10/how-treeset-works-internally-in-java-interview-questions.html
http://javahungry.blogspot.com/p/threads.html
http://javarevisited.blogspot.in/2011/04/synchronization-in-java-synchronized.html
http://javarevisited.blogspot.in/2011/06/volatile-keyword-java-example-tutorial.html
http://mrbool.com/working-with-java-executor-framework-in-multithreaded-application/27560
http://stackoverflow.com/questions/10828863/what-the-use-of-custom-class-loader
http://stackoverflow.com/questions/10901752/what-is-the-significance-of-load-factor-in-hashmap
http://stackoverflow.com/questions/11011291/treeset-internally-uses-treemap-so-is-it-required-to-implement-
hashcode-method
http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons
http://stackoverflow.com/questions/13855013/understanding-java-memory-management
http://stackoverflow.com/questions/2087469/sort-a-file-with-huge-volume-of-data-given-memory-constraint
http://stackoverflow.com/questions/27325997/how-does-countdownlatch-works-in-java
http://stackoverflow.com/questions/56860/what-is-the-liskov-substitution-principle
http://stackoverflow.com/questions/8161896/example-code-to-show-how-java-synchronized-block-works
http://tutorials.jenkov.com/java-concurrency/synchronized.html
http://tutorials.jenkov.com/java-util-concurrent/cyclicbarrier.html
http://www.dynatrace.com/en/javabook/how-garbage-collection-works.html
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStarted/index.html
http://www.programcreek.com/2013/03/hashmap-vs-treemap-vs-hashtable-vs-linkedhashmap/
https://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/garbage_collect.html
https://en.m.wikipedia.org/wiki/Creational_pattern
https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
https://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational-pictures/
https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
Java Basics
SQL
1 ways-to-find-nth-highest-salary
Data structures
1 Prefix search. Sample Ar gives Arc, ArchiTecture, Art, Artist, Artisan Using trie.
2 Check if array is formed of consecutive elements? Gave O(n)
Immutability
Memory model and GC
Synchronization
sleep vs wait
Orderids in time range
1. Why were ORMs like Spring data JPA , Hibernate introduced over JDBC?
2. If you have to set up JDBC in your application, what all changes would you do in your application.
4. Suppose I am calling 4 different services from my application. From 1st service I am fetching data, 2nd
service I am updating data into Database 3rd is doing some delete operation followed by 4th service update
operation. Now all these operations are to be managed within single transaction. How will you do it.
Assume these services have their own databases. Can it be done by using spring transaction management.
If yes how, if now then what is the alternative.
5. (i) You have 2 synchronized methods within a class and 2 threads. Can both the threads access the 2
methods at the same time? In what scenario the threads can access the 2 methods together. In what
scenario the threads cannot access the 2 methods together and only one can be accessed?
(ii) Now I want more than 1 thread holding lock on same instance to access the same synchronized block.
What will you do for that?
(iii) I want 2 threads holding lock on same instance to access the 2 methods together using locks. How can
it be done?
6. Perform Serialization and Deserialization of binary tree. Discuss what all scenarios can come and how you
will manage serialization and deserialization in all these scenarios for the binary tree.
(iv) If I would have used Static class with the restriction within the project that no one is allowed to create
more than 1 object for this class ,would it serve my purpose? Can I replace static class in place of Singleton
in such a scenario.
8. (i)What are the prerequisites of making a custom class object as HashMap key . What all changes you
would do in your custom class to make such a scenario possible. What is the issue caused if we don’t
override equals method?
(ii) Suppose I have not overridden hashcode and equals methods in my custom class. Will it work properly?
(iii) Will the get method provide me the correct and desired data from map if both equals and hashcode
are not overriden? If yes , what is making the get method work properly? If no , then what will be the
output
9. Is SimpleDateFormat a threadsafe object ? If not then how do you make sure it is threadsafe in nature?
What is the exception you get when multiple threads access the SimpleDateFormat in a concurrent way ?
What is the exception you get when multiple threads access a collection like arraylist ?
10. Can a static method access class level variables(instance variables) directly?
11. (i)Write a query to find the employees having same salary in an Employee table.
(ii) Is there a difference in performance of query if you do Select S1.name from Student s1,Student s2
where …. instead of Select S1.name from Student s1 join Student s2 on s1.id = s2.id where….
2. Suppose you are having a huge number of beans within your application. How would you maintain
such a large number of beans in your application .
4. Suppose there are 2 component classes which implement the same interface . Now you want to
autowire both ? Will it cause a runtime exception ?If yes , How can you resolve such an issue? If no ,
how spring manages such a scenario?
7. (i) What all changes you can think of in order to make a custom class object as hashmap key? Why
immutability is considered as a preferred option when it come to hashmap key?
(ii) Suppose I have an Employee class with id and some other field. I have overridden the equals and
hashcode methods. Within equals method implementation I have not used id and have used
remaining fields only . Will it cause me any problem? In what scenarios it will work and it what
scenarios it wont work.
(iii) Now if I remove both equals and hashcode methods from Employee class will it work for me. In
what scenarios it will work and it what scenarios it will fail ?
(iv)Suppose I want to use a 3rd party api object which doesn’t override equals and hashcode as a key in
hashmap. How can I do it?
(v)The api is having a class Employee with a method of getDetails(Employee emp) and doesn’t have
equals and hashcode overriden. I want my application to access that method . How can I access that
method .
8. (i) What kind of threading mechanisms you have implemented in your application?
(ii) How do you decide which threadpool to use for what scenario within your application?
(iii)How do you decide what is the number of threads that threadpool should be having?
(iv) Suppose there are 100 tasks within your application what should be the the ideal size of
threadpool in such a case.
(v)Suppose there are many tasks which keep on coming to your application with no particular DB
operations nor external 3rd party service interactions . What kind of threadpool you would be using in
such a scenario. What should be ideal size to your threadpool?
9. Coding ques : A genius guy has predicted the cost of 1 type of shares for 30 days in 1 go. Some days
the cost is going up some days it is going down. Assume that he can buy at most 10 shares on a given
day and sell any no of shares he is holding. Design a algorithm in such a way that at by the end of 30
days he should be earning maximum profit .
10. You have been given a list of items . Find out the average price of these items using java 8 code.
Q1 IMPLEMENTATION CODING
double findHalfAreaPoint(double X)
e.g. if areaUnderCurve(X) returns 100, then findHalfAreaPoint(X) should return a value "H" such that
areaUnderCurve(H) will return 50.
NOTE: areaUnderCurve is an API function which you can call.
*/
/* Q2 SQL
Table: Hobbies
Person | Hobby
----------------
John | Movies
John | Baseball
Sameer | Reading
Sameer | Music
Sameer | Movies
1. Names of all the people who have the hobby of reading. // Parth
2. Names of all the people who do not have the hobby of reading.*/
/*Q3
* 3.1 MAP AND CONCURRENT HASHMAP
* 3.2 CONCURENT HASHMAP AND TREEHASHMAP
* 3.3 THREAD SAFE BEHAVIOUR OF ABOVE DS
* 3.4 BUCKET LOCKING CONCEPT
Q4
About current project
JUNIT TESTING
CHALLANGES OF MOCKING UNIT CASES
Java-
Network Overriding
Memory Consumption
Memory Allocation
----------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
1) Two classes having static method with same name and if one class extends another.
For eg: Class B extends Class A and suppose both class have method name : display().
What will happen and will it override in base class?
4) There is a class with 2 static synchronized methods M1 and M2 and Multiple threads are accessing these
methods. How will they access these methods? Explain.
5) There is a List of integer values and need to use some methodologies to get even integers from list and its sum
using JAVA 8 techniques.
6) Define a body of function with input parameter as a paragraph String. Write a logic to count the number of
words and count of each words if it occurs more than once.
7) There is a list of values indicating per day stock price. For eg: 1-100,2-150,3-200.......30-100 [day-stockPrice].
Now write a logic to find a day when customer should purchase a stock and a day when he should sell to get a
maximum profit. return buy-day,sell-day and Profit Price.
---------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------
1) Given a function with input parameter as a List<String>. Write a logic to remove duplicates from that List.
2) Given a function with input parameters as (List<Integer>, List<Integer>). Return the elements which are distinct
from both the lists.
3) Given a User defined class Employee {String name, float sal} and have overriden hascode method which returns
same value for all inputs. What will happen of instances of Employee class is put into a HashMap as a key.
Scenarios 2: if Employee class overrides equals method and also it returns true for all values. What will happen of
instances of Employee class is put into a HashMap as a key.
5) Given a Function with input parameter as 2D-Array of Integers with any order. A logic is written inside a function
to put these values into Database table.
Design a Table schema to handle dynamic change in order of input matrix.
http://javahungry.blogspot.com/2013/08/hashing-how-hash-map-works-in-java-or.html
http://javahungry.blogspot.com/2014/06/how-treemap-works-ten-treemap-java-interview-questions.html
http://javahungry.blogspot.com/2015/02/how-concurrenthashmap-works-in-java-internal-implementation.html
http://javahungry.blogspot.com/2015/10/how-treeset-works-internally-in-java-interview-questions.html
http://javahungry.blogspot.com/p/threads.html
http://javarevisited.blogspot.in/2011/04/synchronization-in-java-synchronized.html
http://javarevisited.blogspot.in/2011/06/volatile-keyword-java-example-tutorial.html
http://mrbool.com/working-with-java-executor-framework-in-multithreaded-application/27560
http://stackoverflow.com/questions/10828863/what-the-use-of-custom-class-loader
http://stackoverflow.com/questions/10901752/what-is-the-significance-of-load-factor-in-hashmap
http://stackoverflow.com/questions/11011291/treeset-internally-uses-treemap-so-is-it-required-to-implement-
hashcode-method
http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons
http://stackoverflow.com/questions/13855013/understanding-java-memory-management
http://stackoverflow.com/questions/2087469/sort-a-file-with-huge-volume-of-data-given-memory-constraint
http://stackoverflow.com/questions/27325997/how-does-countdownlatch-works-in-java
http://stackoverflow.com/questions/56860/what-is-the-liskov-substitution-principle
http://stackoverflow.com/questions/8161896/example-code-to-show-how-java-synchronized-block-works
http://tutorials.jenkov.com/java-concurrency/synchronized.html
http://tutorials.jenkov.com/java-util-concurrent/cyclicbarrier.html
http://www.dynatrace.com/en/javabook/how-garbage-collection-works.html
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStarted/index.html
http://www.programcreek.com/2013/03/hashmap-vs-treemap-vs-hashtable-vs-linkedhashmap/
https://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/garbage_collect.html
https://en.m.wikipedia.org/wiki/Creational_pattern
https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
https://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational-pictures/
https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
https://www.geeksforgeeks.org/commonly-asked-dbms-interview-questions/
https://www.geeksforgeeks.org/commonly-asked-dbms-interview-questions-set-2/amp/?ref=rp
https://www.geeksforgeeks.org/sql-interview-questions/amp/?ref=rp
https://www.geeksforgeeks.org/sql-interview-questions-set-1/amp/?ref=rp
https://www.geeksforgeeks.org/sql-interview-questions-set-2/amp/?ref=rp
which header is in rest api that can be used for preventing multiple calls from client
Design:
Design In Memory file system like Unix with below features but should be extensible
ls
mkdir
appendContent to file
Read Contents from file
Database:
Give table Hacker(hacker_id, hacker_name) and Challenge(hacker_id, challenge_id)
1. Get total challenges by each hacker(Solved)
2. If 2 hackers have same number of challenges, filter out both(Could not solve)
3. If highest number of challenge are created by multiple hacker, don’t filter out (Could not solve)
Exception handling.
o Checked exception vs unchecked exception
o Overriding the methods which throws checked or unchecked exceptions
Generics
Serialization
OOPs concepts
Immutable class
Abstract class and interfaces
Encapsulation vs Abstraction
Time complexity of all the operations on HashMap, HashSet, TreeMap, TreeSet, Stack and Queue for Best
case, worst case and average case.
Practice joins
https://www.w3resource.com/sql/joins/sql-joins.php
Write a query in SQL to list the details of the departments where maximum number of employees are
working.
Write a query in SQL to find one employee from each department who is getting the highest salary within
his department. (Don’t forget to handle corner case where multiple / no employees are getting highest
salary in a department.)
Write a query in SQL to list the details of the departments where maximum number of employees are
working. (1 department with max employee or multiple departments having same number of employees)
Get familiar with usage of zookeeper, eureka and consul as a service discovery. Added advantage if you
know trade off of all these solutions.
CAP theorem.
How do you decide that a microservice should expose HTTP or JMS listener?
Microservices design patterns specially SAGA patterns, API Composition pattern and CQRS pattern
Spring Framework
2. Find first and last positions of an element in a sorted array. (Observe the pattern like here array is sorted
and it may contain duplicates)
https://www.geeksforgeeks.org/find-first-and-last-positions-of-an-element-in-a-sorted-array/
6. How to design an LRU cache. Which data structure you would like to use?
Hint: LinkedHashMap Or HashMap + LinkedList
Algorithms
Tim sort (Used by Java for objects)
Quick Sort (Double Pivot Quick Sort is used by Java for primitives)
Merge sort
Multithreading / Concurrency
Synchronization puzzle like print 1 to N sequentially from 2 threads one should be printing even
numbers and one should be printing odd numbers.
When we should prefer volatile int/long over the Atomic Integer / Atomic Long?
When we should prefer Atomic Integer / Atomic Long over the intrinsic and extrinsic locks?
How to Design a website visitor counter. Come up with at least 3 solutions and be aware about the pros
and cons of each one.
Assume you have to replace the thread pool of any web application server using your custom thread pool
executor. Try to build it and submit some tasks to it.
Do load testing of the same.
https://howtodoinjava.com/java/multi-threading/java-thread-pool-executor-example/
JVM Internals
Diagnose Out of memory error.
Heap dumps, memory dumps