Sobes.tech

What can go wrong with HashMap if all keys have the same hash code? Why will search slow down?

204

Name a problem that can occur in a multithreaded application. Tell about Race Condition.

203

Question 1. Which data types cannot be used as keys in a HashMap? - Arrays - Atomics (AtomicBoolean, AtomicInteger, etc.) - Primitives - References

182

Question 7. There is a service ExampleService (see figure). If an external service calls methods in sequence: exampleService.getCityFromCache(100000); exampleService.getCity(100000); How many times will there be a call to CityDao::getCity if the cache was empty? @Component @RequiredArgsConstructor public class ExampleService { private final CityDao dao; @Cacheable public String getCityFromCache(int index) { return dao.getCity(index); } public String getCity(int index) { return getCityFromCache(index); } } 0 1 2 Depends on the implementation of CacheManager

176

Question 6. 10 messages are added to a Kafka topic, and two consumers with different consumer groups read from the topic. How many messages does each consumer read? 5 10 Depends on the number of partitions in the topic Depends on the value of replicationFactor

161

How to protect against mutation of an internal list through an external reference (defensive copy in the constructor)?

150

How to solve the deep copying problem (mutating list elements via AtomicInteger.incrementAndGet)?

147

Is it possible to implement a hashCode that always returns different values for different objects (without collisions)?

147

What are the ways to make a deep copy of an object?

146

Question 3. What can go wrong if the key object field used for calculating hashCode is changed after insertion into HashMap? - Searching by key will return the wrong object - Searching by key will slow down - Searching by key will not return the object

145

Question 2. What can go wrong with HashMap if all keys have the same hashCode? - Searching by key will not return the correct object - Searching by key will slow down - Searching by key will not return the object

142

How to protect against inheritance and overriding of getters (so that colleagues cannot override the getter and remove protective copying)?

140

What are the advantages of monolithic architecture?

140

Is it possible to use an array as a key in a HashMap? Why is this a bad idea?

135

What tools for synchronization are available in Java?

134

Where else is it convenient to use immutable objects besides as keys in HashMap?

132

Question 4. What is JIT compilation? - Compiling code into a jar file - Compiling bytecode into machine code during program execution - Compiling JavaScript into machine code for performance optimization - Compiling a project in a git pipeline

130

Question 9. Write a query that returns employees with the highest salary in their position. Initialization script: CREATE TABLE users ( fio TEXT NOT NULL, position TEXT, salary BIGINT NOT NULL ); INSERT INTO users(fio, position, salary) VALUES ('Ivanov', 'Tester', 100000), ('Gorokhov', 'Tester', 120000), ('Petrov', 'Tester', 140000), ('Sidorov', 'Tester', 100000), ('Kuznetsov', 'Tester', 120000), ('Mikhaylov', 'Tester', 150000), ('Antonov', 'Developer', 200000), ('Sukhoi', 'Developer', 100000), ('Mikoyan', 'Developer', 100000), ('Kapustin', 'Director', 300000), ('Astakhov', 'IT', 200000); Example result: Mikhaylov Tester 150000 Antonov Developer 200000 Kapustin Director 300000 Astakhov IT 200000

130

What are the criteria for when to start breaking down a monolith into microservices?

124

Why did you decide to leave your current job?

123
/2