Java Back End Developer
10+ Java Back End Developer Interview Questions and Answers
Q1. Design a layered architecture for saving the user data to db. What all annotations to be used on each class and on functions if any?
Design a layered architecture for saving user data to db with appropriate annotations.
Create a data access layer (DAO) to interact with the database using annotations like @Repository
Implement a service layer to handle business logic with annotations like @Service
Use @Entity annotation on model classes to map them to database tables
Add @Id annotation on primary key fields in model classes
Utilize @Transactional annotation on service methods for transaction management
Q2. What is the purpose of the @Primary and @Qualifier annotations in Spring Framework?
The @Primary annotation is used to give a higher priority to a bean when multiple beans of the same type are present. The @Qualifier annotation is used to specify which bean to inject when multiple beans of the same type are present.
Use @Primary annotation to specify the primary bean to be used when multiple beans of the same type are present.
Use @Qualifier annotation along with the bean name to specify which bean to inject when multiple beans of the same type are present.
Exa...read more
Java Back End Developer Interview Questions and Answers for Freshers
Q3. Sql query to find nth highest salary. What does limit and offset do?
SQL query to find nth highest salary using LIMIT and OFFSET.
Use ORDER BY salary DESC to sort salaries in descending order.
Use LIMIT 1 OFFSET n-1 to get the nth highest salary.
For example, SELECT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 2 will give the 3rd highest salary.
Q4. Which data structure to use to store data in the order of insertion and also have uniqueness?
LinkedHashSet is the data structure to use for storing data in order of insertion and uniqueness.
LinkedHashSet maintains insertion order and ensures uniqueness of elements.
It uses a combination of LinkedList and HashSet to achieve this.
Example: LinkedHashSet
set = new LinkedHashSet<>();
Q5. What is the difference between the equals method and the == operator when comparing Strings?
The equals method compares the content of two strings, while the == operator compares the memory addresses of the strings.
equals method checks if two strings have the same content
== operator checks if two strings are stored in the same memory location
Example: String str1 = new String("hello"); String str2 = new String("hello"); str1.equals(str2) returns true, but str1 == str2 returns false
Q6. How did you implement multithreading in your project?
Implemented multithreading using Java's Thread class and Executor framework.
Used Thread class to create and manage threads.
Utilized Executor framework for managing thread pools and executing tasks.
Implemented synchronization mechanisms like locks and semaphores to prevent race conditions.
Used Java's concurrent data structures like ConcurrentHashMap and BlockingQueue for thread-safe operations.
Share interview questions and help millions of jobseekers 🌟
Q7. How do you implement security measures for your microservices?
Implementing security measures for microservices involves using authentication, authorization, encryption, and monitoring.
Implement authentication mechanisms such as OAuth, JWT, or API keys to verify the identity of clients accessing the microservices.
Enforce authorization rules to control access to different parts of the microservices based on roles and permissions.
Use encryption techniques like TLS/SSL to secure communication between microservices and external clients.
Imple...read more
Q8. What is the concept of lock isolation in Spring Framework?
Lock isolation in Spring Framework ensures that each transaction operates independently without interfering with other transactions.
Lock isolation prevents concurrent transactions from affecting each other's data.
Different levels of lock isolation can be set in Spring, such as READ_COMMITTED and REPEATABLE_READ.
For example, setting a higher level of lock isolation like REPEATABLE_READ ensures that a transaction will not see changes made by other transactions until it is compl...read more
Java Back End Developer Jobs
Q9. How to handle exception at controller level? Use of restcontrolleradvice
Using RestControllerAdvice to handle exceptions at controller level in Java
Create a class annotated with @RestControllerAdvice to handle exceptions globally
Use @ExceptionHandler annotation in the class to define methods to handle specific exceptions
Return ResponseEntity with appropriate status code and error message in the exception handling methods
Q10. handling distributed transactions in microservices using the Saga pattern?
Saga pattern is used to manage distributed transactions in microservices by breaking them into smaller, independent transactions.
Saga pattern involves breaking down a long transaction into a series of smaller, independent transactions.
Each step in the saga is a separate transaction that can be rolled back if needed.
Compensating transactions are used to undo the effects of a previously completed step in case of failure.
Sagas can be implemented using choreography or orchestrati...read more
Q11. Sort Array in O(N) complexity
Use counting sort to achieve O(N) complexity.
Count the frequency of each string in the array.
Create a new array based on the frequency counts.
Fill the new array with the strings based on their frequency counts.
Interview Questions of Similar Designations
Interview experiences of popular companies
Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary
Reviews
Interviews
Salaries
Users/Month