Final- Java Chap 2 Gaddis Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

A Java source code file contains one or more Java…

A

classes

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

Rule: If more than one class is in a source code file…

A

only one of them may be public

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

The public class and the filename of the source code file…

A

must match

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

Each Java class can be separated into…

A

parts

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

to compile vs to run

A

to compile:
javac Simple.java

to run:
java Simple

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

curly braces

A

contain all of the data and methods for a class. They open on the line after the class header

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

after the class header and the opening curly bracket, there is a…

A

method header and an opening curly bracket for the method

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

method headers look like this:

A

public statis void main (String[] args)

{

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

The application begins

A

after the method header

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

Between the curly brackets of the method are…

A

all the actions to be completed during said method

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

Java statement that is executed when the program runs

A

is indented and within the curly brackets of the method.

ex: System.out.println(“Programming rocks!”);

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

Ignored by compilers

A

comments

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

the class header communicates that

A

other classes can use it (public), that it is a java class (class), and the name (Simple)

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

curly braces

A

define the scope of a class or method

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

In this method:
public static void main(String[] args)

args is…

A

a variable name that can be programmer defined

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

The method

A

is the line of code that the java command will run first. It starts the program

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

Every Java application must have a

A

main method

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

When the program runs, the statements within the main method will be

A

executed

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

Semi-colons only end lines that…

A

are java statements. Not comments or java framework like class headers or method headers

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

A .java file may contain many classes but may only have…

A

one public class

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

If a .java file has a public class, the class must have…

A

the same name as the file.

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

//

A

marks the beginning of a single line comment. Anything after the // on the line will be ignored by the compiler

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

( )

A

used in a method header to mark the parameter list

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

{ }

A

encloses a group of statements, such as the contents of a class or a method

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

” “

A

Encloses a string of characters, such as a message that is to be printed on the screen

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

;

A

marks the end of a complete programming statement

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

standard output device

A

the console window that starts a java application

28
Q

standard input device

A

the keyboard

29
Q

Java sends info to the standard output device by using

A

a Java class stored in the standard Java library

30
Q

Java classes in the standard Java library are accessed using the

A

Java Applications Programming Interface (API)

31
Q

The standard Java library is commonly referred to as

A

the Java API

32
Q

System.out.println(“Programming is great fun!”);

is an example of…

A

a programming statement

33
Q

in the programming statement:
System.out.println(“Programming is great fun!”);

System is…

A

a class called upon by the program that contains methods and objects that perform system level tasks

34
Q

In the programming statement:
System.out.println(“Programming is great fun!”);

out is

A

an object, which is a member of the System class and contains the methods print and println

35
Q

print and println methods actually perform the task of…

A

sending characters to the output device

36
Q

The println method automatically…

A

places a newline character at the end of whatever is being printed out

37
Q

Would the following lines be printed on the same or separate lines? Why?

System.out.println(“This is being printed out”);
System.out.println(“on two separate lines.”);

A

Separate lines since the first statement has println which sens a newline command to the screen.

38
Q

The print statement does not

A

put a newline character at the end of the output.

39
Q

System.out.print(“These lines will be”);
System.out.print(“printed on”);
System.out.println(“the same line.”);

A

Because they didnt use println

40
Q

\n

A

newline character. A special character or escape sequence that can be put into the output to start a new line in the print statement.

41
Q

escape sequences

A

allow the programmer to print characters that otherwise would be unprintable

42
Q

\n

A

Escape sequence. newline. Advances the cursor to the next line for subsequent printing

43
Q

\t

A

Escape sequence. Tab. Causes the cursor to skip over to the next tab stop

44
Q

\b

A

Escape sequence. backspace. Causes the cursor to back up (move left) one position.

45
Q

\r

A

Escape sequence. Carriage return. Causes the cursor to go to the beginning of the current line, not the next line.

46
Q

\

A

Escape sequence. Backslash. Causes a backslash to be printed.

47
Q

'

A

Escape sequence, Single quote. Causes a single quote to be printed

48
Q

"

A

Escape sequence. Double quote.

49
Q

Even though the escape sequences have 2 characters, they are treated by the compiler…

A

as a single character.

50
Q

What output would result from this?:
System.out.print(“These are our top sellers:\n”);
System.out.print(“\tComputer games\n\tCoffee\n “);
System.out.println(“\tAspirin”);

A

These are our top sellers:
Computer games
Coffee
Asprin

51
Q

Complex text output can be achieved with

A

escape sequences.

52
Q

the + operator can be used as:

A

a concatenation operator and an addition operator

53
Q

If either side of the + operator is a string, the result will be a…

A

string.

54
Q

string literals

A

inside (“ “) to be printed as part of a programming statement. Must be treated with care.

55
Q

A string literal cannot

A

span lines in a Java source code file.
Example:
System.out.println(“This line is too long and now it has spanned more than one line, which will cause a syntax error to be generated by the compiler. “);

56
Q

What can fix the problem created by the fact that string literals cannot span more than one line?

A

The string concatenation operator.
Example:
System.out.println(“These lines are “ +
“now ok and will not “ +
“cause the error as before.”);

57
Q

Can string concatenation join various data types?

A

Yes.

58
Q

If an addition operation is needed in a print statement

A

it must be put into parenthesis.
Example:
“\n\tSecond = “ + (6 + 4) + “,”

59
Q

There are 3 methods for commenting codes

A

The first is //

60
Q

//

A

block comment. Everything beginning with /* and ending with the first */ will be ignored by the compiler. This comment type cannot be nested.

61
Q

/**…*/

A

Javadoc comment. This is a special version of the previous block comment that allows comments to be documented by the javadoc utility program. Also cannot be nested.

62
Q

Although java has a strict syntax, what characters are ignored by the compiler?

A

whitespace

63
Q

Java whitespace characters (5):

A

space, tab, newline, carriage return, form feed

64
Q

Each block of code should be…

A

indented a few spaces from its surrounding block. 2-4 spaces are sufficient

65
Q

Why should tab characters be avoided?

A

tabs can vary in size between applications and devices.