Methods in Java a written with a name in cameCase, preceeded by a return-type (or void
for method that returns nothing), followed by a typed parameter list (which can be empty) and a body which consists of zero or more statements enclosed in brackets.
static void doSomething() {
System.out.println("Do something...");
}
Variables in Java are scoped to the method they where declared. See also Local Variable Scope.
Parameter Passing
In Java, parameters are passed by value. In other words, they receives a copy of the original value, and what happens in the method does not affect the original object. See also Pass by Reference vs Pass by Value.
int myVal = 5;
static void doubleVal(int val) {
val *= 2;
System.out.println(val); // 10
}
System.out.println(myVal); // 5