Chapter 3/ Parameters and Objects Flashcards

1
Q

Parameter

A

In Java, parameters sent to methods are passed-by-value. The “type” of data that a method can receive is referred to as a “parameter”.

When passing a parameter must have type declared.

ex.
public static void countSum(int number){
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Formal Parameter

A

A variable that appears inside parentheses in the header of a method that os used to generalize the method’s behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Actual Parameter

A

A specific value or expression that appears inside parentheses in a method call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Character Literals

A

Character literals are enclosed in single quotation mart.
Ex.
‘>’ ‘=’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Parameters vs. Class Constants

A

Parameters are more flexible. Because you specify the value to be used each time you call the method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Overloading of Methods

A

When there are more than one method with the same name, as long as they have different parameters.

The primarily requirement for overloading is that the methods must have different method signatures when defining them.

drawBox(3, 6);
drawBox();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Method Signature

A

The name of a statement along with its number and type of parameters.

Ex.
one method with the same name has zero parameters
and another one has two parameters.

The situations gets complicated when overloading involves the same number of parameters.

For example, println method is a series of overloaded methods. We can call this method by passing different parameters: String, int, double, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Interactive Programs

A

Programs that wait for the user to type a response.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Console Input

A

Response typed by the user an interactive program pauses for input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

System.out -> Standart Output

A

When refer to System.out you accessing an object in the System class known as a standard output stream.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

System.in

A

corresponding object for input.

The easier way to read console inputs with using Scanner objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Constructor (Construct)

A

the most of the objects are constructed by calling a special method Constructor.

Constructor - a method that creates and initializes an object.

Java constructor are called using a keyword ‘new’ followed by the object’s type and any necessary parameters.

Ex. construct a specific scanner object
Scanner console = new Scanner(System.in);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Scanner

A
Import java.util.*;  // a package containing Scanner
public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    System.out.print("Please enter a number: ");
    int num = console.nextInt();
    System.out.print("Please enter a number: ");
    double num = console.nextDouble();
    System.out.println();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Scanner Methods

A

next() -> reads and returns the next tokens a String

nextDouble() -> reads and returns a double value

nextInt() -> reads and returns an int value

nextLine() -> reads and returns the next line of input as a String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Token

A

a single element of input (one word, one number)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Whitespace

A

Spaces, tab characters and new line characters

A Scanner object looks at what the user typed and uses the whitespaces on the input line to break it up into individual tokens.

17
Q

Tokenizing

A

a process when a Scanner controlled how it must turn things into tokens.