What can go wrong with HashMap if all keys have the same hash code? Why will search slow down?
Java
Name a problem that can occur in a multithreaded application. Tell about Race Condition.
Question 1. Which data types cannot be used as keys in a HashMap? - Arrays - Atomics (AtomicBoolean, AtomicInteger, etc.) - Primitives - References
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
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
How to protect against mutation of an internal list through an external reference (defensive copy in the constructor)?
How to solve the deep copying problem (mutating list elements via AtomicInteger.incrementAndGet)?
Is it possible to implement a hashCode that always returns different values for different objects (without collisions)?
What are the ways to make a deep copy of an object?
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
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
How to protect against inheritance and overriding of getters (so that colleagues cannot override the getter and remove protective copying)?
What are the advantages of monolithic architecture?
Is it possible to use an array as a key in a HashMap? Why is this a bad idea?
What tools for synchronization are available in Java?
Where else is it convenient to use immutable objects besides as keys in HashMap?
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
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
What are the criteria for when to start breaking down a monolith into microservices?
Why did you decide to leave your current job?