Learn how to read a method, call it correctly, and use Java's built-in tools with confidence.
Click the choices and see how one order becomes a method call.
The real-world pattern comes first: choose, customize, receive.
In Java, the pattern is still tool, inputs, and result.
Method Call
orderDrink names the tool.
The three strings are the input values.
The variable drink stores the returned result.
A method is a named tool that does a job or gives a result.
Some methods perform a job when you call them.
Other methods return a value you can use.
Use a method by calling its name.
Focus on what it does before how it works.
Action Example
showMessage();
Value Example
applyTax(12);
Stored Result
int books = countBooks(3);
When something is unfamiliar, its instructions tell us what it does and how to use it.
Read each part of a method before using it.
Use the same parts to read several method signatures.
Identify the method name, parameter count and types, and return type.
Identify the method name, parameter count and types, and return type.
Identify the method name, parameter count and types, and return type.
Identify the method name, parameter count and types, and return type.
Identify the method name, parameter count and types, and return type.
Identify the method name, parameter count and types, and return type.
Identify the method name, parameter count and types, and return type.
Javadoc promises what must be true before and after a call.
Precondition
The before promise: what the caller must supply.
Postcondition
The after promise: what the method guarantees to return.
Javadoc Tags
@param and @return record the contract.
Use the method name and place argument values inside the parentheses.
Method Signature
Method Call
Method Name
Call findMax.
Arguments
Pass 8 and 13 to the method.
Parentheses
Place the arguments inside ( ).
A return type determines where a method call can be used.
void Method
A void method performs an action but does not return a value.
Call it as a statement; do not store it or place it inside an expression.
Non-void Method
A non-void method returns a value with the type named in its header.
Store the value in a compatible variable or use it in an expression.
Check the number, order, and compatible types before making a call.
Number
Supply the same number of arguments as parameters.
Order
Match each argument to the parameter in the same position.
Type
Each argument must have a compatible type.
Does the call match the parameter list?
Does the call match the parameter list?
Does the call match the parameter list?
Does the call match the parameter list?
Does the call match the parameter list?
Does the call match the parameter list?
Does the call match the parameter list?
One familiar name can lead to different actions based on the inputs.
The same method name can support different parameter lists.
Same Name
Overloaded methods must share the same method name.
Different Parameters
The ordered parameter type lists must differ; parameter names do not matter.
Return Type Is Ignored
Changing only the return type does not create an overload.
Do these two method signatures create valid overloaded methods?
Do these two method signatures create valid overloaded methods?
Do these two method signatures create valid overloaded methods?
Do these two method signatures create valid overloaded methods?
Do these two method signatures create valid overloaded methods?
Do these two method signatures create valid overloaded methods?
Do not guess. Read the tools first.
A library is a collection of ready-made classes.
An API explains how to use those classes correctly.
Read the available documentation before you guess a method call.
When a method is unfamiliar, check the Java Quick Reference â before guessing how to call it.
Packages organize classes, and classes group data with behavior.
Package
A package groups related classes inside a library.
Class
A class defines a reference type that can be used to create objects.
Attributes
Attributes are the data associated with a class and stored in variables.
Behaviors
Behaviors describe what objects can do and are defined by methods.
Existing classes and libraries let us create useful objects without building every tool from the beginning.
Java already gives you many ready-made tools.
Math for calculations. abs()pow()sqrt()String methods for text. length()substring()equals()Scanner for keyboard input. nextInt()nextDouble()nextLine()These methods belong to the class, so we call them with the class name and a dot.
A class method belongs to the class, not one object.
A class method header contains the keyword static.
Call it with the class name, a dot, and the method name.
Java gives you ready-made methods for common calculations
Returns the absolute value.
Math.abs(-5) -> 5
Returns the absolute value.
Math.abs(-2.75) -> 2.75
Raises a number to a power.
Math.pow(2, 3) -> 8.0
Returns the square root.
Math.sqrt(25) -> 5.0
Returns a value where 0.0 ⤠value < 1.0.
Math.random() -> a new value each run
Other methods exist too.
max() min() ceil() floor() round()
Each Math call gives back a value, and that value has a type.
What value is stored in the variable?
What value is stored in the variable?
What value is stored in the variable?
What value is stored in the variable?
What value is stored in the variable?
What value is stored in the variable?
What value is stored in the variable?
What value is stored in the variable?
Generate a random number from 1 to 6.
Java starts with a random decimal between 0.0 and 1.0.
Which integers could the variable store?
Which integers could the variable store?
Which integers could the variable store?
Which integers could the variable store?
Which integers could the variable store?
Which integers could the variable store?
Complete it on time and submit it before the deadline.
Check what comes next and arrive ready.
Key takeaways from this lesson.
Methods
A method is a named tool that performs a task or returns a result.
Signatures
Read the return type, method name, and ordered parameters.
Arguments
Arguments must match the parameter list in number, order, and type.
Class Methods
Call Math methods with the class name, a dot, and the method name.