Moment 5 Flashcards
What dose the technique “divide and conquer” entail?
Experience has shown that the best way to develop and maintain a large program is to construct it from small, simple pieces. This technique is called divide and conquer
Methods are declared within?
classes
Classes are typically grouped into packages so they can be?
imported and reused.
Methods allow you to modularize a program by?
separating its tasks into self-contained units. The statements in a method are written only once and hidden from other methods.
Using existing methods as building blocks to create new programs is a form of?
software reusability (p. 206) that allows you to avoid repeating code within a program.
A method call specifies the?
name of the method to call and provides the arguments that the called method requires to perform its task. When the method call completes, the method returns either a result, or simply control, to its caller.
A class may contain static methods to perform?
common tasks that do not require an object of the class. Any data a static method might require to perform its tasks can be sent to the method as arguments in a method call.
A static method is called by?
specifying the name of the class in which the method is declared followed by a dot (.) and the method name, as in:
ClassName.methodName(arguments)
Class Math provides static methods for performing?
common mathematical calculations.
The constant Math.PI (3.141592653589793; p. 208) is the?
ratio of a circle’s circumference to its diameter.
The constant Math.E (2.718281828459045; p. 208) is the?
base value for natural logarithms (calculated with static Math method log).
Math.PI and Math.E are declared with the?
modifiers public, final and static. Making them public allows you to use these fields in your own classes.
A field declared with keyword final (p. 209) is?
constant—its value cannot be changed after it’s initialized.
Both PI and E are declared final because?
their values never change. Making these fields static allows them to be accessed via the class name Math and a dot (.) separator, just like class Math’s methods.
When you execute the Java Virtual Machine (JVM) with the java command, the JVM loads the class you specify and?
uses that class name to invoke method main. You can specify additional command-line arguments (p. 209) that the JVM will pass to your application.
What method will be called by the java command?
You can place a main method in every class you declare—only the main method in the class you use to execute the application will be called by the java command.
Class, method and variable names are?
identifiers.
By convention all use camel case names. Class names begin with an uppercase letter, and method and variable names begin with a lowercase letter.
Parameters are declared in?
a comma-separated parameter list (p. 211), which is located inside the parentheses that follow the method name in the method declaration. Multiple parameters are separated by commas. Each parameter must specify a type followed by a variable name.
Every method’s body is delimited by?
left and right braces ({ and }).
Each method’s body contains one or more statements that?
perform the method’s task(s).
The method’s return type specifies the?
type of data returned to a method’s caller.
Keyword void indicates that?
a method will perform a task but will not return any information.
Empty parentheses following a method name indicate that?
the method does not have parameters.
When a method that specifies a return type (p. 211) other than void is called and completes its task, the method must?
return a result to its calling method.
The return statement (p. 212) passes a?
value from a called method back to its caller.
When a method is called, the program makes a copy of?
the method’s argument values and assigns them to the method’s corresponding parameters.
When program control returns to the point in the program where the method was called, the method’s parameters are?
removed from memory.
Strings can be concatenated (p. 212) using?
operator +, which creates a new String containing the characters of the left operand followed by those of the right operand.
Every primitive value and object in Java can be represented as a?
String. When an object is concatenated with a String, the object is converted to a String, then the two Strings are concatenated.