
Deloitte


30+ Deloitte Java Developer Interview Questions and Answers
Q1. Sort 0 and 1 Problem Statement
Given an integer array ARR
of size N
containing only integers 0 and 1, implement a function to sort this array. The solution should scan the array only once without using any addi...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. Convert BST to Greater Sum Tree
Given a Binary Search Tree (BST) of integers, your task is to convert it into a greater sum tree. In the greater sum tree, each node's value should be replaced with the sum of al...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.
Q3. Write a code for Iterate hashmap using iterator
Iterate through a hashmap using an iterator in Java
Create an iterator using the entrySet() method of the hashmap
Use a while loop to iterate through the hashmap entries
Access the key and value of each entry using the getKey() and getValue() methods
Q4. Do you have exp in Kubernetes?
Yes, I have experience in Kubernetes.
I have worked on deploying and managing applications on Kubernetes clusters.
I am familiar with creating and managing Kubernetes resources such as pods, deployments, services, and ingresses.
I have experience in using tools like kubectl and Helm for interacting with Kubernetes clusters.
I have implemented CI/CD pipelines using Kubernetes for automated deployment and scaling of applications.
Q5. What is @PreAuthorize and @PostAuthorize
Annotations used in Spring Security to apply authorization rules before and after a method is called.
Used in Spring Security to define authorization rules
@PreAuthorize is used to apply authorization rules before a method is called
@PostAuthorize is used to apply authorization rules after a method is called
Both annotations support SpEL expressions for defining rules
Q6. How much exp in docker?
I have 2 years of experience working with Docker in various projects.
2 years of experience working with Docker in various projects
Proficient in creating Docker containers, managing images, and orchestrating containers using Docker Compose
Familiar with Docker Swarm and Kubernetes for container orchestration
Experience in troubleshooting Docker-related issues and optimizing container performance
Q7. how authentication and authorization works in java
Authentication verifies the identity of a user, while authorization determines what actions they are allowed to perform.
Authentication is the process of verifying the identity of a user, typically through credentials like username and password.
Authorization determines what actions a user is allowed to perform after they have been authenticated.
Java provides various authentication mechanisms like Basic Authentication, Digest Authentication, and OAuth.
Authorization in Java can ...read more
Q8. What is spring profile
Spring profile is a way to segregate parts of your application configuration and make it only available in certain environments.
Spring profiles allow you to define different configurations for different environments such as development, testing, and production.
You can use @Profile annotation to specify which beans should be loaded based on the active profile.
Profiles can be activated in various ways such as through application properties, environment variables, or command lin...read more
Q9. Explain Oops Concept, keywords in java, access specifiers
OOPs concept in Java includes keywords and access specifiers for defining classes and objects.
OOPs concept focuses on objects and classes for code organization
Keywords like 'class', 'extends', 'implements' are used for defining classes and inheritance
Access specifiers like 'public', 'private', 'protected' control visibility of class members
Q10. java 8 features, write lambda function to add two numbers
Lambda functions in Java 8 allow for concise and functional programming style.
Use the lambda operator '->' to define the lambda function.
Specify the parameters and the body of the lambda function.
Example: (int a, int b) -> a + b
Q11. Find second Max salary? How internally hashmap grows its size? SOLID principles?
To find the second highest salary, sort the salaries in descending order and skip the first one.
Sort the salaries in descending order
Skip the first salary to get the second highest salary
Handle edge cases like duplicates or null values
Q12. What is OOP?
OOP stands for Object-Oriented Programming, a programming paradigm based on the concept of objects.
OOP focuses on creating objects that contain data and methods to manipulate that data.
Encapsulation, inheritance, and polymorphism are key principles of OOP.
Examples of OOP languages include Java, C++, and Python.
Q13. Coding question - find repeat elements in an array
Find repeat elements in an array of strings
Iterate through the array and store each element in a HashMap with its count
Check if the count of any element is greater than 1, then it is a repeat element
Return the repeat elements found in the array
Q14. Explain the architecture for a student management system in springboot
A student management system in SpringBoot involves multiple layers like controller, service, repository, and database.
Use SpringBoot for creating RESTful APIs to handle student data
Implement controller layer to handle incoming HTTP requests and route them to appropriate service methods
Service layer contains business logic for managing student data
Repository layer interacts with the database to perform CRUD operations on student entities
Use JPA for mapping Java objects to data...read more
Q15. What is hashmap
HashMap is a data structure in Java that stores key-value pairs and allows fast retrieval of values based on keys.
HashMap implements the Map interface in Java
It allows null keys and values
Keys in a HashMap must be unique
Example: HashMap
map = new HashMap<>()
Q16. Internal Working of hashmap
HashMap is a data structure that stores key-value pairs and uses hashing to efficiently retrieve values.
HashMap internally uses an array of linked lists to store key-value pairs.
When a key-value pair is added, the key is hashed to determine the index in the array where it will be stored.
If multiple keys hash to the same index, a linked list is used to handle collisions.
HashMap uses the hashCode() method of keys to calculate the hash value.
HashMap allows one null key and multi...read more
Q17. Types of polymorphism
Polymorphism in Java refers to the ability of a method to do different things based on the object it is acting upon.
Types of polymorphism in Java include method overloading and method overriding.
Method overloading is when multiple methods have the same name but different parameters.
Method overriding is when a subclass provides a specific implementation of a method that is already defined in its superclass.
Q18. Compare Throw vs Throws
Throw is used to explicitly throw an exception in a method, while Throws is used to declare the 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.
Throw is followed by an instance of Throwable class, while Throws is followed by the exception class names separated by commas.
Example: throw new IllegalArgumentException();
Example: public void m...read more
Q19. Arraylist vs LinkedList/Vector
ArrayList is resizable array implementation, LinkedList is doubly linked list implementation, Vector is synchronized version of ArrayList.
ArrayList is faster for accessing elements, LinkedList is faster for adding/removing elements in middle.
ArrayList uses less memory than LinkedList due to contiguous memory allocation.
Vector is thread-safe but slower than ArrayList due to synchronization overhead.
Q20. How does Hashmap works internally
HashMap is an implementation of Map interface that stores key-value pairs using a hash table.
HashMap uses hashing to store and retrieve elements.
It uses an array of linked lists to handle collisions.
The hash code of the key is used to determine the index of the array.
If multiple keys have the same hash code, they are stored in the same linked list.
When retrieving a value, the hash code is used to find the correct linked list and then linearly search for the key.
HashMap allows...read more
Q21. Build a basic CRUD REST API endpoint
Build a basic CRUD REST API endpoint
Create a REST API endpoint for each CRUD operation (Create, Read, Update, Delete)
Use HTTP methods like POST, GET, PUT, DELETE to perform CRUD operations
Implement data validation and error handling for each operation
Utilize a framework like Spring Boot or Express.js to simplify API development
Q22. SQL question - third highest salary
To find the third highest salary in a SQL table, you can use the 'SELECT TOP 1' statement with 'ORDER BY salary DESC OFFSET 2 ROWS FETCH NEXT 1 ROWS ONLY'.
Use the 'SELECT TOP 1' statement to retrieve only one record
Order the records by salary in descending order using 'ORDER BY salary DESC'
Skip the first two highest salaries using 'OFFSET 2 ROWS'
Fetch the next record after skipping the first two using 'FETCH NEXT 1 ROWS ONLY'
Q23. Array vs Arraylist
Arrays are fixed in size, while ArrayLists can dynamically resize. ArrayLists provide more flexibility and functionality.
Arrays have a fixed size, while ArrayLists can dynamically resize.
ArrayLists can easily add, remove, or modify elements, while arrays require manual shifting of elements.
Arrays use [] syntax for declaration and initialization, while ArrayLists use the ArrayList class from the Java Collections framework.
Q24. how to create rest API
To create a REST API, you need to define endpoints, implement CRUD operations, handle HTTP methods, and use frameworks like Spring Boot.
Define endpoints for different resources (e.g. /users, /products)
Implement CRUD operations (Create, Read, Update, Delete) for each endpoint
Handle HTTP methods like GET, POST, PUT, DELETE
Use frameworks like Spring Boot to simplify API development
Q25. Thread in java
Threads in Java allow multiple tasks to run concurrently within a single program.
Threads are lightweight sub-processes that share the same memory space.
They are used to improve performance by allowing tasks to run simultaneously.
Examples include creating a new thread using the Thread class or implementing the Runnable interface.
Q26. What are java solid principles
Java SOLID principles are a set of design principles that help in creating maintainable and scalable software.
S - Single Responsibility Principle: A class should have only one reason to change.
O - Open/Closed Principle: Software entities should be open for extension but closed for modification.
L - Liskov Substitution Principle: Subtypes must be substitutable for their base types.
I - Interface Segregation Principle: Clients should not be forced to depend on interfaces they do ...read more
Q27. Diff between arraylist and linkedlist
ArrayList is implemented using a dynamic array while LinkedList is implemented using a doubly linked list.
ArrayList provides fast random access and slower insertion/deletion, while LinkedList provides fast insertion/deletion and slower random access.
ArrayList uses more memory as it needs to allocate a fixed-size array, while LinkedList uses more memory for storing references to the next and previous elements.
Example: ArrayList is suitable for scenarios where random access is ...read more
Q28. Difference between hashmap and hashtable
HashMap is non-synchronized and allows null values, while Hashtable is synchronized and does not allow null keys or values.
HashMap is non-synchronized, meaning it is not thread-safe, while Hashtable is synchronized and thread-safe.
HashMap allows null values and one null key, while Hashtable does not allow null keys or values.
HashMap is generally preferred for non-thread-safe applications, while Hashtable is used in thread-safe scenarios.
Q29. Diff between set and list
Set is a collection of unique elements with no specific order, while list is a collection of elements with a specific order and allows duplicates.
Set does not allow duplicate elements, while list allows duplicates.
Set does not maintain insertion order, while list maintains insertion order.
Examples: HashSet is a set implementation, ArrayList is a list implementation.
Q30. coding reverse a palindrome
Reverse a palindrome string using Java
Create a function to check if a string is a palindrome
If the string is a palindrome, reverse it using a StringBuilder
Return the reversed string
Q31. solid design principles
Solid design principles are a set of best practices for designing software that is maintainable, scalable, and flexible.
Single Responsibility Principle - each class should have only one responsibility
Open/Closed Principle - classes should be open for extension but closed for modification
Liskov Substitution Principle - objects of a superclass should be replaceable with objects of its subclasses without affecting the program's correctness
Interface Segregation Principle - client...read more
Q32. design patterns in java
Design patterns in Java are reusable solutions to common problems in software design.
Design patterns help in creating flexible, maintainable, and scalable code.
Examples of design patterns in Java include Singleton, Factory, Observer, and Strategy.
Each design pattern has its own purpose and can be applied in different scenarios.
Understanding design patterns is essential for Java developers to write efficient code.
Q33. Working of hashset
HashSet is a collection that does not allow duplicate elements and does not guarantee the order of elements.
HashSet uses a hash table for storage.
Elements are stored based on their hash code.
Adding an element to a HashSet returns false if the element is already present.
Example: HashSet
set = new HashSet<>(); set.add("apple");
Q34. Program on sorting
Sorting program to arrange strings in alphabetical order
Use Arrays.sort() method to sort the array of strings
Implement a custom Comparator to sort in a specific order
Consider using Collections.sort() for sorting ArrayList of strings
More about working at Deloitte




Interview Process at Deloitte Java Developer

Top Java Developer Interview Questions from Similar Companies








Reviews
Interviews
Salaries
Users/Month

