Sobes.tech

In which design pattern is the Comparator class used for comparing objects?

Junior — Middle
324

public class MoneyTransferService { /** * @param fromAccountId unique identifier of the user transferring funds * @param toAccountId unique identifier of the user receiving funds * @param amount transfer amount. Positive number */ @Transactional public void transferMoney(Long fromAccountId, Long toAccountId, BigDecimal amount) { if (amount.compareTo(BigDecimal.ZERO) <= 0) { throw new RuntimeException("Amount must be +"); } if (fromAccountId.equals(toAccountId)) { throw new RuntimeException("Account can't be the same"); } Long firstId = Math.min(fromAccountId, toAccountId); Long secondId = Math.max(fromAccountId, toAccountId); Account first = accountRepository.findByIdForUpdate(firstId) .orElseThrow(() -> new RuntimeException("Account not found")); Account second = accountRepository.findByIdForUpdate(secondId) .orElseThrow(() -> new RuntimeException("Account not found")); Account from = fromAccountId.equals(firstId) ? first : second; Account to = fromAccountId.equals(firstId) ? second : first; if (from.getBalance().compareTo(amount) < 0) { throw new RuntimeException("Balance is less 0"); } from.setBalance(from.getBalance().subtract(amount)); to.setBalance(from.getBalance().add(amount)); accountRepository.save(to); accountRepository.save(from); } } @Entity @Data public class Account { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private BigDecimal balance; }

324

Describe the process of handling JSP pages, from server request to user response.

Middle
324

How can you temporarily disable the execution of tests during a Maven project build?

Junior — Middle
324

Which HTTP method is not idempotent?

Junior
324

Explain how memory allocation and management occur in the JVM in the event of an OutOfMemoryError.

Junior — Middle
324

What operations exist in streams and what types of operations are there?

Middle
324

How are beans initialized in Spring?

Middle
323

What methods can be used to protect your application from unwanted mass activity and spam attacks?

Junior — Middle
323

What is meant by the persistent state of an entity in Hibernate, and how does it affect its management in ORM?

Junior — Middle
323

What annotation is used in Spring to define environment profile handling?

Junior — Middle
323

How to ensure safe access to a singleton class in a multithreaded environment?

Junior — Middle
323

How to implement counting processed records when using multithreading?

Junior — Middle
323

What is the difference between @RequestMapping and @PutMapping annotations in Spring?

Junior
323

Can you explain the principle of data replication in a database?

Junior — Middle
323

Should only one connection be established or can there be multiple?

Junior — Middle
323

Why is the clone() method declared in the Object class and not in the Cloneable interface?

Middle+
323

Can you explain the concept of lock-free algorithms and how they differ from other synchronization methods?

Junior — Middle
323

How can application performance analysis be conducted to identify bottlenecks?

Junior — Middle
323
/739