Writing Methods

Ethan Taylor
5 min read
Study Guide Overview
This study guide covers pass-by-value for primitive and reference variables in Java. It focuses on writing methods in Java classes, including examples for an Assignment and Student class. The guide demonstrates method structure with Javadoc comments, new instance variables, and explains method headers (access modifiers, return types, method names, and parameters).
Now, it’s time to write most of the rest of our methods. But first, a quick reminder about pass-by-value from Unit 2. When we put a primitive variable in as a parameter, we are giving the method a copy of that value so if you change the value of that variable, it does not get carried over to outside that method.
Meanwhile, if you put a reference variable or object as a parameter, it passes a copy of the reference to the method. Changing the value of the variable has the same effect as a primitive variable, but changing information about the variable (such as using a getter method) will carry over outside the method as well. Normally we do not want to modify mutable objects that are passed in as parameters.
#Writing Methods
Now, we will write some of the methods for our two classes (others will require information from future topics). Take note of the Javadoc comments and also new instance variables that we have added in order for these methods to work. Any changes we have made to the class will be bolded as in previous topics.
#Java Example
/** Represents an...

How are we doing?
Give us your feedback and let us know how we can improve