Defining a method does nothing on its own. The code inside only runs when you call the method by writing its name followed by parentheses and any required arguments.
public static void main(String[] args) {
int result = doubleValue(5);
System.out.println(result);
greet("Alice");
}
When Java hits doubleValue(5), it jumps to the doubleValue method, runs the code inside with x set to , and then comes back with the return value. The returned gets stored in result.
For void methods like greet, you call them as standalone statements. There is no return value to capture in a variable.