Kapitel 2 Flashcards

1
Q

1

A
// A crazy mixed up program public class Columbus 
{ 
public static void main(String[] args) { 
System.out.println("In 1492 Columbus sailed the ocean blue.");
 } 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

2

A

Columbus.java

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

3

A
public class Hello 
{ 
public static void main(String[] args) { 
System.out.println("Hello World"); 
} 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

4

A
// Example // August 22, 2013 
public class MyName { 
public static void main(String[] args) { System.out.println("Herbert Dorfmann"); 
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

5

A

C

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

6

A

A

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

7

A
// Its a mad, mad program public class Success 
{ 
public static void main(String[] args) 
{ System.out.print("Success\n"); System.out.print("Success "); System.out.print("Success\n"); System.out.println("\nSuccess"); 
} }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

8

A

The works of Wolfgang include the following

The Turkish March and Symphony No. 40 in G minor.

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

9

A
// August 22, 2013
public class PersonalInfo
{
public static void main(String[] args)
{
System.out.println("Herbert Dorfmann");
System.out.println("123 Elm Street");
System.out.println("My Town, NC 21111");
System.out.println("919-555-1234");
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

10

A
Variables:
little
big
Literals:
2
2000
"The little number is "
"The big number is "
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

11

A

The value is number

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

12

A

99bottles is illegal because it starts with a number.

r&d is illegal because the & character is illegal.

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

13

A

They are not the same because one begins with an uppercase S while the other
begins with a lowercase s. Variable names are case-sensitive.

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

14

A

a) short
b) int
c) 22.1 because it is stored as a double .

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

15

A

6.31E17

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

16

A

Append the F suffix to the numeric literal, such as:

number = 7.4F;

17
Q

17

A

true and false

18
Q

18

A

a) char letter;
b) letter = ‘A’;
c) System.out.println(letter);

19
Q

19

A

The code for ‘C’ is 67.
The code for ‘F’ is 70.
The code for ‘W’ is 87.

20
Q

20

A

‘B’ is a character literal.

21
Q

21

A

You cannot assign a string literal to a char variable. The statement should be:
char letter = ‘Z’;

22
Q

22

A
Expression Value
6 + 3 * 5 21
12 / 2 - 4 2
9 + 14 * 2 - 6 31
5 + 19 % 3 - 1 5
(6 + 2) * 3 24
14 / (11 - 4) 2
9 + 12 * (8 - 3) 69
23
Q

23

A

Integer division. The value 23.0 will be stored in portion .

24
Q

24

A

a) x += 6;
b) amount -= 4;
c) y *= 4;
d) total /= 27;
e) x %= 7;

25
Q

25

A

a) No
b) Because the result of basePay + bonus results in an int value, which cannot be
stored in the short variable totalPay . You can fix the problem by declaring
totalPay as an int , or casting the result of the expression to a short .

26
Q

26

A

a = (float)b;

27
Q

27

A

String city = “San Francisco”;

28
Q

28

A

stringLength = city.length();

29
Q

29

A

oneChar = city.charAt(0);

30
Q

30

A

upperCity = city.toUpperCase();

31
Q

31

A

lowerCity = city.toLowerCase();

32
Q

32

A

To write a single line comment you begin the comment with // . To write a multi-line
comment you begin the comment with /* and end it with */ . To write a documentation
comment you begin the comment with /** and end it with */ .

33
Q

33

A

Documentation comments can be read and processed by a program named
javadoc . The javadoc program can read Java source code files and generate
attractively formatted HTML documentation files. If the source code files contain
any documentation comments, the information in the comments becomes part of
the HTML documentation.

34
Q

34

A

A message dialog box is used to display a message to the user. An input dialog box
is used to gather keyboard input from the user.

35
Q

35

A

a) JOptionPane.showMessageDialog(null, “Greetings Earthling.”);
b) str = JOptionPane.showInputDialog(“Enter a number.”);

36
Q

36

A

String str;
int age;
str = JOptionPane.showInputDialog(“Enter your age.”);
age = Integer.parseInt(str);

37
Q

37

A

import javax.swing.JOptionPane;