Learn Java Tutorial for Beginners (Video), Part 16: Method Parameters

How to pass parameters (values and variables) to your methods; a vital programming skill. I also discuss something that usually confuses beginners -- namely, how data flows from one variable to another when you pass the variable to a method. Plus another brief revisit to the subject of references vs. values.

When the video is running, click the maximize button in the lower-right-hand corner to make it full screen.



Code for this tutorial:

class Robot {
    public void speak(String text) {
        System.out.println(text);
    }
    
    public void jump(int height) {
        System.out.println("Jumping: " + height);
    }
    
    public void move(String direction, double distance) {
        System.out.println("Moving " + distance + " in direction " + direction);
    }
}

public class App {

    public static void main(String[] args) {
        Robot sam = new Robot();
        
        sam.speak("Hi I'm Sam");
        sam.jump(7);
        
        sam.move("West",  12.2);
        
        String greeting = "Hello there";
        sam.speak(greeting);
        
        int value = 14;
        sam.jump(value);

    }

}
 
 
Hi I'm Sam.
Jumping: 7
Moving 12.2 metres in direction West
Hello there.
Jumping: 14