// 3 public class Variables { public static void main(String[] args) { A a = new A(); a.val = 1; inc(a); System.out.println(a.val); set(a); System.out.println(a.val); } public static class A { public int val; } public static void inc(A a) { a.val++; } public static void set(A a) { a = new A(); a.val = 10; } }
Java
What is next after the first ticket? How to build further development for a junior?
What is the purpose of the @Transactional annotation in transaction management?
ArrayList vs LinkedList when iterating over a million elements — which is faster?
What is DDD (Domain-Driven Design)? How is it related to aggregate and bounded context?
What problem occurs when calling an @Transactional method from another method of the same class?
/** * Interface for interacting with ATM hardware. */ interface Hardware { /** * Returns an array with the number of banknotes by denominations 50, 100, 500, 1000, 5000. * The method is slow and creates noise. * * @return array where each element corresponds to the number of banknotes of a certain denomination. * For example, [10, 20, 30, 40, 50] means: * - 10 banknotes of 50 rubles * - 20 banknotes of 100 rubles * - 30 banknotes of 500 rubles * - 40 banknotes of 1000 rubles * - 50 banknotes of 5000 rubles */ int[] getBillsCounts(); /** * Loads the specified banknotes into the dispensing box. * * @param billsCounts array with the number of banknotes by denominations [50, 100, 500, 1000, 5000]. * For example, [0, 1, 0, 2, 0] means: * - 0 banknotes of 50 rubles * - 1 banknote of 100 rubles * - 0 banknotes of 500 rubles * - 2 banknotes of 1000 rubles * - 0 banknotes of 5000 rubles */ void giveBills(int[] billsCounts); } /** * Class for implementing ATM logic. * You need to write code here */ class MyATM { /** * ATM hardware. */ Hardware hardware; public boolean withdraw(int amount) { int[] counts = hardware.getBillsCounts(); int[] nom = {50, 100, 500, 1000, 5000}; int[] toGive = new int[5]; for (int i = 4; i >= 0; i--) { int needed = amount / nom[i]; int use = Math.min(needed, counts[i]); toGive[i] = use; amount -= use * nom[i]; } if (amount != 0) { return false; } hardware.giveBills(toGive); return true; } }
What problems can arise under high load (tens of millions of requests)? How to scale the solution?.
Why has Spring Boot become so popular compared to Java EE?
Why did you decide to cache the client specifically in Redis?
Implement your own enum type as if before the modern enum in Java 1.5. It should implement the contract of a modern Java enum: • easy to get any enum value • safe comparison of values by reference (==) • each value has a string name matching the value name • each value has an integer `ordinal` identifier containing its declaration order • can get a list of all enum values • can get a value by its `ordinal` • can get a value by its name For example, you can take a list of currencies. It is important that the list is potentially extendable, because the quality of the code will determine how smoothly it will be in the future to add values to the enum. class Currency { // TODO } --- Given the user_orders table |ts|user_id|order_value| Return the sum of the first purchase for each user.
What is missing in the Redis scheme? How to solve the problem of binding order_id to courier_id?
What is the problem with calling REST directly from a Kafka consumer?
How else can routing be implemented without binding to class name?
[Name] asked: Did you work directly in Sovcombank?
What is the difference between the @Bean annotation and @Component?
Why is the Java Stream API designed to be lazy? Pros and cons of this approach.
Can you tell more about the project you worked on? What did you like and what did not?
How to speed up this SQL query on a large table? What index to add and will an index only on status help?
-- There are tables with the structure Employee id (PK) name salary dep_id(FK department.id) Department id (PK) name -- write a query that returns a list of all department names with the maximum salary in each department select d.name, COALESCE(MAX(e.salary), 0) from Department d left join Employee e on e.dep_id = d.id group by d.name