Java Questions
Java Questions
Below is the compilation of all the different types of Java, Spring Boot, Database
and related questions that were asked in companies like JP Morgan Chase,
BlackRock, Morgan Stanley, Deloitte, UBS, Goldman Sachs, BNP Paribas and some
other companies interviews that I personally gave.
Note
2 String Concepts 3
6 Exception Handling 8
8 Design Patterns 10
11 Spring Security 12
12 Microservices 12-13
14 Database Questions 14
15 15
Frontend/Angular Questions
3
String Concepts
1. Why are strings immutable in Java and how many objects will be created in
String temp = "A" + "B" + "C"; explain your answer in detail.
2. How to find duplicate strings in a list of strings.
3. Difference between String vs String Builder vs String Buffer
4. Difference between Comparable and Comparator.
5. Write a program to find if a String is a palindrome String.
6. Write a program to find a list of substrings of a given String and sort the
individual substrings.
7. Find all the words from a dictionary that are anagrams of each other.
8. Run Length Encoded string
9. Finding the most repeating or common word in a string
10. What is String Interning/Intern() method/ String Pool concept?
Object-Oriented Programming(OOPs)
Ans. Function<T>
1. Explain each interface and class present in the Collection interface. Starting
from the Collection interface tell me the timecomplexity of each for
insertion/deletion, accessing elements, insertion order maintained or not.
2. Internal working of HashSet? How are null key and values are handled in
HashSet?
3. Why do we need to override equals and hashcode methods in Java? Equals
- HashCode Contract in Java?
4. Hash Map Internal Working.
a. the Data structure it uses,
b. hash calculation and index calculation
c. capacity of buckets, load factor
d. hash collision? How doubly linkedlist is ued to resolve hashcollision?
what is used when all the buckets of doublylinkedlist is filled?
e. time complexities of insert, delete and search operations.
f. What is the Role of equals() and hashcode() methods in the Object
class?
g. What will be the behavior if we override the hashcode() method to
always return?
h. How are null key and values are handles in HashMap?
5. What is CopyOnWriteArrayList?
6. What is ConcurrentHashMap?
7. HashMap vs HashTable vs ConcurrenthHashMap
8. Map vs FlatMap?
9. Synchronized collections vs Concurrent collections
10. Fail-safe vs Fail-fast concept in Java? What are Fail-fast and Fail Safe
iterator in the collections framework?
11. Comparator in Java and how do you create one? What is natural ordering?
Can it be used for multiple fields sorting?(No)
12. Comparable in Java and how do you create one? Advantages of
Comparable over Comparator? What is total-ordering? Which one would you
use in real time project for sorting or ordering? Can it be used for multiple
fields sorting?(Yes)
13. What is the difference between ArrayList and LinkedList?
14. What is the difference between a HashMap and a TreeMap?
15. What is the difference between a HashSet and a TreeSet?
16. What is the difference between an Iterator and a ListIterator?
17. What is the difference between an ArrayList and a LinkedList?
18. How to sort an ArrayList? Ascending order/Descending Order using Custom
Class fields.
19. How to sort a Map? Ascending order/Descending Order using Custom Class
fields.
20. How do you pass the Comparable to the PriorityQueue or TreeSet?
21. Can we insert null in treeset?
7
Note:
1. Make sure you do lots of practice as it will be asked to run the code in an
IDE. Be thorough with all the methods and ways you go about solving
something especially in Java.
2. Always they will ask you to write the code in Java 8 or later way. So, always
ensure you are using Stream API whenever necessary, and using all sorts of
Funtional Interfaces with the correct use of Lambda Expressions.
Exception Handling
1. Program vs Process
2. Inter Process Communication
3. Multiprocessing real life example
4. Multiprocessin vs Multithreading
5. What is Multithreading and where have you used the multithreading or
written code for the same in your project?
6. Proc
7. What is volatile keyword in terms of thread?
8. Need for synchronization in java?
9. What is thread safety and How will you achieve thread safety in a Java
Program?
10. What is a thread and what are the different stages in its lifecycle?
11. How do you create a thread in Java? What are the different ways of
creating a thread? Which one is the best way to do it?
12. What is the difference between process and thread?What are the different
types of thread priorities available in Java?
13. What is context switching in Java?
14. What is the difference between user threads and Daemon threads?
15. What is synchronization?
16. What is a deadlock?
17. Class level lock vs object level lock in Java?
18. What is the difference between synchronized and volatile in Java?
19. What is the purpose of the sleep() method in Java?
20. What is the use of the wait() and notify() methods?
10
Design Patterns
1. What are Design Patterns? Different Types of Design Patterns?
2. Write a code for Singleton Class? Write all the variations of a Singleton class
from lazy loading to thread safe singleton to Bill Pugh Singleton.
3. How do you make a singleton class thread safe?
4. What is Builder Design Pattern?
5. What is a Decorator Design Pattern?
6. Concurrency Design Patterns
Sping boot 3?
Spring Security
1. What is Spring Security?
2. Simple AUTH vs JWT(JSON Web Token) vs OAuth. Pros and cons of using
each.
3. Security filters
4. Pre-authorization
5. Post-authorization
6.
Microservices
1. What are Microservices and when should someone think about
Microservices in terms of migration? What problems does it solves? What
are the disadvantages of Microservices?
2. CAP theorem in case of Microservices
3. How do microservices communicate with each other?
4. Point to Point Communication vs Publish Subscribe Communication
5. Apahe Kafka.
● How it offers High Throughput
● What are Partitions
● What are Consumer
● How many partitions will be consumed by different individual
consumers in a consumer group?
● How many partitions will be consumed by different consumer groups?
● How can you make a Kafka Topic as a Message Queue?
6. Apache Kafka vs Messaging Queue(Rabbit MQ, IBM MQ, Active MQ, etc). In
depth understanding of what to use when to use?
7. Rest Template and its uses? What is now used as Rest Template is
deprecated? Accessing RESTful services on the client in Java- Rest
Template.
8. How to consume RESTful webservice in a springboot application using
RESTTemplate or WebClient
9. What is Reactive Programming? What were other options in Java existing
before reacting programming that was introduced recently. Retry() method.
10. Explain how to implement asynchronous processing in Springboot
application. Provide an example using @Async annotation
11. How can you secure your spring boot application. Demonstrate the use of
Spring Security for basic authentication and authorization
12. Circuit Breaker Pattern used in Microservices. Why its used?
13. What iS ELK i.e. Elastic Search - LogStash - Kibana stack? Why its used?
What is Splunk?
14. What is Zipkin?
15. What is Promethus and Grafana and how are they utilized in Microservices?
16. How to do Distributed tracing - zipkin, telemetry ?
17. How to debug the cascading issue?
14
Database Questions
15
Ans. Ask the DBA team to provide the detailed AWR report of each query resulting
into slowness
Frontend/Angular Questions