Java Developer
1500+ Java Developer Interview Questions and Answers
You have been given an integer array/list(ARR) of size N that contains only integers, 0 and 1. Write a function to sort this array/list. Think of a solution which scans the array/list only once and don'...read more
The function sorts an integer array containing only 0s and 1s in linear time complexity.
Use two pointers, one starting from the beginning and the other from the end of the array.
Swap the elements at the pointers if the element at the beginning pointer is 1 and the element at the end pointer is 0.
Continue moving the pointers towards each other until they meet in the middle of the array.
Q2. Parent class has run() and walk() . Parent run() - calls walk() Child Class overrides Parent class Inside run() - calls super.run() Walk() - calls super.walk In main class Parent p = new child() p.run() What wi...
read moreThe order of execution will be: parent's run() -> child's run() -> parent's walk()
When p.run() is called, it will first execute the run() method of the parent class
Inside the parent's run() method, it will call the walk() method of the parent class
Since the child class overrides the parent class, the child's run() method will be executed next
Inside the child's run() method, it will call the run() method of the parent class using super.run()
Finally, the walk() method of the pa...read more
Java Developer Interview Questions and Answers for Freshers
You are given an array βARRβ of 'N' integers. Your task is to find the longest harmonious subsequence of this array.
A sequence is Harmonious if the difference between the maximum ...read more
You have been given a Binary Search Tree of integers. You are supposed to convert it to a greater sum tree such that the value of every node in the given BST is replaced with ...read more
The task is to convert a Binary Search Tree into a Greater Sum Tree.
Traverse the BST in reverse inorder (right, root, left) to visit nodes in descending order.
Keep track of the sum of all greater nodes encountered so far.
Update the value of each node by adding the sum of greater nodes and update the sum.
Continue this process until all nodes have been visited.
Return the modified BST.
You are given a string S of words. Your task is to count the occurrence of each word present in the string S. A word is a sequence of one or more non-space ch...read more
You are given a sorted integer array' ARR' of size 'N'. You need to remove the duplicates from the array such that each element appears only once. Return the length of this ...read more
Share interview questions and help millions of jobseekers π
You have been given an array/list βAβ consisting of βNβ integers all of which are β0β initially. You are given an array/list βARRβ consisting of βMβ...read more
Q8. What array list and linkedlist difference,how hashmap internally working,what is synchronised and it's type,what is difference between abstract and interface,class loading mechanism in Java, you hat is single t...
read moreJava Developer interview questions covering array list, linkedlist, hashmap, synchronization, abstract vs interface, singleton class, Spring framework, database configuration, and Java 8 features.
ArrayList and LinkedList differ in terms of implementation, performance, and usage
HashMap uses hashing to store and retrieve key-value pairs
Synchronized is used to ensure thread safety and prevent race conditions
Abstract classes cannot be instantiated and can have both abstract and n...read more
Java Developer Jobs
Q9. what are the difference between abstract class and interface, and throw and throws, and why we use throws?? Why String is Immutable?
Explaining differences between abstract class and interface, throw and throws, and why we use throws. Also, why String is immutable.
Abstract class can have both abstract and non-abstract methods, while interface can only have abstract methods.
A class can implement multiple interfaces, but can only extend one abstract class.
Throw is used to explicitly throw an exception, while throws is used to declare the exceptions that a method may throw.
We use throws to inform the caller o...read more
Q10. How to sort a list of students on the basis of their First name?
To sort a list of students on the basis of their First name, use the Collections.sort() method with a custom Comparator.
Create a custom Comparator that compares the first names of the students.
Implement the compare() method in the Comparator to compare the first names.
Use the Collections.sort() method to sort the list of students using the custom Comparator.
Q11. 2. What will happen if hashcode only returns a constant? How will it affect the internal working of the HashMap?
If hashcode returns a constant, all elements will be stored in the same bucket, resulting in poor performance.
All elements will be stored in the same bucket of the HashMap.
This will lead to poor performance as the HashMap will essentially become a linked list.
Retrieving elements will take longer as the HashMap will have to iterate through the linked list to find the desired element.
Which among String or String Buffer should be preferred when there are lot of updates required to be done in the data?
Q13. 1. Abstraction vs Inheritance 2. What is Garbage collector? 3. What is class loader? 4. Spring security 5. Scopes of bean 6. Wait , notify and notify all 7. Class level vs object level local 8. Arraylist vs Lin...
read moreJava interview questions covering topics like abstraction, inheritance, garbage collector, class loader, Spring security, bean scopes, wait-notify, class vs object level local, ArrayList vs LinkedList, Singleton class, and RestController vs Controller.
Abstraction focuses on hiding implementation details while inheritance allows a class to inherit properties and methods from another class.
Garbage collector is a program that automatically frees up memory by deleting objects tha...read more
Q14. Explain OOPS Concept? What is Polymorphism and Types of polymorphism? Write Code for compile time and Run time Polymorphism? What are singleton class and factory method? What is Exception and Exception Hierarch...
read moreJava interview questions on OOPS concepts, polymorphism, exceptions, data structures, and threading.
OOPS concepts include encapsulation, inheritance, and polymorphism.
Polymorphism refers to the ability of an object to take on multiple forms.
Singleton class is a class that can only have one instance, while factory method is a method that creates objects.
Exception is an error that occurs during program execution, with a hierarchy of exceptions.
Volatile keyword is used to indica...read more
Suppose you have a 4 liter jug and a 9 liter bucket . The buckets have no measurement lines on them either. How could you measure exactly 6 liter using only those buckets and you have as much extra water ...read more
Q16. write a code to filter out loans with incomplete status using java 8 features.
Code to filter out loans with incomplete status using Java 8 features.
Use stream() method to convert the list of loans into a stream
Use filter() method to filter out loans with incomplete status
Use collect() method to collect the filtered loans into a new list
Q17. Write a program to return the length of the longest word from a string whose length is even?
This program returns the length of the longest word from a string whose length is even.
Split the string into an array of words using a space as the delimiter.
Iterate through the array and check if the length of each word is even.
Keep track of the length of the longest even word encountered.
Return the length of the longest even word.
Which among String or String Buffer should be preferred when there are lot of updates required to be done in the
data?
Q19. 1.What is Singleton in java and create your own singleton class countering all breakable conditions? 2. What is Auto Configuration? 3. @Primary vs @Qualifier 4. What is idempotent? 5. What is class loader? Type...
read moreThe interview questions cover various topics related to Java development, including Singleton pattern, memory management, exception handling, Spring framework, and design patterns.
Singleton pattern ensures a class has only one instance and provides a global point of access to it.
Auto Configuration in Spring Boot automatically configures the Spring application based on dependencies present in the classpath.
@Primary annotation is used to give higher preference to a bean when mu...read more
What is the @Controller annotation used for? How can you create a controller without an annotation?
Q21. 5. If we have a mutable object inside immutable class then how will you handle it?
To handle a mutable object inside an immutable class, make the object private and provide only read-only access methods.
Make the mutable object private to encapsulate it within the immutable class.
Provide read-only access methods to retrieve the state of the mutable object.
Ensure that the mutable object cannot be modified from outside the class.
If necessary, create defensive copies of the mutable object to prevent unintended modifications.
Q22. 1. Can we keep an object of a Class as key in HashMap?
Yes, we can keep an object of a Class as a key in HashMap.
The key in a HashMap can be any non-null object.
The key's class must override the hashCode() and equals() methods for proper functioning.
If two objects have the same hashCode(), they will be stored in the same bucket and compared using equals().
If the key is mutable, its state should not be modified after it is used as a key in the HashMap.
Q23. What are the main OOPS concepts in java and explain one by one?
Java OOPS concepts include inheritance, polymorphism, encapsulation, and abstraction.
Inheritance allows a class to inherit properties and methods from another class.
Polymorphism allows objects to take on multiple forms and behave differently based on their context.
Encapsulation hides the implementation details of a class and only exposes necessary information.
Abstraction allows for the creation of abstract classes and interfaces that can be implemented by other classes.
Exampl...read more
Q24. write program fibonacci series, write program using boolean, write class cast exceptn, singleton design pattern(like you have to jvm one have jdk 1.7 and other have jdk 1.8 how many instance created if one then...
read moreThis interview question covers various topics including programming, design patterns, data structures, and exception handling in Java.
Write a program to generate the Fibonacci series
Write a program using boolean variables
Explain the ClassCastException and how to handle it
Discuss the Singleton design pattern and its implementation with different JDK versions
Explain abstract classes and interfaces in your current project
Explain hashing in HashMap and the number of buckets
Differ...read more
Take two numbers as input and swap them and print the swapped values.
Input Format:
The first line of input contains a single integer 't', representing the total...read more
Q26. Write a query to find name of authors who have written more than 10 books. Table - Bookauthhor Column - Book Column - Author
Query to find authors who have written more than 10 books
Use the GROUP BY clause to group the records by author
Use the HAVING clause to filter the groups with a count greater than 10
Join the Bookauthor table with the Author table to get the author names
Q27. Is Java platform-independent, if yes why?
Yes, Java is platform-independent because of its 'write once, run anywhere' principle.
Java programs are compiled into bytecode, which can be executed on any platform with a Java Virtual Machine (JVM).
The JVM acts as an interpreter, translating the bytecode into machine code specific to the underlying platform.
This allows Java programs to run on different operating systems and hardware architectures without modification.
For example, a Java program developed on a Windows machin...read more
Q28. 1. What is JDK, JVM, JRE.
JDK is a development kit, JRE is a runtime environment, and JVM is a virtual machine for executing Java code.
JDK includes JRE and development tools like javac and java
JRE includes JVM and necessary libraries to run Java applications
JVM is responsible for interpreting Java bytecode and executing it
Example: JDK 8 includes JRE 8 and development tools like javac and java
Example: JRE 8 includes JVM 8 and necessary libraries to run Java applications
What are the new features in Java8?
Given the head node of the singly linked list, return a pointer pointing to the middle of the linked list.
If there are an odd number of elements, return the middle element if there are eve...read more
What is the starter dependency of the Spring boot module?
Q32. What is the use of private variables even though they are accessible via getters and setters from some other class?
Private variables provide encapsulation and data hiding.
Private variables can only be accessed within the class they are declared in, providing encapsulation and preventing direct modification from outside the class.
Getters and setters provide controlled access to private variables, allowing for validation and manipulation of the data before it is accessed or modified.
For example, a class may have a private variable for a person's age, but the getter can return a calculated a...read more
Q33. Q1. What are the technologies you have worked on ? Q2. What are the corporate training you have attended ? Q3. How do you handle non-productive team members ? Q4. Tell us some of your extraordinary skills which...
read moreAnswers to interview questions for a Java Developer position
Q1. Mention the technologies you have worked on, such as Java, Spring, Hibernate, etc.
Q2. List any corporate training you have attended, like Java certification courses or workshops.
Q3. Explain how you handle non-productive team members, emphasizing communication and motivation strategies.
Q4. Highlight your extraordinary skills that set you apart from other technical associates, such as problem-solving abilities or l...read more
How would you differentiate between a String, StringBuffer, and a StringBuilder?
What are the advantages of Packages in Java?
What Are the Basic Annotations that Spring Boot Offers?
What is static variable and static method?
How would you differentiate between a String, StringBuffer, and a StringBuilder?
Q39. 3. What if we do not override Equals method ? What is we do not override Hashcode method?
Not overriding equals method can lead to incorrect comparison of objects. Not overriding hashCode method can lead to incorrect behavior in hash-based data structures.
If equals method is not overridden, the default implementation from Object class will be used which compares object references.
This can lead to incorrect comparison of objects where two different objects with same content are considered unequal.
If hashCode method is not overridden, the default implementation from...read more
Q40. 2.differance between throw and throws, and difference between final,finally,finalize and difference between arraylist and linked list
throw is used to explicitly throw an exception, while throws is used to declare exceptions that a method may throw.
throw is used within a method to throw an exception explicitly
throws is used in the method signature to declare the exceptions that the method may throw
final is a keyword used to make a variable, method, or class unchangeable
finally is a block that is used to execute code regardless of whether an exception is thrown or not
finalize is a method that is called by th...read more
Why Java is platform independent and JVM platform dependent?
Q42. 5. What are scope of beans? 6. Functional interfaces and examples 7. Can we make a class as private? 8. SQL query to find employees of particular department table. 9. Cascading 10. MapBy in hibernate 11. What i...
read moreJava Developer interview questions on beans, functional interfaces, SQL queries, hibernate, and more.
Scope of beans refers to the visibility of a bean within an application context.
Functional interfaces have only one abstract method and can be used as lambda expressions.
Classes cannot be private, but their constructors can be.
SQL query to find employees of a particular department table: SELECT * FROM employees WHERE department = 'department_name'
Cascading in Hibernate refers ...read more
How to enable debugging log in the spring boot application?
Q44. What are the principles of object oriented programming, such as OOPs concepts in Java
Object-oriented programming (OOP) principles in Java include encapsulation, inheritance, polymorphism, and abstraction.
Encapsulation: Bundling data and methods together into a single unit (class) to hide implementation details.
Inheritance: Creating new classes (subclasses) from existing classes (superclasses) to inherit properties and behaviors.
Polymorphism: The ability of an object to take on many forms, allowing objects of different classes to be treated as objects of a com...read more
What does the @SpringBootApplication annotation do internally?
Q46. If we have @Service, @Controller, @Configuration, and @Repository why do we need @Component? Can we replace them with @Component?
The @Component annotation is a generic stereotype annotation that can be used in place of other annotations.
The @Component annotation is a general-purpose annotation that can be used in place of @Service, @Controller, @Configuration, and @Repository annotations.
However, using more specific annotations can help in better understanding the role of the annotated class.
For example, using @Service annotation on a class that provides a service makes it easier to understand the purp...read more
Q47. Tell me some keywords to make a thread safe program in java ?
Keywords for thread safe program in Java
Synchronization using synchronized keyword
Using volatile keyword for shared variables
Using atomic classes for thread safe operations
Using thread safe collections like ConcurrentHashMap
Using locks and semaphores for synchronization
Avoiding shared mutable state
Using immutable objects
Using thread local variables
Q48. what is interface, inheritance doesn't supported by java, where to use interface, what are the advantage of using program to reverse each word in a string (eg. input -> pace wisdom output ->ecap modsiw)
Answering questions related to Java interfaces and string manipulation
Interface is a collection of abstract methods that can be implemented by a class
Inheritance is supported by Java, but only single inheritance is allowed
Interfaces are used to achieve abstraction and provide a contract for implementing classes
Advantages of program to reverse each word in a string include improved readability and searchability
To reverse each word in a string, split the string into words, reve...read more
What is the root application context in Spring MVC? How is it loaded?
Q50. Using Java 8 find the sum of squares of all the odd numbers in the arraylist.
Using Java 8, find the sum of squares of all the odd numbers in the arraylist.
Use the stream() method to convert the ArrayList to a stream
Use the filter() method to filter out the even numbers
Use the mapToInt() method to square each odd number
Use the sum() method to find the sum of the squared odd numbers
Interview Questions of Similar Designations
Top Interview Questions for Java Developer Related Skills
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