What Is a Code Review and Why Teams Do It
Fast recall
Quick revision
Core answer
Interview-ready guide
Interview answer
Code review is an examination of a proposed change by another developer before or around integration into a shared codebase. The reviewer checks whether the change meets its requirement, handles important edge cases, protects data, has suitable tests, and remains understandable. A second perspective can find assumptions the author missed, while the discussion spreads knowledge about that part of the system. Review is one control rather than a guarantee: automated tests, analysis, deployment safeguards, and monitoring cover other risks. Teams choose a review method and depth based on the change, from an asynchronous pull request to pairing or an emergency review path.
What Is a Code Review and Why Teams Do It
Direct Answer
A code review is when a peer examines your code changes before they merge into the shared codebase. Teams do it to catch bugs early, enforce consistent standards, and spread knowledge so no single person is the only one who understands a system.
Code Example
// Pull Request: Add order validation before payment processing
// Context: Customers were able to submit orders with negative quantities
@Service
public class OrderService {
private final PaymentGateway paymentGateway;
private final OrderRepository orderRepository;
public OrderService(PaymentGateway paymentGateway, OrderRepository orderRepository) {
this.paymentGateway = paymentGateway;
this.orderRepository = orderRepository;
}
public Order processOrder(OrderRequest request) {
// Validation added to catch business rule violations early
if (request.quantity() <= 0) {
throw new InvalidOrderException("Quantity must be positive");
}
if (request.totalAmount().compareTo(BigDecimal.ZERO) <= 0) {
throw new InvalidOrderException("Order total must be positive");
}
var order = new Order(request.productId(), request.quantity());
var payment = paymentGateway.charge(request.totalAmount());
order.setPaymentId(payment.id());
return orderRepository.save(order);
}
}
A clear PR description plus a small, focused diff like this is exactly what makes a change quick to review.
Common Mistakes & Pitfalls
- Skipping review for small changes: Freshers think one-line fixes don't need review, but small changes often have big impacts. A logging level change can flood production logs and fill disk space. A single character typo in a SQL query can corrupt data.
- Treating review as personal criticism: When a reviewer points out issues, freshers feel attacked and get defensive. Code review targets the code, not you. A comment saying your method is hard to understand isn't saying you're a bad developer—it's helping you write clearer code.
- Waiting too long to submit: Freshers work on a feature for two weeks, then submit a massive 2000-line PR. By then, requirements might have changed, merge conflicts are guaranteed, and reviewers can't give thorough feedback on that volume. Submit work incrementally.
Check your understanding
Answer these without looking back at the article.
- What is a pull request and how does it relate to code review?
- How many reviewers should a pull request have?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.