🧩 Methods
13 Java concepts, each explained step by step with real code, a common trap and practice questions.
- Defining & calling methodsModifiers, return type, name, parameters, body.
- Return values & voidreturn ends the method; every path must return in non-void methods.
- Parameters vs argumentsFormal parameters receive copies of argument values.
- Java is always pass-by-valuePrimitives copy the value; references copy the reference (object can be mutated, variable cannot be re-pointed).
- Method overloadingSame name, different parameter lists; resolution order (exact, widening, boxing, varargs).
- VarargsType... args, must be last, received as an array.
- Static vs instance methodsstatic methods belong to the class and cannot use this.
- Local variables & scopeLocals live on the stack frame and die when the method returns.
- The call stackEach call pushes a frame; returning pops it.
- RecursionBase case + recursive case; tracing recursive calls.
- StackOverflowErrorMissing base case or too-deep recursion exhausts the stack.
- Method signatureName + parameter types; return type is not part of it.
- Pure functions & side effectsWhy methods that don't mutate state are easier to reason about.