1: Quizzes Flashcards

1
Q

What is the correct method signature for the ‘main’ method used to allow a Java class to serve as a stand-along program?

A

public static void main(String[] args)

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

When you compile a java program, what is produced?

A

Object code, which is also called bytecode. (.class file)

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

When you compile a java program, what kind of file is produced?

A

A .class file.

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

All java programming language statements must end with what?

A

A semicolon ;

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

You have just written a program that compiles and runs without showing any error messages. However, it does not produce the correct results. What kind of error do you have?

A

A logic error.

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

What is the mechanism used in the second line of code below that allows a programmer to force a potentially unsafe conversion between data types?

double size = 4.67;
int s = (int)size;

A

A cast

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

Name 10 Java keywords

A

public, class, static, void, boolean, char, double, else, final, float, for, if, import, int, long, new, package, private, return, short, throw, throws, while

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

What type of characters are used to define the beginning and end of a Java block, such as a class or method definition?

A

Curly braces { }

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

Name three important characteristics of a class name.

A
  1. For good style, it should be capitalized.
  2. It must match the name of the file where it is stored.
  3. It must be one word (no spaces).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The process of breaking a large programming task down into a series of smaller ones is called…

A

Procedural decomposition.

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

The process of breaking a large programming task down into a series of smaller ones is called…

A

Procedural decomposition.

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

What is the correct syntax for a method header with parameters?

A

public static int example(int x, int y) {

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

What is the term when you have 2 methods in a class with the same name, but different parameter lists?

A

Method overloading

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

What is the keyword used to indicate that a method returns no value?

A

void

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

What is the name of the package that contains Scanner?

A

java.util

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

When you want to call a method on an object, in other words - send the object a message - what is the proper syntax?

A

objectName.methodName()

17
Q

Name the different data types that represent integer values (from smallest to largest).

A

byte, short, int, long

18
Q

Name the different data types that represent floating point numbers (from smallest to largest).

A

float, double

19
Q

Name the eight primitive data types.

A

byte, short, int, long, float, double, char, boolean

20
Q

What is a binary operator?

A

Any operator that takes two operands.

21
Q

What’s the name of an expression where the binary operator has two operands of different data types?

A

Mixed-type expression.

22
Q

Even though widening is legal from type long to type float, what can happen?

A

Widening from type long to type float is legal, because the range of possible float values includes the range of all possible long values. However, some loss of precision is possible in such a conversion because a long value can have as many as 19 significant figures, whereas a float is limited to about 7.

23
Q

Rank the primitive data types from narrowest to widest.

A

boolean (true/false) & byte (integer) –> char (characters) & short (integer) –> int (integer) –> long (integer) –> float (floating point numbers) –> double (floating point numbers)

24
Q

“The scope of this type of variable begins with its declaration inside a method and ends at the end of the block in which it is declared.” What kind of variable is it?

A

Local variable

25
Q

Which of the following statements are true?

  1. A method may have no parameters.
  2. A method may have one or more parameters.
  3. A method may or may not return a value.
A

All 3 are true.

26
Q

Which of the following is the name of a reference type (object type) we have encountered this quarter?

String
Graphics
Scanner
DrawingPanel

A

All of them.

27
Q

The arguments of a method call must match the parameters of a method definition in what ways?

A
  1. The number of arguments must match the number of parameters
  2. The order in which the arguments are listed must match the parameters
  3. The data type of each argument must match the corresponding parameter
28
Q

What units are required when specifying an angle for the trigonometric methods (sin, cos, etc.)?

A

Radians

29
Q

If two methods within the same class have the same name and different parameter lists, what do you have?

A

An overloaded method.

30
Q

What is the name given to a method that can be called using the name of its class, rather than an object reference, as a qualifier (for example, Math.round(…))?

A

A class method or static method.

31
Q

Which of the following is NOT true about class Scanner?

  1. The Scanner class is part of the java.util package.
  2. A Scanner object can be used to get keyboard input if it is constructed using System.in as the source stream.
  3. A Scanner object must be constructed before it can be used.
  4. All of the Scanner methods return type String.
  5. None of the above – all of these statements are true.
A
  1. All of the Scanner methods return type String.
32
Q

What is the correct syntax for declaring a class constant named BET_LIMIT?

A

public static final int BET_LIMIT = 1000;

33
Q

What is the proper way to instantiate a DrawingPanel object?

A

DrawingPanel dp = new DrawingPanel(500, 500);

34
Q

What is the name of a post-test loop in Java, meaning that its test is at the bottom?

A

do…while

35
Q

A problem type known as “loop and a half” is solved using what type of loop?

A

fencepost