JAVA Study Materils
JAVA Study Materils
Preparation Material:
1. You are using a class from a library (say Student). You have a list of Student objects.
You need to sort this list based on first name. How will you do it? Constraint: (You do
not have the ability to change the source code of the Student class)
2. Consider a class Person with two attributes - String name and List<String> degrees.
How will you make this class immutable. Ask what are the advantanges of immutable
classes
3. We have a Parent class with 2 methods walk and run. We have a child class which
overrides both the methods. Both child class methods just call their respective Super
implementation. Parent class run method calls walk(). class Parent Parent p = new
Child(); p.run(); Tell the order in which each method is called
6. write an sql query to find names of all employees who are having third highest salary
7. Given a sorted integer array and a value K. find two elements from given array whose
sum will be equal to K
11. Consider a class A with a synchronized method class A { public void synchronized
m1() {Thread.sleep(5000);} } We create two objects of this class - o1 and o2. We call
o1.m1() on one thread and o2.m1() on another thread, at the same time. What will be
the behaviour? Follow up with - how will you force these calls to execute one after
the other
12. We have a Parent class with 2 methods walk and run. We have a child class which
overrides both the methods. Both child class methods just call their respective Super
implementation. Parent class run method calls walk(). class Parent Parent p = new
Child(); p.run(); Tell the order in which each method is called
13. Given a List of integers (List<Integer>), write code in Java 8 style to get the sum of
the squares of all the odd numbers in the array.
14. What is the difference between HashMap and ConcurrentHashMap? Follow up with -
what is the difference between CHM and synchronized Map.
15. We have a table called BookAuthor. It has two columns Book and Author, Book being
unique column. Write a query to find the names of the authors who have written
more than 10 books.
16. Given an array of n integers and a number k, find the pairs of numbers in the array
such that the difference between the pair is k. Find the optimal solution with and
without extra storage
18. Consider a class Person with two attributes - String name and List<String> degrees.
How will you make this class immutable. Ask what are the advantanges of immutable
classes
19. Consider a class A with a synchronized method class A { public void synchronized
m1() {Thread.sleep(5000);} } We create two objects of this class - o1 and o2. We call
o1.m1() on one thread and o2.m1() on another thread, at the same time. What will be
the behaviour? Follow up with - how will you force these calls to execute one after
the other
20. We have a table called BookAuthor. It has two columns Book and Author, Book being
unique column. Write a query to find the names of the authors who have written
more than 10 books.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-Observer pattern
-SQL: find employees with max salary in each dept Print employee name and
manager name
6. Oops concept
7. design pattern
9. wait notify
15. Basics of String pool constant, why we use that where it is in main memory
17. 3rd round - manegerial , java 8 , stram api, spring boot rest api
28. How will you design a class to use that class as key in HashMap?
30. What is memory leak and write a program for memory leak
44. When we call wait method which class method is called and How its release
lock.
45. What challenge you are looking for in future
46. Basic java core HashMap and hash set and tree map usages
47. Explain Immutability and its advantages and immutable classes in java.
50. Three threads are there. First prints continuously 1, while second and third
prints 2 and 3 respectively. How will you synchronize them to print 1,2,3
sequentially and efficiently?
52. Detail about project in fact complete 3 years what I have done which project
worked on what was role
53. You have a thread and I want to return a value to the main thread how do u do
that. This was basically about thread pool executor callable and future
55. Given a tree with elements as 1->2&3 and 2->4&5 and 3->6&7. So now a
child tree is given. Write a function to check whether the child tree is a subtree
or not. Also try to optimize it.and he asked what the time complexity of the
method is proposed by me.how I deduce the complexity. Which order
transversal of the tree will it be good
57. what is factory, abstract factory, builder, singleton and composite patterns
61. How one thread can take two object lock. What is it role?
62. Comparable and comparators-based question. like you have employee object
and you are adding it to a collection how u make sure the employees will be
added in sorting order with their id, id and name, what if designation is there
and I want CEO Olin 1st in the list and other employees as per sorting order
with id
65. Basic definitions about different frameworks, uses of trending libraries and
project related details
66. What will happen if class is mutable and used as key in HashMap.
67. Employee object added into hash map and then Id of the employee changed
what will happen. this was basically related to mutable key in hash map
70. Overloading and overriding and what will happen if you override a method
and change in exception throws
71. How to make singleton detailed discussion on it like how to make thread safe
etc
74. You have student object and the stream of student coming in you don't know
how many very large numbers can be if u only must read which collection do u
use
88. - The name of the annotation that specifies which implementation to use at
runtime out of many
90. What if u must search the element than which collection to use
94. : How will you design a class to use that class as key in hash map.
98. What if u must store unique student which data structure to use
107. : Synchronization
112. Try throwing filenotfound and other unknown exceptions then print file not
found or general exception
118. Servlet.
If we have I millions of records and we need to search. Then which data structures will
use, hash set and array list
126. Use case of Multithreading: parallel reading of file using multiple threads.
130. With every question he will, real-time example or how you are using in your
project.
131. Spring scope prototype vs singleton. Which do you use your project and
why?
139. Multithreading: Volatile, atomic variable, cyclic and countdown latch, livelock
140. What will happen if class is mutable and used as key in hash map
156. More tools related questions, for tools which were mentioned in CV.
157. More questions about the things which were mentioned in CV.
167. What is memory leak and write a program for memory leak
170. Employee object added into hash map and then Id of the employee changed
what will happen. this was basically related to mutable key in hash map
173. Overloading and overriding and what will happen if you override a method
and change in exception throws
182. How to make singleton detailed discussion on it like how to make thread safe
etc
193. - The name of the annotation that specifies which implementation to use at
runtime out of many
197. - what is factory, abstract factory, builder, singleton and composite patterns
200. Producer and consumer problem with and without wait notify
203. How will you design a class to use that class as key in hashmap .
204. You have a thread and I want to return a value to the main thread how do
you do that. This was basically about thread pool executor callable and future
213. Try throwing filenotfound and other unknown exceptions then print file not
found or general exception
216. Overloading and overriding and what will happen if you override a method
and change in exception throws
219. What if u must search the element than which collection to use
220. What is memory leak and write a program for memory leak
221. Spring scope prototype vs singleton. Which do you use your project and
why?
226. use collection to store data, if already present return false, not present
added, and give sorted order data
230. why String object has special preference to store data in String constant
pool?
233. What is volatile keyword and what will be the output of a variable if two
thread increments shared variable from 0 to 10 and print
234. There is a function which every time returns random number. You are calling
this function in infinite loop for an hour. How will you get top largest 1lac
integers from these calls?
235. There is a Student class, it has 20 attributes, there are 1 billion rows in
memory for this Student class.
There is another object of a Student class and I want to check if this object exists
in the list of 1 billion rows. It should match all 20 attributes for object to be
equal. How will you do this in Java
236. Why should we write notify method call at the end of synchronized block?
- polymorphism
- constructor chaining
- object creation and it's life on JVM
249. Design of current project including interfaces, classes. Design patterns used
in the project. How will you manager delivery and technical challenges
together. Grooming of juniors. Design something like twitter, Facebook, trading
platform.
254. Mostly he may focus on project which candidate might have done and he
may ask what kind of issues candidate faced while working on project.... like
any technical issues and how he deals with that.
258. Between dispatch servlet and filter who will get first request
265. With every question he will, real-time example or how you are using in your
project.
269. Then which data structures will use, hash set and array list
276. Annotations in SpringMVC and how to set http status codes in response?
- Use of builder
- and implementations
284. What if u must search the element than which collection to use
292. Streams
296. How to make class immutable and why we use final prefix to instance
variables
299. Hash tree internal working. (hashing, hashing collision, hash code() and
equals())
300. Annotations in SpringMVC and how to set http status codes in response?
302. Between dispatch servlet and filter who will get first request
313. Microservices
318. What is the most challenging task u have done in last three months?
323. Iterator
324. CopyOnWriteArrayList
325. What do you know in UI? HTML, JS, jQuery, CSS, Angular?
335. How you write API in Spring? What all sequence of steps you will take?
337. Fill the table with Yes/No and explain why it is yes/no.
Class
Interface
Abstract Class
Method
Local Variable
Instance Variable
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1. System Design
2. Give use case and finding word combination from given dictionary
3. logical question to solve a problem of Lego where multiple shapes were given as
input, we need to give the count of each shape. the shape can be rotated.
4. problem statement for solving a question where we have 2 files feed and we need
to find out which records are only in left file or only in right file or if present in both
then which identify which is having higher value left or right.
7. Lru cache
14. Word given eat and find ate tea like all possible word from dictionary
15. Function to take two strings as arguments and then find whether first is
permutations of other or not.
18. Trading system he has given a scenario in that there are multiple company and
price are getting populated. please design a data structures to store this
24. : Lots of small small output questions related to Java - Linked hash map
26. You have a linked list given with value into it a1, a2, a3, b1, b2, b3, Create new
list with value a1, b1, a2, b2, a3, b3
34. we have a huge file containing positive and negative numbers. Get the
summation of those numbers and explain the process and problems faced while
processing.
35. In a sorted array of n-1 elements. Which contains all numbers up to n except
1??Find the missing number?
46. In a sorted array of n-1 elements. Which contains all numbers unto n except
1??Find the missing number??
49. Designing....If you have 4 3d printers. we will get jobs with a input how much
time it will to take print.... what will be the design? What all classes will be
their...what all data structure u will use.
52. You have student object and the stream of student coming in you don't know
how many very large numbers can be if u only must read which collection do u
use
53. Write a program to count the number of times a substring occurred in each string
57. given an array, write code to print another array which include the product of all
the other numbers in the array except the number at the index (without using
divide) eg: [1,2,3,4] -> [24,12,8,6]
58. given a number write it in words. 123 -> one hundred twenty-three
60. Print natural numbers till 20 using 2 threads, 1 thread for odd number and 1
thread for even numbers. (Thread communication).
63. Read millions of orders(Order_Id, Order_Time) from a file and output the order
ids within given time window(Start date and end date). Write test cases.
65. Code to find number of employees working under them with data being in
Map<String, String>
66. Code to find out year with highest living population where data given is year
wise birthcount and deathcount
67. Class A{
}}
Class B Extends A{
}}
Integer a=5;
Fun(a:
Sop(a);
}
A=4
PSVM(
Try{
Sop(fun();
}catch(Exception e){
Sop(“error”)
)}
Try{
Return 4;
}catch{exception e}{
System.exit(0);
}
}}
// output
72. Write a program to count the number of times a substring occurred in each string
74. We have a huge file containing positive and negative numbers. Get the
summation of those numbers and explain the process and problems faced while
processing.
75. Given array of numbers [5,10,15,20,25...] create another array which is product
of all elements in the array itself except the element at the position
77. find the first repeating character in a string and print its previous and repeated
index.
81. array of numbers given, find all pairs which makes sum k. Numbers can be +/-,
duplicates, one no can be used only once in pairs Send same files to multiple
client and wait until all client acknowledge and then process based on ack. How
main thread can wait and proceed further once client ack.
82. Say there is a new page in paint, and you draw multiple lines
: How will you design a code to decide which are should get filled with which color
: You can take a two-dimensional array and each cell in array say has a object with a
value color as white color
: When you click on position and fill color it will only fill the enclosed area with the
line
83. Print natural numbers till 20 using 2 threads, 1 thread for odd number and 1
thread for even numbers. (Thread communication).
86. Read millions of orders (Order_Id, Order_Time) from a file and output the order
ids within given time window (Start date and end date). Write test cases.
88. Design of current project including interfaces, classes. Design patterns used in
the project. How will you manager delivery and technical challenges together.
Grooming of juniors. Design something like twitter, Facebook, trading platform.
93. How will you implement a cancel button in mobile video player when a 10 gb
movie is getting played in a phone with 2 gb ram? (using volatile keyword)
94. write a class and method using generics with proper syntax.
https://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-
array/
98. we have a huge file containing positive and negative numbers. Get the
summation of those numbers and explain the process and problems faced while
processing.
99. Make the all elements equal for given array of integers using certain number of
options.
100. Delete the inbound nodes from given acyclic directed graph.
101. Design the distributed multi-threaded model to pick and updated the process
based in their execution status, write the API code as well.
1,4,8,5,4
Then 4.
3,6,2,15,1
Then 3
10,5,7,5,1,10
Then 5
103. Given an integer array and a sum variable need to find the pair with sum equal
to sum variable in best time complexity
105. Design the Amazon product search feature. Millions of products. Filter on
multiple properties such as colors, price, size, etc.
106. Find 1st duplicate letter and it's all occurrences in each string.
Problem statement: there are n new developers named 1,2,..N. So a pool of total N
developers.
A will give his preference of developers needed for his team in high priority to low
priority order. EX: [3,4,1,2,6,7]
B will also give his preference of developers needed for his team in high priority to
low priority order. EX: [1,4,3,2,6,7]
Now selection process goes like A gets chance to pick developers from available
pool and then B gets chance to pick among available. This process goes on until no
developers left.
111. Discussion on low level design of an airport which has many takeoffs and
landings and has only one airstrip or runway
115. If we call java Account using two putty with the same machine IP address, then
how many jvm will start where Account is the class name that stored on the
machine in compiled format I.e. Account. Class
117. Given a tree with elements as 1->2&3 and 2->4&5 and 3->6&7. So now a child
tree is given. Write a function to check whether the child tree is a subtree or not.
Also try to optimize it. and he asked what the time complexity of the method is
proposed by me. how I deduce the complexity. Which order transversal of the
tree will it be good
118. You have student object and the stream of student coming in you don't know
how many very large numbers can be if u only must read which collection do u
use.
119. we have a huge file containing positive and negative numbers. Get the
summation of those numbers and explain the process and problems faced while
processing.
122. Discussion on low level design of an airport which has many takeoffs and
landings and has only one airstrip or runway
Problem statement: there are n new developers named 1,2,..N. So a pool of total N
developers.
A will give his preference of developers needed for his team in high priority to low
priority order. EX: [3,4,1,2,6,7]
B will also give his preference of developers needed for his team in high priority to
low priority order. EX: [1,4,3,2,6,7]
Now selection process goes like A gets chance to pick developers from available
pool and then B gets chance to pick among available. This process goes on until no
developers left.
what all functionality needs to be provided by system? and How implementation will
be done. (Controller, service, model classes.)
128. How to identify top 5 most repeated words in a file?
129. Create a data structure where add, get and delete in order of 1 with natural
ordering
130. How will you implement a cancel button in mobile video player when a 10 gb
movie is getting played in a phone with 2 gb ram? (using volatile keyword)
131. write a class and method using generics with proper syntax.
135. we have bank transactions in a flat file with name, type(v buy/sell), amount.
136. we need to give gift vouchers for all transactions exceeding rs. 10,000. also
consider pair of transactions which are exceeding 10,000. Make sure to give
maximum number of gift vouchers.
137. How will you design a code to decide which are should get filled with which
color
138. Say there is a new page in paint, and you draw multiple lines
139. Java - Design of current project including interfaces, classes. Design patterns
used in the project. How will you manager delivery and technical challenges
together. Grooming of juniors. Design something like twitter, Facebook, trading
platform
141. When user A requests their all bags to be infornt of the queue
All bags will a tag also with class line class Bags {String tagName;String Owner;}
142. 3rd round there were scenario-based questions on my current project like how
did I read large number of jobs from database to perform operation on that like
which data structures i used.
143. One problem solving to find max subarray length having sum of that sub array
elements to 0 (zero) in an array having random positive and negative integers
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1. Query to print 3 highest paid employees from table without using sql functions
in efficient way.
th
3. 100 highest salary in employee table
5. Database query to fetch the person name whose hobby is not reading
9. Transaction in database
13. Given two tables employee and department. Find max salary from employee
table based on department.
17. Sql query to get employee records having salary greater than average salary
20. query to print department name and count of persons in each department?
23. DB optimization
26. Find all the employees who has manager sql query
32. Write a query to get all the employees who directly or indirectly reports to an
employee and also tell how it stores in java
36. There are 2 tables A and B, both has 2 columns id and name. How will you
find data which is not common in both table?
40. How to find list of departments from employee table for which all employee of
that department has same salary
41. DB - Joins (left outer join), Indexes, Query plans, Query optimization.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
https://kupdf.net/download/cracking-core-java-interviews-munish-chandel_58fcadffdc0d60ae279
59eec_pdf
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1. Multithreading/JVM/Garbage-collector ->
https://www.youtube.com/c/DefogTech/featured
2. SQL ->
https://www.youtube.com/playlist?list=PL6n9fhu94yhXcztdLO7i6mdyaegC8CJwR
3. Microservices ->
https://www.amazon.in/Cracking-Spring-Microservices-Interviews-developers-ebook/dp/
B07B4H3VZ9
4. Java-Interview-Questions ->
https://www.amazon.in/Cracking-Core-Java-Interviews-3rd-ebook/dp/B07BD3HB3Q/ref=
sr_1_2?dchild=1&qid=1602927449&refinements=p_27%3AMunish+Chandel&s=digital-t
ext&sr=1-2
5. Problem Solving -> a. Array -> https://www.geeksforgeeks.org/array-data-structure/
b. Strings -> https://www.geeksforgeeks.org/string-data-structure/
c. Trees -> https://www.geeksforgeeks.org/binary-tree-data-structure/
d. Graph -> https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX