Midterm Exam Flashcards

1
Q

When you create a block, you must place multiple statements within it.

A

False

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

Which of the following is NOT a component of a variable declaration statement?

a.
variable name

b.
ending semicolon

c.
data type identifier

d.
symbolic constant

A

symbolic constant

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

Although not a requirement, it is Java standard that class identifiers begin with an uppercase letter and use other uppercase letters to improve readability.

A

True

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

The executable file that executes a Java bytecode into a machine code:
Select one:

a.
javax

b.
java

c.
javaw

d.
javah

e.
appletviewer

f.
javac

A

java

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

Modulus operator, %, can be applied to which of these?

Select one:

a.
Both Integers and floating

b.
None of the mentioned

c.
Integers

d.
Floating

A

Both Integers and floating

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

A ____ is a named memory location that you can use to store a value
a.
primitive

b.
reference

c.
variable

d.
cast

A

variable

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

Java methods must be located inside a class.

A

True

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

Although not required, it is common procedure to align the keyword if with the keyword else.

A

True

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

Which of these is returned by greater than,

A

Boolean

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

The literals 5, 23, -2, and 900 are integer literals in Java and are of automatic type long.

A

False’.

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

Which of these statement is correct?
Select one:

a.
true and false are non numeric values.

b.
true is any non zero value and false is 0.

c.
true and false are numeric values 1 and 0.

d.
true and false are numeric values 0 and 1.

A

true and false are non numeric values.

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

What is the operand of arithmetic operators?
Select one:

a.
Numeric

b.
Both Numeric & Characters

c.
Characters

d.
Boolean

A

Both Numeric & Characters

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

All Java statements are terminated with a semicolon.

A

True

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

A loop that never ends is called a(n) ____ loop.

a.
while

b.
for

c.
infinite

d.
definite

A

infinite

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

Which of these is necessary condition for automatic type conversion in Java?
Select one:

a.
None of the mentioned

b.
The destination type is smaller than source type.

c.
The destination type is larger than source type.

d.
The destination type can be larger or smaller than source type.

A

The destination type is larger than source type.

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

____ occurs when both of the operands are integers.
Unlike assignment

b.
Integer division

c.
Data modeling

d.
Type cast

A

Integer division

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

Classes and methods are always defined in blocks of code enclosed in {}.

A

True

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

In the switch structure, break is followed by one of the possible values for the test expression and a colon.

A

False

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

A variable can hold more than one value at a time.

A

False’.

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

When you place a block within an if statement, it is crucial to place the ____ correctly.

a.
commas

b.
periods

c.
curly braces

d.
angle brackets

A

curly braces

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

When an expression containing a ____ is part of an if statement, the assignment is illegal.

a.
Boolean value

b.
double equal sign

c.
single equal sign

d.
greater than sign

A

single equal sign

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

Local variables are variables that are declared inside the class but outside the method.

A

False’.

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

A compiler ignores whitespace (that is, any combination of nonprinting characters) between words and lines.

A

‘True’.

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

true && false || 9 < 4 + 5

A

False’.

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

In Java, when a numeric variable is concatenated to a String using the ____, the entire expression becomes a String.

a.
plus sign

b.
equal sign

c.
concatenate statement

d.
string statement

A

plus sign

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

The ____ operator is always evaluated before the OR operator.

a.
AND

b.
Assignment

c.
Logical

d.
Conditional

A

AND

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

JDK stands for Java _____ Kit.
Select one:

a.
Distinct

b.
Distributed

c.
Design

d.
Development

A

Development

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

Why is the main() method special in a Java program?
Select one:

a.
Every class must have a main() method.
b.
The main() method must be the only static method in a program.

c.
Only the main() method may create objects.

d.
It is where the Java interpreter starts the whole program running.

A

It is where the Java interpreter starts the whole program running.

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

The compiler does not take indentation into account when compiling code, but consistent indentation can help readers understand a program’s ____.

a.
decision

b.
machine language

c.
logic

d.
class

A

logic

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

What is the size of a double variable in Java?
Select one:

a.
2 bytes

b.
8 bytes

c.
It depends on the compiler setting

d.
It depends on the operating system

e.
4 bytes

A

8 bytes

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

A logical structure called a(n) ____ structure is when one step follows another unconditionally.

a.
decision

b.
straight

c.
unconditional

d.
sequence

A

sequence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
What is the output of this program?
 class conversion {
 public static void main(String args[]) 
 { 
 double a = 295.04;
 int b = 300;
 byte c = (byte) a;
 byte d = (byte) b;
 System.out.println(c + " " + d);
 } 
 }

Select one:

a.
39 44

b.
295 300

c.
38 43

d.
295.04 300

A

295 300

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

IDE stands for _____ Development Environment.
Select one:

a.
Integrated

b.
Integral

c.
Instantiated

d.
Interface

A

Integrated

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

The extension used for a java source file is .class.

A

False’.

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

Short is an object data type in Java.

A

‘True’.

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

You use the NOT operator, which is written as the exclamation point (!), to negate the result of any Boolean expression.

A

True’.

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

The byte and short data types occupy less memory and can hold only smaller values.

A

‘True’.

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

API stands for _____ Programming Interface.
Select one:

a.
Application

b.
Asynchronous

c.
Amplified

d.
Advanced

A

Application

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

The kinds of loops based on behavior:
Select one:

a.
Linear, Matrix, Multi-Dimensional

b.
Class, Method, Statement

c.
while, do while, for

d.
Counting, Sentinel-Controlled, Result-Controlled

A

Counting, Sentinel-Controlled, Result-Controlled

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

You use the ____ data type to hold any single character.

a.
char

b.
byte

c.
single

d.
float

A

char

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

You can use the ____, which is written as ||, if you want some action to occur when at least one of two conditions is true.

a.
switch statement

b.
logical AND operator

c.
conditional OR operator

d.
range check

A

conditional OR operator

42
Q

In Java, you use variables of type ____ to store integers, or whole numbers.

a.
num

b.
int

c.
double

d.
var

A

int

43
Q

Int data types represents _______ bits.

a.
8

b.
32

c.
64

d.
16

A

32

44
Q

The ____ operator is written as the exclamation point ( ! ).

a.
NOT

b.
assignment

c.
equality

d.
AND

A

NOT

45
Q

The kinds of loops based on Java syntax:
Select one:

a.
Class, Method, Statement

b.
Counting, Sentinel-Controlled, Result-Controlled

c.
while, do while, for

d.
Linear, Matrix, Multi-Dimensional

A

while, do while, for

46
Q

You can leave out the ____ statements in a switch structure.

a.
if

b.
case

c.
break

d.
switch

A

break

47
Q

Multiplication, division, and remainder always take place after addition or subtraction in an expression.

A

‘False’.

48
Q

When you use nested if statements, you must pay careful attention to placement of any else clauses.

A

‘True’.

49
Q

true, false, null, goto, try and catch are part of the Java reserved words.

A

‘True’.

50
Q
What is the output of this program?
 class increment {
 public static void main(String args[]) 
 { 
 int g = 3;
 System.out.print(++g * 8);
 } 
 }

Select one:

a.
25

b.
33

c.
32

d.
24

A

32

51
Q

When you block statements, you must remember that any ____ you declare within a block is local to that block

a.
expression

b.
method

c.
variable

d.
decision

A

variable

52
Q

Which of these operators can skip evaluating right hand operand?
Select one:

a.
!

b.
|

c.
&&

d.
&

A

&&

53
Q

Statements in which an if structure is contained inside another if structure are commonly called ____ if statements.

a.
inside

b.
logical

c.
blocked

d.
nested

A

nested

54
Q

Which of these statement is incorrect?
Select one:

a.
it is possible to create a nested switch statements.

b.
two case constants in the same switch can have identical values.

c.
switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression.

d.
switch statement is more efficient than a set of nested ifs.

A

two case constants in the same switch can have identical values.

55
Q

Which of these have highest precedence?
Select one:

a.
*

b.
()

c.
»

d.
++

A

( )

56
Q

____ refers to the order in which values are used with operators.

a.
Initialization

b.
Associativity

c.
Declaration

d.
Floating

A

Associativity

57
Q

Just as you can block statements that depend on an if, you can also block statements that depend on a(n) ____.

a.
operator

b.
Boolean expression

c.
else

d.
constant

A

else

58
Q

What sort of thing is “Nothing New” as in the following: String str = “Nothing New”;
Select one:

a.
A String shortcut

b.
An optimized String

c.
A quoted String

d.
A String literal

A

A String literal

59
Q

What will the output of the following code segment be?
int a = 1, b = 2;

System.out.println(++a+”,”+b++);

a.
2,2

b.
3,3

c.
2,3

d.
1,2

A

2,2

60
Q

What is the keyword “final” used for in Java?

a.
identify a string

b.
identify an integer

c.
identify a constant

d.
identify a final answer

A

identify a constant

61
Q

logic errors are easily identified when a program is compiled

A

False

62
Q

The kinds of loops based on dimension:
Select one:

a.
while, do while, for

b.
Class, Method, Statement

c.
Counting, Sentinel-Controlled, Result-Controlled

d.
Linear, Matrix, Multi-Dimensional

A

Linear, Matrix, Multi-Dimensional

63
Q

A ____ is a structure that allows repeated execution of a block of statements.

a.
loop

b.
loop control

c.
Boolean expression

d.
body

A

loop

64
Q

An expression involving byte, int, and whole literal numbers is promoted to which of these?
Select one:

a.
int

b.
byte

c.
float

d.
long

A

int

65
Q
Identify what java language component are the following:
helloWorld
HELLO_WORLD
hello.world
helloWorld()
HelloWorld
A

helloWorld
variable

HELLO_WORLD
constant

hello.world
package

helloWorld()
method

HelloWorld
class

66
Q

The AND operator is written as two ____.

a.
asterisks

b.
equal signs

c.
plus signs

d.
ampersands

A

ampersands

67
Q

Which are legal declarations? (Choose all that apply)

a.
short[5] x2;

b.
short [] y;

c.
[5];

d.
short [] y2

e.
short x [];

f.
short z2 [5];

A

short x [];, short [] y;, [5];

68
Q

A Java identifier can contain only letters, digits, ampersands, or number signs.

A

‘False’.

69
Q

An expression involving byte, int, and whole literal numbers is promoted to which of these?
Select one:

a.
int

b.
byte

c.
float

d.
long

A

int

70
Q
What is the output of this program?
 class Output {
 public static void main(String args[]) 
 { 
 int a = 1;
 int b = 2;
 int c;
 int d;
 c = ++b;
 d = a++;
 c++;
 b++;
 \++a;
 System.out.println(a + " " + b " " + c);
 } 
 }
Select one:

a.
3 2 3

b.
2 3 4

c.
3 4 4

d.
3 2 4

A

3 4 4

71
Q
What is the output of this program?
 class increment {
 public static void main(String args[]) 
 { 
 int g = 3;
 System.out.print(++g * 8);
 } 
 }

Select one:

a.
25

b.
33

c.
32

d.
24

A

32

72
Q
What is the output of this program?
 class jump_statments {
 public static void main(String args[]) 
 { 
 int x = 2;
 int y = 0;
 for ( ; y < 10; ++y) {
 if (y % x == 0) 
 continue; 
 else if (y == 8)
 break;
 else
 System.out.print(y + " ");
 }
 } 
 }
Select one:

a.
1 3 5 7 9

b.
2 4 6 8

c.
1 3 5 7

d.
1 2 3 4 5 6 7 8 9

A

1 3 5 7 9

73
Q
What is the output of this program?
 class operators {
 public static void main(String args[]) 
 { 
 int x = 8;
 System.out.println(++x * 3 + " " + x);
 } 
 }
Select one:

a.
27 9

b.
27 8

c.
24 8

d.
24 9

A

27 9

74
Q

Java supports only 2 kinds of comment styles, single-line and multi-line.

A

False

75
Q

A(n) ____ variable can hold only one of two values: true or false.

a.
true

b.
boolean

c.
comparison

d.
integer

A

boolean

76
Q

Which of the following will output -4.0
Select one:

a.
System.out.println(Math.min(-4.7));

b.
System.out.println(Math.ceil(-4.7));

c.
System.out.println(Math.floor(-4.7));

d.
System.out.println(Math.round(-4.7));

A

System.out.println(Math.ceil(-4.7));

77
Q
Determine if the following names are valid or in invalid:
booleaN
object
compute-Tax
0ThreeTwo
Class
A
booleaN → valid, 
object → valid,
 compute-Tax → invalid, 
0ThreeTwo → invalid, 
Class → valid
78
Q

You are limited to declaring a maximum of three variables in a single statement.

A

‘False’.

79
Q

You use a unary minus sign preceding a value to make the value ____.

a.
constant

b.
positive

c.
negative

d.
valid

A

negative

80
Q

Keywords can be used as a name of a variable, method of class as long as they start with capital letter.

A

‘True’

81
Q

A ____ checks a value, and based on the result performs one of two actions.

a.
decision structure
block structure

b.
sequence structure

c.
short-circuit structure

A

decision structure

block structure

82
Q

When you want to increase a variable’s value by exactly 1, use the ____.

a.
binary operators

b.
prefix increment operator

c.
accumulating operator

d.
power statement

A

prefix increment operator

83
Q

The simplest statement you can use to make a decision is the ____ statement.

a.
if

b.
Boolean

c.
this

d.
true false

A

if

84
Q

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
Select one:

a.
while

b.
for

c.
None of the mentioned

d.
do-while

A

do-while

85
Q

Java is case insensitive.

A

‘False’.

86
Q

The ____ statement is useful when you need to test a single variable against a series of exact integer, character, or string values.

a.
switch

b.
else

c.
if

d.
break

A

switch

87
Q

The executable file that compiles a Java source code into a byte code:
Select one:

a.
java

b.
javah

c.
appletviewer

d.
javac

e.
javaw

f.
javax

A

javac

88
Q

The ____ statement is useful when you need to test a single variable against a series of exact integer, character, or string values.

a.
switch

b.
else

c.
if

d.
break

A

switch

89
Q

Decide what should be the data type for the following literals:

The monthly salary of an employee without cents

The name of a person

The flag that either turns on or off

The blood type of a person

The account balance of a persons bank savings

A

The monthly salary of an employee without cents → int,

The name of a person → String,

The flag that either turns on or off → boolean,

The blood type of a person → String,

The account balance of a persons bank savings → double

90
Q

Evaluate the following conditions whether it yields a true or a false:
100+18%81-34+563%12>=66/32-11&&335%7!=10*44-8

2334+7%21/6==125%6/3||23*5%9+1<16

!true&&false||!true||!false&&23%34+12<10

34+7>23||23<7+43

10%345%7-208/32<=49/3+7%6&&23+9-8*5%12>18

A

100+18%81-34+563%12>=66/32-11&&335%7!=10*44-8 → true,

2334+7%21/6==125%6/3||23*5%9+1<16 → true,

!true&&false||!true||!false&&23%34+12<10 → false,

34+7>23||23<7+43 → false,

10%345%7-208/32<=49/3+7%6&&23+9-8*5%12>18 → true

91
Q

Identify what type of operators are the following:

*
<=
?:
||
%
A
* → arithmetic, 
<= → relational,
 ?: → ternary,
 || → logical,
 % → arithmetic
92
Q

The int data type is the most commonly used integer type.

A

True’.

93
Q

What is the range of data type short in Java?
Select one:

a.
-32768 to 32767

b.
None of the mentioned

c.
-128 to 127

d.
-2147483648 to 2147483647

A

-32768 to 32767

94
Q

In Java, ____ is a built-in class that provides you with the means for storing and manipulating character strings.

a.
Escape

b.
Character

c.
String

d.
Type

A

String

95
Q

When nesting loops, the variable in the outer loop changes more frequently.

A

False’.

96
Q

Which of these selection statements test only for equality?
Select one:

a.
if

b.
None of the mentioned

c.
switch

d.
Both if and switch

A

switch

97
Q

Even if a statement occupies multiple lines, the statement is not complete until the semicolon is reached.

A

True’.

98
Q

What is the output of relational operators?
Select one:

a.
Characters

b.
Integer

c.
Double

d.
Boolean

A

Boolean

99
Q
What is the output of this program?
 class operators {
 public static void main(String args[])
 {
 int var1 = 5; 
 int var2 = 6;
 int var3;
 var3 = ++ var2 * var1 / var2 + var2;
 System.out.print(var3);
 } 
 }
Select one:

a.
12

b.
11

c.
56

d.
10

A

11

100
Q

The extension of the bytecode file that is generated after successful compilation is .java

A

False’.

101
Q

Boolean is a primitive data type in Java.

A

true