1. How does the when expression differ from switch in Java?
The when expression is Kotlin's replacement for switch statements but is much more powerful, allowing any type of condition including ranges, type checks, and arbitrary expressions, and it returns a value making it a true expression. Unlike Java's switch which falls through cases by default requiring break statements, when automatically breaks after each branch preventing common bugs. You can use when with or without an argument, match multiple values with commas, use in for range checks, use is for type checks, and even use arbitrary boolean expressions. When must be exhaustive if used as an expression, meaning it must cover all possible cases or include an else branch.