Stage 1 · Lesson 5 of 9
Methods, parameters and scope
A is a named block of code with a return type and typed parameters, such as static int add(int a, int b). void means it returns nothing. The compiler insists that every path through a non-void method returns a value.
Java always uses , meaning a method gets a copy. For a primitive, that is a copy of the number. For an object, it is a copy of the reference (the pointer to the object).
So a method can change an you pass in, but it cannot make your variable point to a new one. Variables live only in the block where they are declared, which is their . Methods with the same name but different parameters are called .
Keep methods short and make them return values, because that is what makes them testable later.
A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CourseFreeJava Programming MOOC
University of Helsinki · Beginner
Free Helsinki course with hundreds of auto-tested exercises; parts 1 to 8 cover this stage
- GuideFreeDev.java: Learn Java
Oracle · Beginner
Official tutorials from the Java team: read the language basics path next to the MOOC