Java Back End Developer

Java Back End Developer Interview Questions and Answers

Updated 29 Sep 2024

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?

Ans.

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. Sql query to find nth highest salary. What does limit and offset do?

Ans.

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.

Q3. Which data structure to use to store data in the order of insertion and also have uniqueness?

Ans.

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<>();

Q4. How to handle exception at controller level? Use of restcontrolleradvice

Ans.

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

Are these interview questions helpful?

Q5. Sort Array in O(N) complexity

Ans.

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.

Java Back End Developer Jobs

Java Back End Developer - Bangalore/Hyderabad/Pune 5-8 years
Tech Mahindra
3.6
₹ 13 L/yr - ₹ 23 L/yr
Hyderabad / Secunderabad
Java Back End Developer 4-8 years
Tech Mahindra
3.6
₹ 12 L/yr - ₹ 22 L/yr
Hyderabad / Secunderabad
Java Back End Developer 4-9 years
Oracle
3.7
Pune
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.9
 • 596 Interviews
3.7
 • 567 Interviews
3.4
 • 505 Interviews
3.8
 • 210 Interviews
3.6
 • 97 Interviews
4.0
 • 28 Interviews
3.7
 • 16 Interviews
3.9
 • 2 Interviews
3.2
 • 1 Interview
View all

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

Java Back End Developer Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter