Senior Java Developer

20+ Senior Java Developer Interview Questions and Answers for Freshers

Updated 29 Nov 2024

Popular Companies

search-icon

Q1. What is immutable and how we can create our own immutable class ?

Ans.

Immutable objects are those whose state cannot be changed after creation.

  • Use final keyword to make class immutable

  • Make all fields private and final

  • Do not provide setter methods

  • If a field is mutable, return a copy of it instead of the original object

  • Examples: String, Integer, LocalDate

Q2. What is singleton and how to create singleton class and benefits ?

Ans.

Singleton is a design pattern that restricts the instantiation of a class to one object.

  • To create a singleton class, make the constructor private, create a static method to get the instance of the class, and create a private static variable to hold the instance.

  • Benefits of singleton include ensuring only one instance of the class exists, providing a global point of access to the instance, and reducing the number of objects created in the system.

  • Example: java.lang.Runtime is a...read more

Q3. BELOW SQL QUESTIONS: 1.TRUNCATED VS DELETE VS DROP 2.WHAT IS COMPOSITE KEY 3.Write query to find customer details whos average between 1000 and 2000 customer and order different table link with customer_id

Ans.

SQL questions on Truncate, Delete, Drop, Composite Key and Query to find customer details

  • Truncate removes all data from a table, Delete removes specific data, Drop removes the entire table

  • Composite key is a combination of two or more columns that uniquely identifies a row in a table

  • SELECT * FROM customer c JOIN order o ON c.customer_id = o.customer_id WHERE AVG(o.amount) BETWEEN 1000 AND 2000

Q4. Multiply ele E.g:[1,8,7,3,2] => 1 = 8*7*3*2 [336,42,48,112,168] If 1 then you should multiply all except 1 i.e 8*7*3*2=336

Ans.

The question asks to multiply all elements in an array except for a given number.

  • Iterate through the array and calculate the product of all elements except the given number.

  • Use a variable to keep track of the product.

  • If the given number is 1, multiply all other elements.

  • Return the resulting array.

Are these interview questions helpful?

Q5. 1.Calculate age without without using any inbuilt function 2.Department wise highest salary 3.Factorial number

Ans.

Answering interview questions for Senior Java Developer

  • To calculate age, subtract birth year from current year

  • To find department wise highest salary, group by department and find max salary

  • To find factorial number, use a loop to multiply numbers from 1 to n

Q6. What is difference between get & load in hibernate

Ans.

get() method returns null if object is not found in database, while load() method throws ObjectNotFoundException.

  • get() method is eager loading while load() method is lazy loading.

  • get() method returns a fully initialized object while load() method returns a proxy object.

  • get() method is slower than load() method as it hits the database immediately.

  • load() method is faster than get() method as it returns a proxy object and hits the database only when required.

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q7. Write code for below: Removed number character before hash based on count of hash Case 1 I/P= abc#d O/P= abcd Case 2 I/P=abc##d O/p=ad

Ans.

Write code to remove number character before hash based on count of hash

  • Count the number of hashes in the input string

  • Loop through the string and remove the character before the hash based on the count of hashes

  • Return the modified string

Q8. Can we create own immutable class

Ans.

Yes, we can create our own immutable class in Java.

  • Make the class final

  • Make all fields private and final

  • Do not provide any setter methods

  • Provide only getter methods

  • If any mutable object is used, return a copy of it instead of the original object

Senior Java Developer Jobs

Java Senior Developer (Banking or Payments) 5-12 years
FIS Global Business Solutions India Pvt. Ltd.
3.9
Kolkata
Senior Java Developer 4-6 years
Yamaha Motor Solutions India Pvt. Ltd.
4.1
₹ 18 L/yr - ₹ 25 L/yr
Faridabad
Senior Java Developer 6-8 years
CGI Information Systems And Management Consultants
4.0
Hyderabad / Secunderabad

Q9. How ClassLoader work & what is JIT

Ans.

ClassLoader loads classes at runtime. JIT compiles bytecode to native machine code.

  • ClassLoader loads classes dynamically at runtime

  • It searches for classes in classpath and loads them into JVM memory

  • JIT (Just-In-Time) compiler compiles bytecode to native machine code for faster execution

  • It optimizes frequently executed code by compiling it at runtime

  • JIT is enabled by default in most JVMs

Q10. What is difference between JDK & JRE

Ans.

JDK is a development kit that includes JRE, while JRE is a runtime environment for executing Java programs.

  • JDK stands for Java Development Kit and includes tools for developing, debugging, and monitoring Java applications.

  • JRE stands for Java Runtime Environment and includes the minimum set of tools required to run Java applications.

  • JDK includes JRE, so if you have JDK installed, you also have JRE.

  • JDK includes a compiler, while JRE does not.

  • JDK is required for developing Java ...read more

Q11. What is volatile ? And write program

Ans.

Volatile is a keyword in Java used to indicate that a variable's value may be modified by multiple threads.

  • Volatile variables are not cached in thread's local memory

  • Changes made to volatile variables are immediately visible to other threads

  • Volatile keyword is used to ensure visibility and ordering of variables in multithreaded environment

  • Example: volatile int count = 0;

Q12. How HashMap work internally?

Ans.

HashMap is a data structure that stores key-value pairs and uses hashing to retrieve values quickly.

  • HashMap uses an array of buckets to store key-value pairs

  • The hash code of the key is used to determine the index of the bucket where the key-value pair is stored

  • If two keys have the same hash code, they are stored in the same bucket as a linked list

  • When retrieving a value, the hash code of the key is used to find the bucket and then the linked list is searched for the key

  • HashMa...read more

Q13. how to remove autoconfiguration in springboot

Ans.

To remove autoconfiguration in Spring Boot, exclude the specific autoconfiguration class from the application.

  • Exclude the autoconfiguration class using @EnableAutoConfiguration annotation with exclude attribute

  • Create a configuration class and exclude the specific autoconfiguration class using @EnableAutoConfiguration annotation

  • Use application.properties or application.yml to exclude autoconfiguration classes

Q14. Difference between @component and @configuration ?

Ans.

The @Component annotation is used to mark a class as a bean, while @Configuration is used to define a configuration class.

  • The @Component annotation is used to auto-detect and auto-configure beans using classpath scanning.

  • @Configuration classes are used to define beans and their dependencies explicitly.

  • A @Configuration class can contain @Bean methods that return bean instances.

  • A @Component class can be used as a bean in a Spring application context.

Q15. Write a program for customise exception

Ans.

A program to create custom exceptions in Java.

  • Create a class that extends Exception or RuntimeException

  • Add constructors to the custom exception class

  • Throw the custom exception in the code when needed

Q16. How microservices communicate?

Ans.

Microservices communicate through lightweight protocols like HTTP/REST or messaging systems like RabbitMQ.

  • Microservices can communicate through synchronous protocols like HTTP/REST, where one service sends a request to another service and waits for a response.

  • Microservices can also communicate through asynchronous messaging systems like RabbitMQ, where one service publishes a message to a queue and other services consume the message when they are ready.

  • Microservices can use l...read more

Q17. Garbage collector internal implementation algorithm

Ans.

Garbage collector is an automatic memory management system in Java that reclaims memory by deallocating objects no longer in use.

  • Garbage collector uses different algorithms like Mark-Sweep, Mark-Compact, and Copying to reclaim memory.

  • Mark-Sweep algorithm marks objects as reachable or unreachable, then sweeps through and deletes the unreachable objects.

  • Mark-Compact algorithm moves reachable objects to one end of the memory space and compacts them to free up space.

  • Copying algor...read more

Q18. Count dublicate name in SQL .

Ans.

To count duplicate names in SQL, use the GROUP BY clause with the COUNT function.

  • Use GROUP BY clause to group the names together

  • Use COUNT function to count the number of occurrences

  • Use HAVING clause to filter out names with count less than 2

Q19. how spring security works?

Ans.

Spring Security is a powerful and customizable authentication and access control framework for Java applications.

  • Spring Security provides comprehensive security services for Java EE-based enterprise software applications.

  • It offers authentication, authorization, and protection against common security vulnerabilities.

  • Configurations are typically done using XML or Java-based configuration.

  • It supports various authentication mechanisms such as form-based, HTTP Basic, and OAuth.

  • Dev...read more

Q20. What is collection framework

Ans.

Collection framework is a set of classes and interfaces that provide a standard way to store and manipulate groups of objects.

  • It provides interfaces like List, Set, and Map for storing collections of objects.

  • It includes classes like ArrayList, LinkedList, HashSet, and HashMap for implementing these interfaces.

  • Collections framework simplifies the process of storing, retrieving, and manipulating data in Java.

Q21. What is java and springboot

Ans.

Java is a popular programming language used for developing various applications. Spring Boot is a framework that simplifies the development of Java applications.

  • Java is an object-oriented programming language known for its platform independence and versatility.

  • Spring Boot is a framework that simplifies the development of Java applications by providing pre-configured settings and tools.

  • Spring Boot allows for rapid development and deployment of Java applications, making it popu...read more

Q22. New features of java 1.8

Ans.

Java 1.8 introduced lambda expressions, default methods, and functional interfaces.

  • Lambda expressions allow functional programming in Java.

  • Default methods allow adding new methods to interfaces without breaking existing implementations.

  • Functional interfaces are interfaces with a single abstract method, used for lambda expressions.

  • Stream API for processing collections and arrays.

  • Date and Time API for easier handling of date and time.

  • Nashorn JavaScript engine for embedding Java...read more

Q23. how Oauth2.0 works ?

Ans.

OAuth2.0 is an authorization framework that allows a user to grant limited access to their resources without sharing their credentials.

  • OAuth2.0 involves the client, resource server, authorization server, and the user.

  • The client requests authorization from the user and receives an access token from the authorization server.

  • The client then uses the access token to access the user's resources on the resource server.

  • OAuth2.0 supports different grant types such as authorization co...read more

Q24. Steam operations of student objects

Ans.

Using Java Stream operations to manipulate student objects

  • Use Stream API to perform operations on a collection of student objects

  • Apply filter, map, reduce, and other stream operations to transform and manipulate data

  • Use lambda expressions to define the operations to be performed on each student object

  • Example: filtering students based on a certain criteria, mapping student names to uppercase, calculating the average grade

Q25. expain springboot annotations

Ans.

Spring Boot annotations are used to simplify the development process by providing shortcuts for common tasks.

  • Annotations like @SpringBootApplication, @RestController, @Autowired, @GetMapping, @PostMapping are commonly used in Spring Boot applications.

  • These annotations help in configuring the application, defining RESTful endpoints, injecting dependencies, and mapping HTTP requests to controller methods.

  • Annotations like @Component, @Service, @Repository are used for component ...read more

Q26. Describe Api gateway

Ans.

API gateway is a server that acts as an API front-end, receiving API requests, enforcing throttling and security policies, passing requests to the back-end service, and then passing the response back to the requester.

  • Acts as a single entry point for all API requests

  • Enforces security policies and authentication

  • Handles request routing and load balancing

  • Provides caching and rate limiting

  • Logs and monitors API usage

  • Examples: Amazon API Gateway, Apigee, Kong

Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10k Interviews
3.9
 • 7.8k Interviews
3.7
 • 7.3k Interviews
3.7
 • 5.2k Interviews
3.8
 • 4.6k Interviews
3.6
 • 3.7k Interviews
3.6
 • 3.6k Interviews
3.6
 • 2.3k Interviews
3.7
 • 507 Interviews
3.4
 • 492 Interviews
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

Senior Java 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