home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
lect01b
a first program
[go over course-info sheet, for 30min.]
Let's reflect:
- Programs take an input value, and compute an answer (which it
returns).
- Java programs are written inside a class.
-
When writing a function like pizzaArea, you must tell Java
the type of the parameter (input),
as well as the Java the type which the function returns.
This is specified by:
typereturn namefunction( typeparam nameparam )
|
This is also referred to as the function's signature.
I may also call this the contract, as it forms a deal:
the function is guaranteed to be given a parameter of the correct type,
and it has pledged to return a value of the specified type.
-
Java uses the specific word return to emphasize
that the function is returning a value.
-
To run a program (“call a function”, “compute”):
-
Right-click on the class (tan), and compile it.
-
Right-click on the class (tan), and create a new instance (red).
-
Right-click on the instance (red), and select the function you want to call.
-
Enter the arguments.
-
Check the result. (Is it what you expected?)
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs