Java Interview Questions - 1
Java Interview Questions - 1
• Actuator.
• Circuit Breaker (hystrix circuit breaker)
• How to check log of fat jar.
• How do you configure property files of a microservice in my project?
• How to achieve 80% code coverage and how this is configured in your project.
• Basic knowledge of java script-based server-side development (NodeJS)
• Apache Camel
• Explain inter microservice communication?
• Basic of Horizontal and vertical scaling (Docker/Docker swarn/ kubernetes + AWS
cloud)
1|Page
• What is dependency Injection? How do we implement it with Spring Boot?
• @Autowired annotation - what is auto wired - where does the value come from?
• Mention some of the annotations we use in Spring Boot and explain.
Java
• Garbage collection
• Immutability of Strings in Java
• .equals() method and "==" operator in Java
• POM file -dependency management
• CI/ CD related - tools used for Continuous Integration & Continuous Delivery/
Deployment in my team
• git commands
• Agile basics
2|Page
Spring Boot/ Webservice
• How you will ensure the security access to your webservice.
• How you will layer your webservice so that through internet there will not be any
unauthorized access to your webservice.
• How to control call limit to say 200 calls from particular client to our Spring boot
webservice
• Any idea on Rate Limiter
Core Java
RDBMS
• Suppose there are millions of record rows. how you will handle the fetching of
records from your project
Java
• How can we index a non PK/ non key column in table. What is cluster and non -cluster
indexing
• The Employee table holds all employees including their managers. Every employee
has an Id, and there is also a column for the manager Id.
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
Given the Employee table, write a SQL query that finds out employees who earn more than
their managers. For the above table, Joe is the only employee who earns more than his
manager.
3|Page
• What is the difference between Spring and Spring boot? We can write APIs in spring
also then why spring boot.
• What is the difference between Micro service and rest service?
• What are the ACID properties? How we will follow in code.
• How beans will be initialized in spring boot. Scenario: We are having Class A and
Class B,
• So class A needs class B reference and class B needs class A reference how we will
achieve.
• Write code for producer and consumer problems using threads.
• What is the difference between abstract class and interface? How we will overcome
Java
the diamond
• problem with default implemented functions from interface.
• What is the difference between process and thread? Thread how it will run.
• What is the difference between goroutines and Threads in java? Why are routines
more popular compared to java threads?
• Write code below requirement.
Given an array A[] and a number x, check for pair in A[] with sum as x
arr[] = {0, -1, 2, -3, 1}
sum = -2
-3 1
• What is use of make function in GoLang
• What is Kafka…Use of API
• Spring Boot annotations, difference btw spring/spring boot
• Interface vs Abstract class, Concept for producer/consumer problem using java using
blocking queue and write code.
Java
4|Page
• how to create a singleton class and if u configure that as singleton will spring use it-
ans-need to use static factory method.
• how to configure a static factory method.
• RDBMS vs NOsql db when to use which db.
• disadvantages of microservice architecture from developer side.
• tell all the design paterns u used in microserivces.
• in mongodb when data is spread across multiple nodes ,how does the searching
happens
• In web application ,if a certain user is accessing website for many number of times,
how to low prioritise him and give changes to other users?
• In web application will thread be created for each request?
• scopes in spring bean. when to use which scope.
• same database query to finds out employees who earn more than their managers.
• which search algorithm to use if it is just a tree(it is not a Binary tree.)
• Write an efficient algorithm that searches for a value in an m x n matrix. This matrix
has the following properties:
The first integer of each row is greater than the last integer of the previous row.
Java
Output: true
• The Employee table holds all employees including their managers. Every employee
has an Id, and there is also a column for the manager Id.
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
Given the Employee table, write a SQL query that finds out employees who earn more than
their managers. For the above table, Joe is the only employee who earns more than his
manager.
5|Page
+----------+
| Employee |
+----------+
| Joe |
+----------+
• write a function to reverse the sub array [7,8,9,1,2,4,6,4,32] reverse the array
elements from index 2 to index 5
• program to check if the elements are closed properly or not
String s="{}[]()"//valid string and String s1="{[]}"//also valid
String s="{[(])}"//should be invalid.as the the open braces is not properly closed.
• In projects…….
• asked about stack data structure and methods in stack
• About different advices in spring AOP ,before advice vs Around Advice ,
will control goes to target even if exception raised in Before advice?
• how to handle exceptions in completablefuture.
• Multithreading
6|Page
• Difference between Microservices and monolithic design. Advantages &
disadvantages.
• how to handle session in Microservices
• how to handle authentication in between the microservices
• Data structure
• Mongo DB query fetching and how to make faster queries.
• Data fetching in MongoDB
• sql query regarding the employee and manger salary.
• Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's
(water), return the number of islands.
Example 1:
Input: grid = [
["1","1","1","1","0"],
["1","1","0","1","0"],
["1","1","0","0","0"],
Java
["0","0","0","0","0"]
]
Output: 1
Example 2:
Input: grid = [
["1","1","0","0","0"],
["1","1","0","0","0"],
["0","0","1","0","0"],
["0","0","0","1","1"]
]
Output: 3
• Microservice architecture
• Communication between microservice
• Hystrix
• Difference between image and container
• Steps for moving code to azure cloud
• How db was setup in cloud
7|Page
• 1) encryption mechanism vs hashing mechanism
• how hashcode works internally?
• Database query optimization?
• How to control the call limit to say 500 calls from clients.
• How to find out a particular element in a tree, which sorting mechanism is the
Java
best?
• when we call the Arrays. Sort() method internally it follows which sorting
mechanism?
• someone called your service which is running on other process. How can you
provide authentication and authorization?
8|Page
• What is the difference between VM and container?
• Arrays.sort() internally which sorting algorithm to use?
• What is space complexity for quicksort?
• What is the time complexity for Binary Search?
• How to restrict a particular client accessing an application?
• What are the properties we can access from the external class to the inner class?
• How many ways to authenticate users to access applications.
• We have thousands of records in one table. Select query taking a long time to
fetch the data. How you can optimise.
• Write a query for the below requirement.
•
• +-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| num | varchar |
+-------------+---------+
id is the primary key for this table.
Write an SQL query to find all numbers that appear at least three times
consecutively. Return the result table in any order. The query result format is in
the following example:
Java
Logs table:
+----+-----+
| Id | Num |
+----+-----+
|1|1|
|2|1|
|3|1|
|4|2|
|5|1|
|6|2|
|7|2|
+----+-----+
Result table:
+-----------------+
| ConsecutiveNums |
+-----------------+
|1|
+-----------------+
1 is the only number that appears consecutively for at least three times.
9|Page
• Java 8 and microservices questions related to data structures and algorithm
• Binary tree vs Binary search tree-Space Complexity & Time complexity
• Quick sort vs merge sort-Time complexity
• Zuul Api gateway? what is the need for api gateway?
• What is Eureka? why we need eureka?
• Write an SQL query to find all numbers that appear at least three times consecutively.
• Which Data structure does Binary tree use?
Java
• About my recent project which I worked and how difficult I felt leveraging monolithic
architecture to microservices?
• Monolithic vs Microservices?
• Disadvantages of microservices?
Java
input = 100
Find the input from the arr using binary search
• Write the code for creating a new Rest Endpoint in a Controller. Requires code
• Find repeated words in the given sentence and count the repetitions - "today is is is a
sunny sunny day today today is a sunny"
Output should be like -
today - 3
is - 4
Java
a-2
day - 1
10 | P a g e
• define the project you have worked
• how would you make sure about the code quality - mentioned about design
principles?
• features of java 8
• difference between mongo db and normal oracle db
Java
logs?
• An Stored procedure is running fine in dev and taking too long in prod, how do you
troubleshoot
• How the workflow of the project is implemented, how did the application is scaled.
No of users used the application.
• Technology used in my previous project.
11 | P a g e
• Difference between Symmetric and Asymmetric key encryption
• what are the authentication methods in spring LDAP?
• How do you manage users in LDAP?
• Authentication vs authorization explain scenarios
Java Spring Boot
12 | P a g e
• Introduction and Project explanation/architecture.
• Spring Boot common annotations used.
• What are methods of Rest.
• What are mime types of @Produces?
• What is a resource in a REST?
• Types of Joins in SQL. What is Left Join?
• What is symmetric encryption and asymmetric encryption? What encryption did you
use in your project?
• Have you used Spring Initializer, how to generate Spring boot project using it.
What is an Actuator? Define a custom actuator using annotations?
• Difference between @RequestMapping and @GetMapping.
• What is the use of @Controller?
Java Spring boot
13 | P a g e
• Complete architecture of current project.
• What is the methodology used in your project?
• Entire process from getting requirements to moving production.
• How is version management happening?
• What is the branching strategy?
• What is the first branch you have?
• What are the branches used in a release?
Java Spring boot
14 | P a g e