-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Structure change in repo. More organised files and folder. More Filtered and Perfectly Curated Content added.
- Loading branch information
1 parent
985d08b
commit e2b1bb4
Showing
18 changed files
with
403 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Accolite Digital Senior Java Developer Interview Questions (3+ YOE) | ||
|
||
## Round 1 | ||
|
||
1. ArrayList vs LinkedList | ||
2. Write Deque Implementation Code | ||
3. Interface vs Abstract Class | ||
4. Find Palindrome of a Given String and Write Code | ||
5. Explain Internal Working of HashMap | ||
6. Code to Increment Counter Using Static Variable | ||
7. Queue vs Stack | ||
8. Compile Time vs Runtime Polymorphism | ||
9. Instance Variable vs Static Variable | ||
10. Find Equilibrium Index of an Array and Write Code | ||
11. LinkedList vs Circular LinkedList | ||
12. Write Code to Convert Integer to Binary Format, Count Frequency of 0s | ||
13. Difference Between HashSet and TreeSet | ||
14. Explain the Concept of Garbage Collection in Java | ||
|
||
## Round 2 | ||
|
||
1. Functional Interface | ||
2. Comparable vs Comparator | ||
3. Stream API | ||
4. Abstract Factory & Factory Design Pattern | ||
5. Write a Java Program that Takes a List of Integers as Input and Returns the Squares of All the Odd Numbers in the List, Using the Stream API. | ||
6. Find Subarray with Given Sum | ||
7. Design Patterns | ||
8. Role and Responsibilities within Project | ||
9. Challenges Faced within Project | ||
10. Java 8 Features | ||
11. HashMap Related Code | ||
12. How to Break Singleton Pattern | ||
13. Difference Between Synchronized and Concurrent Collections | ||
14. Explain the ‘volatile’ Keyword in Java | ||
|
||
## Round 3 | ||
|
||
1. Find the Nth Highest Salary | ||
2. Monolithic vs Microservices | ||
3. Check if Array is Sorted or Not | ||
4. Fault Tolerance in Microservices | ||
5. Join Related Questions | ||
6. Explain the Use of Docker in Microservices Architecture | ||
7. Discuss a Scenario Where You Implemented a Microservice |
12 changes: 12 additions & 0 deletions
12
Company-Wise/Altran_Java_Developer_First_Round/One-Plus-Years-Experience.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
1. Internal working of HashMap Is HashMap thread-safe? | ||
2. Can you inherit private methods of a class? | ||
3. Can you override private methods? | ||
4. Can you override member variables of a class? | ||
5. How to create a Singleton class How to do shallow copy in Java | ||
6. What is the use of Cloneable interface? Which class has the clone method? Why is the clone method in the Object class? | ||
7. Explain serialization and deserialization | ||
8. What is dependency injection in Spring Boot? How to do dependency injection in code? | ||
9. Explain @Autowired annotation | ||
10. What is the difference between @RestController and @Service? | ||
11. How do we create beans in Spring Boot? | ||
12. What are microservices? Have you heard of Discovery Service? |
20 changes: 20 additions & 0 deletions
20
Company-Wise/Inevestment_Banks/Core-Java-Interview-Questions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
- How does substring () inside String works? | ||
- What is a classloader? | ||
- How is the creation of a String using new() different from that of a literal? | ||
- What is difference between Executor.submit () and Executer.execute() method? | ||
- What do you understand by Java Memory Model? | ||
- How to make a class Immutable? What purpose does it solve? | ||
- Can you use HashMap in the multi-threaded environment? What can be the problem? | ||
- Can you write a critical section code for the singleton? | ||
- What is Singleton? is it better to make the whole method synchronized or only the critical section synchronized? | ||
- How do you avoid deadlock in Java? | ||
- How can you avoid serialization in the child class if the base class is implementing the Serializable interface? | ||
- What is the ConcurrentHashMap in Java and do you implement it? | ||
- Explain the FailFast iterator and Fail Safe iterator along with examples for each. | ||
- What is the difference between Checked Exception and Unchecked Exception? | ||
- What is the difference between factory and abstract factory pattern? | ||
- What is marker interface? | ||
- When Finally block doesn't get executed? | ||
- How does Garbage collection in Java works? | ||
- Difference between ClassNotFound vs NoClassDefError? | ||
- How to break Singleton? |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
**Designing a Least Recently Used (LRU) cache is a common interview question (Asked in Citi Bank)** | ||
|
||
## Understand Concept, Design, and implementation : | ||
|
||
- An LRU cache evicts the least recently used items first when it reaches its capacity. Here’s how we can approach this problem: | ||
|
||
- **Main Concepts:** | ||
|
||
**Cache Operations:** The cache should support two primary operations: | ||
|
||
`get(key):` Return the value of the key if it exists in the cache, otherwise return -1. | ||
`put(key, value):` Insert or update the value of the key. If the cache reaches its capacity, it should invalidate the least recently used item. | ||
|
||
**Data Structures:** | ||
|
||
`HashMap:` For O(1) access to cache items by key. | ||
Doubly Linked List: To keep track of the usage order of cache items. The most recently used items are moved to the front, and the least recently used items are at the end. | ||
|
||
**Class Structure** | ||
|
||
- **LRU Cache Class** | ||
|
||
This class will contain the core logic of the LRU cache. | ||
|
||
**Attributes:** | ||
|
||
`capacity:` The maximum number of items the cache can hold. | ||
map: A HashMap that maps keys to nodes in the doubly linked list. | ||
head and tail: Nodes to represent the boundaries of the doubly linked list. | ||
|
||
**Methods:** | ||
|
||
`get(int key):` Retrieves an item from the cache. | ||
`put(int key, int value):` Adds or updates an item in the cache. | ||
`Helper` methods for managing the doubly linked list: | ||
`addNode(Node node):` Adds a new node right after the head. | ||
`removeNode(Node node):` Removes an existing node from the list. | ||
`moveToHead(Node node):` Moves an existing node to the head. | ||
`popTail():` Removes the node at the tail and returns it. | ||
|
||
**Node Class** | ||
|
||
This class represents each node in the doubly linked list. | ||
|
||
**Attributes:** | ||
|
||
`key:` The key of the cache item. | ||
`value:` The value of the cache item. | ||
`prev:` Pointer to the previous node. | ||
`next:` Pointer to the next node. | ||
|
||
- **Designing Concept :** | ||
Let's design and implement a Least Recently Used (LRU) cache in Java. An LRU cache is a data structure that stores a fixed number of key-value pairs and evicts the least recently used item when the cache reaches its capacity. | ||
|
||
We can implement the LRU cache using a combination of a HashMap for fast key-value lookups and a doubly linked list to keep track of the access order of the elements. | ||
|
||
Here's the basic outline of our LRU cache implementation: | ||
|
||
1. Define a `Node` class to represent individual elements in the doubly linked list. Each node will store a key-value pair. | ||
2. Define a `LRUCache` class that contains the HashMap for fast lookups and the doubly linked list to maintain the access order. | ||
3. Implement methods to perform operations such as `get` (retrieve value for a given key), `put` (insert or update a key-value pair), and `evict` (remove the least recently used item when the cache is full). | ||
|
||
- **Implementation Solution :** | ||
|
||
```java | ||
import java.util.HashMap; | ||
|
||
class Node { | ||
int key; | ||
int value; | ||
Node prev; | ||
Node next; | ||
|
||
public Node(int key, int value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
} | ||
|
||
public class LRUCache { | ||
private HashMap<Integer, Node> map; | ||
private Node head; | ||
private Node tail; | ||
private int capacity; | ||
|
||
public LRUCache(int capacity) { | ||
this.capacity = capacity; | ||
map = new HashMap<>(); | ||
head = new Node(-1, -1); // Dummy head node | ||
tail = new Node(-1, -1); // Dummy tail node | ||
head.next = tail; | ||
tail.prev = head; | ||
} | ||
|
||
public int get(int key) { | ||
if (!map.containsKey(key)) | ||
return -1; | ||
|
||
Node node = map.get(key); | ||
moveToHead(node); // Move accessed node to the head | ||
return node.value; | ||
} | ||
|
||
public void put(int key, int value) { | ||
if (map.containsKey(key)) { | ||
Node node = map.get(key); | ||
node.value = value; // Update value | ||
moveToHead(node); // Move accessed node to the head | ||
} else { | ||
if (map.size() == capacity) { | ||
evict(); // Remove least recently used item if capacity is reached | ||
} | ||
|
||
Node newNode = new Node(key, value); | ||
addToHead(newNode); | ||
map.put(key, newNode); | ||
} | ||
} | ||
|
||
private void moveToHead(Node node) { | ||
removeNode(node); | ||
addToHead(node); | ||
} | ||
|
||
private void removeNode(Node node) { | ||
node.prev.next = node.next; | ||
node.next.prev = node.prev; | ||
} | ||
|
||
private void addToHead(Node node) { | ||
node.next = head.next; | ||
node.prev = head; | ||
head.next.prev = node; | ||
head.next = node; | ||
} | ||
|
||
private void evict() { | ||
Node leastUsed = tail.prev; | ||
removeNode(leastUsed); | ||
map.remove(leastUsed.key); | ||
} | ||
|
||
public static void main(String[] args) { | ||
LRUCache cache = new LRUCache(2); // Create an LRU cache with capacity 2 | ||
cache.put(1, 1); | ||
cache.put(2, 2); | ||
System.out.println(cache.get(1)); // Output: 1 (1 is present in the cache) | ||
cache.put(3, 3); // evicts key 2 | ||
System.out.println(cache.get(2)); // Output: -1 (2 is not present in the cache) | ||
cache.put(4, 4); // evicts key 1 | ||
System.out.println(cache.get(1)); // Output: -1 (1 is not present in the cache) | ||
System.out.println(cache.get(3)); // Output: 3 (3 is present in the cache) | ||
System.out.println(cache.get(4)); // Output: 4 (4 is present in the cache) | ||
} | ||
} | ||
``` |
61 changes: 61 additions & 0 deletions
61
Java-Coding-Questions/Design-Pattern-Java/Singelton-Design-Pattern.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
- **Asked in Roche Holding AG (Pharmaceutical Company)** | ||
- Role : Java Developer 1 Yr. Exp. | ||
|
||
1. **Question :** Implement a thread-safe Singleton class in Java using the double-checked locking. | ||
|
||
**Solution:** To create a thread-safe Singleton class using double-checked locking in Java, we have to follow below steps: | ||
|
||
- Declare a private static volatile instance variable. | ||
- Define a private constructor to prevent instantiation from outside the class. | ||
- Implement a public static method that returns the Singleton instance, using double-checked locking. | ||
|
||
Implementation: | ||
|
||
```java | ||
public class Singleton { | ||
// Volatile keyword ensures that changes to the uniqueInstance variable are visible to all threads. | ||
private static volatile Singleton uniqueInstance; | ||
|
||
private Singleton() {} | ||
|
||
public static Singleton getInstance() { | ||
if (uniqueInstance == null) { // First check (without locking) | ||
synchronized (Singleton.class) { | ||
if (uniqueInstance == null) { // Second check (with locking) | ||
uniqueInstance = new Singleton(); | ||
} | ||
} | ||
} | ||
return uniqueInstance; | ||
} | ||
} | ||
``` | ||
|
||
2. 𝐇𝐨𝐰 𝐭𝐨 𝐩𝐫𝐞𝐯𝐞𝐧𝐭 𝐒𝐢𝐧𝐠𝐥𝐞𝐭𝐨𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧 𝐟𝐫𝐨𝐦 𝐂𝐥𝐨𝐧𝐢𝐧𝐠 - (𝐀𝐬𝐤𝐞𝐝 𝐢𝐧 𝐃𝐞𝐥𝐨𝐢𝐭𝐭𝐞) | ||
**Solution :** Singleton Design pattern ensures that there is only one instance of a class created in the application. This is achieved by making the constructor private and providing a public static method to access the instance. | ||
|
||
Singleton design pattern is broken when the class implements the Cloneable interface. This is because the clone() method can be used to create multiple instances of the class, which violates the singleton design pattern. To handle this, we can override clone() method and throw an exception from clone method that is 𝐂𝐥𝐨𝐧𝐞𝐍𝐨𝐭𝐒𝐮𝐩𝐩𝐨𝐫𝐭𝐞𝐝𝐄𝐱𝐜𝐞𝐩𝐭𝐢𝐨𝐧. Now, whenever user will try to create clone of singleton object, it will throw an exception and hence our class remains singleton. | ||
|
||
```java | ||
public class Singleton { | ||
|
||
private static Singleton instance; | ||
|
||
private Singleton() { | ||
} | ||
|
||
public static synchronized Singleton getInstance() { | ||
if (instance == null) { | ||
instance = new Singleton(); | ||
} | ||
return instance; | ||
} | ||
|
||
@Override | ||
protected Object clone() throws CloneNotSupportedException { | ||
throw new CloneNotSupportedException("Cloning is not allowed."); | ||
} | ||
} | ||
``` | ||
|
||
We can also return the same instance from the clone method instead of throwing exception. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Stream API : | ||
|
||
1. Create a stream pipeline to group a list of strings by their length. | ||
2. Write a program to count the number of occurrences of each character in a string using streams. | ||
3. Given a list of Employee objects, find the employee with the highest salary using streams. | ||
4. Using streams, filter a list of numbers to only include those greater than 10 and then find their average. | ||
5. Write a program to concatenate a list of strings into a single string, separated by commas, using streams. | ||
6. Using Java Streams, convert a list of strings to a map where the key is the string and the value is its length. | ||
7. Write a stream operation to flatten a list of lists of integers into a single list of integers. | ||
8. Given a list of transactions, filter out transactions of a specific type and collect them into a set. | ||
9. Create a stream pipeline to find the first name of the oldest person in a list of Person objects. | ||
10. Write a program to find the first non-repeating character in a string using streams. | ||
11. Using streams, find the sum of the squares of a list of integers. | ||
12. Write a stream operation to skip the first 5 elements in a list and then print the rest. | ||
13. Create a stream to generate an infinite sequence of random numbers and print first 10. | ||
14. Using streams, partition a list of integers into even and odd numbers. | ||
15. Write a program to convert a list of strings to a list of their respective lengths using streams. | ||
16. Using streams, find the product of all elements in a list of integers. | ||
17. Create a stream pipeline to collect all unique words from a list of sentences. | ||
18. Write a program to filter out null values from a list of strings using streams. | ||
19. Using streams, merge two lists of integers and remove duplicates. | ||
20. Write a stream operation to check if any string in a list starts with a specific prefix. |
2 changes: 2 additions & 0 deletions
2
Java-Coding-Questions/ReverseString.java → ...oding-Questions/String/ReverseString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Java-Coding-Questions/ReverseString1.java → ...ding-Questions/String/ReverseString1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ding-Questions/ReverseStringPingPong.java → ...estions/String/ReverseStringPingPong.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package String; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
1 change: 1 addition & 0 deletions
1
...ions/ReverseStringPingPongBruteForce.java → ...ring/ReverseStringPingPongBruteForce.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
**Java 7 or We Just Say General Jva Questions Mostly Asked in Interviews** | ||
|
||
1. What is the difference between HashMap and HashTable? | ||
2. How does hashmap work internally? | ||
3. What is a singleton design pattern? | ||
4. What is the Runtime exception? How to create a custom runtime exception? | ||
5. What are the bean scopes? Difference between singleton and Request bean scope? | ||
6. What are actuators? | ||
7. Which algorithm is used in garbage collector? | ||
8. What is Method Reference in Java 8? | ||
9. Write a Program to print only numbers from an alphanumeric char array using Java 8. | ||
10. Can we override the static method? | ||
11. Write a Program to find the duplicates in an array using stream API. | ||
12. Explain Throw, throws, and throwable keywords in Java. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Java 8 Topic Wise QUestions | ||
|
||
## Lambda in Java 8: | ||
|
||
1. What is a lambda expression in Java 8? | ||
2. What are the main benefits of using lambda expressions in Java 8? | ||
3. Explain the syntax of a lambda expression in Java 8. | ||
4. What is the relationship between functional interfaces and lambda expressions? | ||
5. How do lambda expressions improve code readability and maintainability? | ||
6. What are method references in Java 8 and how do they relate to lambda expressions? | ||
7. What is the difference between a lambda expression and an anonymous class? | ||
8. How do lambda expressions enable functional programming in Java? | ||
9. Can lambda expressions be used with collections and streams? Explain with an example. | ||
10. Explain the role of the@Functionallnterface annotation. | ||
11. How does type inference work in lambda expressions? | ||
12. Write a lambda expression to sort a list of strings in descending order. | ||
13. How would you filter a list of integers to find all even numbers using lambda expressions and streams? | ||
14. Demonstrate how to use a lambda expression to implement a custom comparator for sorting a list of objects. | ||
15. Show how to use a lambda expression to print each element of a list. | ||
16. Implement a lambda expression to convert a list of strings to uppercase. | ||
17. Write a lambda expression to sum all elements in a list of integers. | ||
18. Create a lambda expression to find the maximum value in a list of integers. | ||
19. Demonstrate the use of a lambda expression to group elements in a list by a specific criterion. | ||
20. Implement a lambda expression to find the first element in a stream that matches a given predicate. | ||
21. Write a lambda expression to concatenate a list of strings with a delimiter. |
Oops, something went wrong.