Java - Chapter 5
Two important points to remember about @param:
1) All @param tags must appear after the general description of the method, 2) the description can span several lines. It ends at the end of the documentation comment or at the beginning of another tag.
General format of @param
@param parameterName Description
lifetime of a local variable
A function's local variables exist only while the function is executing; any value stored in a local variable is lost between calls to the method in which the variable is declared.
void method
A method that does not return a value; simply performs a task and then terminates.
divide and conquer
A program design strategy in which tasks are broken down into subtasks, which are broken down into sub-subtasks, and so on, until each piece is small enough to code comfortably. These pieces work together to accomplish the total job.
method header
Appears at the beginning of a method definition, lists several important things about the method, including the method's name.
There is a need for a method that tests an argument and returns a true or false value indicating whether or not a condition exist. This will return a ____________ value.
Boolean
True or False - You can use the method's return value anywhere you can use a regular value of a different data type.
False - It needs to be the same data type.
@param
Javadoc block tag specifying a variable's name and its description.
@return
Javadoc block tag to describe the return value of a method. @return Description
Layered method calls
Method A can call Method B, which can then call Method C.
functional decomposition
The process of breaking a problem down into smaller pieces.
Return type
The type of data a method gives back.
True of False: A variable is visible only to statements inside the variable's scope.
True
True or False: A value-returning method can also return a reference to a non-primitive type such as a String object.
True
True or False: Each parameter variable in a parameter list must have a data type listed before its name.
True
method body
a collection of statements that are performed when the method is executed
method
a collection of statements that performs a specific task; commonly used to break a problem into small, manageable pieces.
Any time you use the = operator to assign a string literal to a String reference variable:
a new String object is created in memory
When an object, such as String, is passed as an argument, it is:
a reference to the object that is passed
passed by value
all arguments of the primitive data types; only a copy of an argument's value is passed into a parameter variable; a method's parameters variables are separate and distinct from the arguments that are listed inside the parentheses of a method call.
Values that are sent into a method are called ____________.
arguments
return statement
causes the method to end execution and it returns a value to the statement that called the method. return Expression;
local variable
declared inside a method and is not accessible to statements outside of the method
How to call a method named displayMessage?
displayMessage(); it is the name of the method followed by a set of parentheses.
Documentation comments can be read and processed by a program named __________, which produces attractive HTML documentation.
javadoc
Methods can also be called in ________ fashion.
layered
Every complete Java program must have a __________ method.
main
Reference variable holds the ________________ of an object.
memory address
Two parts of a definition
method header and method body
Method name
name that is descriptive of what the method does
Parameter list
passing more than one argument to a method
value-returning method
performs a task, but also sends a value back to the code that called it
You must have a __________ statement in a value-returning method.
return
How to write a method that accepts the two arguments num1 and num2 as integers?
showSum(int num1, int num2)
parameter variable
sometimes referred to as a parameter; is a special variable that holds a value being passed into a method.
When writing a value-returning method, you must:
specify the data type of the return value in the method header
When you pass an argument to a method, be sure that:
the argument's data type is compatible with the parameter variable's data type.
If a method calls another method that has a throws clause in its header, then:
the calling method should have the same throws clause.
method modifiers
the key words public and static. Public means that the method is publicly available to the code outside of the class. Static means that the method belongs to the class, not a specific object.
Parentheses
the method name is always followed by a set of parentheses. If the method is capable of receiving arguments, a list of one or more variable declarations will appear inside the parentheses.
In Java, String objects are immutable, which means:
they cannot be changed
Java will automatically perform a ________________ if the argument's data type is ranked ________ than the parameter's variable's data type.
widening conversion; lower
When passing a variable as an argument, do not:
write the data type of the argument variable in the method call
code reuse
writing the code to perform a task once and then reusing it each time you need to perform the task