Java Fundamentals Flashcards

1
Q

What is bytecode and why is it important to Java’s use for Internet programming?

A

Bytecode is a highly optimized set of instructions that is executed by the Java Virtual Machine. Bytecode helps Java achieve both portability and security.

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

What are the three main principles of object-oriented programming?

A

Encapsulation, polymorphism, and inheritance.

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

Where do Java programs begin execution?

A

Java programs begin execution at main( ).

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

What is a variable?

A

A variable is a named memory location. The contents of a variable can be changed during the execution of a program.

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

Which of the following variable names is invalid?

A. count
B. $count
C. count27
D. 67count

A

The invalid variable is D. Variable names cannot begin with a digit.

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

How do you create a single-line comment? How do you create a multiline comment?

A

A single-line comment begins with // and ends at the end of the line. A multiline comment begins with /* and ends with */.

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

Show the general form of the if statement. Show the general form of the for loop.

A

The general form of the if:
if(condition) statement;

The general form of the for:
for(initialization; condition; iteration) statement;

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

How do you create a block of code?

A

A block of code is started with a { and ended with a }.

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

The moon’s gravity is about 17 percent that of earth’s. Write a program that computes your effective weight on the moon.

A

/*
Compute your weight on the moon.

Call this file Moon.java.
*/
class Moon {
public static void main(String[] args) {
double earthweight; // weight on earth
double moonweight; // weight on moon
earthweight = 165;

moonweight = earthweight * 0.17;

System.out.println(earthweight +
                   " earth-pounds is equivalent to " +
                   moonweight + " moon-pounds.");

}
}

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

Adapt Try This 1-2 so that it prints a conversion table of inches to meters. Display 12 feet of conversions, inch by inch. Output a blank line every 12 inches. (One meter equals approximately 39.37 inches.)

A

/*
This program displays a conversion
table of inches to meters.

Call this program InchToMeterTable.java.
*/
class InchToMeterTable {
public static void main(String[] args) {
double inches, meters;
int counter;

counter = 0;
for(inches = 1; inches <= 144; inches++) {
  meters = inches / 39.37; // convert to meters
  System.out.println(inches + " inches is " +
                     meters + " meters.");

  counter++; 
  // every 12th line, print a blank line 
  if(counter == 12) {
    System.out.println();
    counter = 0; // reset the line counter
  }
}   } }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If you make a typing mistake when entering your program, what sort of error will result?

A

A syntax error.

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

Does it matter where on a line you put a statement?

A

No, Java is a free-form language.

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