Final- Java Chap 2 Gaddis 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
" "
Encloses a string of characters, such as a message that is to be printed on the screen
26
;
marks the end of a complete programming statement
27
standard output device
the console window that starts a java application
28
standard input device
the keyboard
29
Java sends info to the standard output device by using
a Java class stored in the standard Java library
30
Java classes in the standard Java library are accessed using the
Java Applications Programming Interface (API)
31
The standard Java library is commonly referred to as
the Java API
32
System.out.println("Programming is great fun!"); is an example of...
a programming statement
33
in the programming statement: System.out.println("Programming is great fun!"); System is...
a class called upon by the program that contains methods and objects that perform system level tasks
34
In the programming statement: System.out.println("Programming is great fun!"); out is
an object, which is a member of the System class and contains the methods print and println
35
print and println methods actually perform the task of...
sending characters to the output device
36
The println method automatically...
places a newline character at the end of whatever is being printed out
37
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.");
Separate lines since the first statement has println which sens a newline command to the screen.
38
The print statement does not
put a newline character at the end of the output.
39
System.out.print("These lines will be"); System.out.print("printed on"); System.out.println("the same line.");
Because they didnt use println
40
\n
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
escape sequences
allow the programmer to print characters that otherwise would be unprintable
42
\n
Escape sequence. newline. Advances the cursor to the next line for subsequent printing
43
\t
Escape sequence. Tab. Causes the cursor to skip over to the next tab stop
44
\b
Escape sequence. backspace. Causes the cursor to back up (move left) one position.
45
\r
Escape sequence. Carriage return. Causes the cursor to go to the beginning of the current line, not the next line.
46
\\
Escape sequence. Backslash. Causes a backslash to be printed.
47
\'
Escape sequence, Single quote. Causes a single quote to be printed
48
\"
Escape sequence. Double quote.
49
Even though the escape sequences have 2 characters, they are treated by the compiler...
as a single character.
50
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");
These are our top sellers: Computer games Coffee Asprin
51
Complex text output can be achieved with
escape sequences.
52
the + operator can be used as:
a concatenation operator and an addition operator
53
If either side of the + operator is a string, the result will be a...
string.
54
string literals
inside (" ") to be printed as part of a programming statement. Must be treated with care.
55
A string literal cannot
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
What can fix the problem created by the fact that string literals cannot span more than one line?
The string concatenation operator. Example: System.out.println("These lines are " + "now ok and will not " + "cause the error as before.");
57
Can string concatenation join various data types?
Yes.
58
If an addition operation is needed in a print statement
it must be put into parenthesis. Example: "\n\tSecond = " + (6 + 4) + ","
59
There are 3 methods for commenting codes
The first is //
60
/*...*/
block comment. Everything beginning with /* and ending with the first */ will be ignored by the compiler. This comment type cannot be nested.
61
/**...*/
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
Although java has a strict syntax, what characters are ignored by the compiler?
whitespace
63
Java whitespace characters (5):
space, tab, newline, carriage return, form feed
64
Each block of code should be...
indented a few spaces from its surrounding block. 2-4 spaces are sufficient
65
Why should tab characters be avoided?
tabs can vary in size between applications and devices.