A method is a named mini-program: values come in through parameters, a result comes out through return.
1 One job per method
A method packages a named task — greet(), add(), printLine() — and you can call it anywhere, any number of times.
2 Parameters feed it
Values passed in (arguments) let one method work on many different inputs.
3 Return sends back
return hands a result to the caller; void methods just do their job and end.
4 Modular programs
Big problems split into small methods are easier to write, test and fix.
One job per method
One job per method1A method packages a named task — greet(), add(), printLine() — and you can call it anywhere, any number of times. Parameters feed it2Values passed in (arguments) let one method work on many different inputs. Return sends back3return hands a result to the caller; void methods just do their job and end. Modular programs4Big problems split into small methods are easier to write, test and fix. 4 building blocks make up One job per method
Press Run to follow one call from the moment main hits it to the moment the result lands back.
Two tabs: greet() returns a value main prints, and buyTicket() is a void method that updates a static field.
JVMThe JVM loads Greeter — main and the greet helper live in one class.
Memory
no variables yet — press play
Console
output appears as the program runs…
One method, two calls — the second call feeds on the result of the first.
Your predicted output — one line per console line
Hint: twice(3) returns 6. Then twice(a) doubles that again before the + 1.
Click a term, then click its meaning to lock the pair.
5 conceptsTap a card to expand ?methoddrops into place
?parameterdrops into place
?argumentdrops into place
?returndrops into place
?voiddrops into place
01Methods give a name to a task so main stays short and readable.
02Parameters carry values in; return carries the result out.
03void methods do their work without returning a value.
04Every call pushes a stack frame; every return pops it.
05Static methods belong to the class — no object needed to call them.