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
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
plus sign
26
The ____ operator is always evaluated before the OR operator. a. AND b. Assignment c. Logical d. Conditional
AND
27
JDK stands for Java _____ Kit. Select one: a. Distinct b. Distributed c. Design d. Development
Development
28
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.
It is where the Java interpreter starts the whole program running.
29
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
logic
30
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
8 bytes
31
A logical structure called a(n) ____ structure is when one step follows another unconditionally. a. decision b. straight c. unconditional d. sequence
sequence
32
``` 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
295 300
33
IDE stands for _____ Development Environment. Select one: a. Integrated b. Integral c. Instantiated d. Interface
Integrated
34
The extension used for a java source file is .class.
False'.
35
Short is an object data type in Java.
'True'.
36
You use the NOT operator, which is written as the exclamation point (!), to negate the result of any Boolean expression.
True'.
37
The byte and short data types occupy less memory and can hold only smaller values.
'True'.
38
API stands for _____ Programming Interface. Select one: a. Application b. Asynchronous c. Amplified d. Advanced
Application
39
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
Counting, Sentinel-Controlled, Result-Controlled
40
You use the ____ data type to hold any single character. a. char b. byte c. single d. float
char
41
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
conditional OR operator
42
In Java, you use variables of type ____ to store integers, or whole numbers. a. num b. int c. double d. var
int
43
Int data types represents _______ bits. a. 8 b. 32 c. 64 d. 16
32
44
The ____ operator is written as the exclamation point ( ! ). a. NOT b. assignment c. equality d. AND
NOT
45
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
while, do while, for
46
You can leave out the ____ statements in a switch structure. a. if b. case c. break d. switch
break
47
Multiplication, division, and remainder always take place after addition or subtraction in an expression.
'False'.
48
When you use nested if statements, you must pay careful attention to placement of any else clauses.
'True'.
49
true, false, null, goto, try and catch are part of the Java reserved words.
'True'.
50
``` 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
32
51
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
variable
52
Which of these operators can skip evaluating right hand operand? Select one: a. ! b. | c. && d. &
&&
53
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
nested
54
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.
two case constants in the same switch can have identical values.
55
Which of these have highest precedence? Select one: a. * b. () c. >> d. ++
( )
56
____ refers to the order in which values are used with operators. a. Initialization b. Associativity c. Declaration d. Floating
Associativity
57
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
else
58
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 String literal
59
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
2,2
60
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
identify a constant
61
logic errors are easily identified when a program is compiled
False
62
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
Linear, Matrix, Multi-Dimensional
63
A ____ is a structure that allows repeated execution of a block of statements. a. loop b. loop control c. Boolean expression d. body
loop
64
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
int
65
``` Identify what java language component are the following: helloWorld HELLO_WORLD hello.world helloWorld() HelloWorld ```
helloWorld variable HELLO_WORLD constant hello.world package helloWorld() method HelloWorld class
66
The AND operator is written as two ____. a. asterisks b. equal signs c. plus signs d. ampersands
ampersands
67
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];
short x [];, short [] y;, [5];
68
A Java identifier can contain only letters, digits, ampersands, or number signs.
'False'.
69
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
int
70
``` 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
3 4 4
71
``` 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
32
72
``` 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
1 3 5 7 9
73
``` 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
27 9
74
Java supports only 2 kinds of comment styles, single-line and multi-line.
False
75
A(n) ____ variable can hold only one of two values: true or false. a. true b. boolean c. comparison d. integer
boolean
76
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));
System.out.println(Math.ceil(-4.7));
77
``` Determine if the following names are valid or in invalid: booleaN object compute-Tax 0ThreeTwo Class ```
``` booleaN → valid, object → valid, compute-Tax → invalid, 0ThreeTwo → invalid, Class → valid ```
78
You are limited to declaring a maximum of three variables in a single statement.
'False'.
79
You use a unary minus sign preceding a value to make the value ____. a. constant b. positive c. negative d. valid
negative
80
Keywords can be used as a name of a variable, method of class as long as they start with capital letter.
'True'
81
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
decision structure | block structure
82
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
prefix increment operator
83
The simplest statement you can use to make a decision is the ____ statement. a. if b. Boolean c. this d. true false
if
84
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
do-while
85
Java is case insensitive.
'False'.
86
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
switch
87
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
javac
88
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
switch
89
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
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
Evaluate the following conditions whether it yields a true or a false: 100+18%81-34+56*3%12>=66/32-11&&33*5%7!=10*44-8 23*34+7%21/6==12*5%6/3||23*5%9+1<16 !true&&false||!true||!false&&23%34+12<10 3*4+7>23||23<7+4*3 10%3*45%7-20*8/32<=49/3+7%6&&23+9-8*5%12>18
100+18%81-34+56*3%12>=66/32-11&&33*5%7!=10*44-8 → true, 23*34+7%21/6==12*5%6/3||23*5%9+1<16 → true, !true&&false||!true||!false&&23%34+12<10 → false, 3*4+7>23||23<7+4*3 → false, 10%3*45%7-20*8/32<=49/3+7%6&&23+9-8*5%12>18 → true
91
Identify what type of operators are the following: ``` * <= ?: || % ```
``` * → arithmetic, <= → relational, ?: → ternary, || → logical, % → arithmetic ```
92
The int data type is the most commonly used integer type.
True'.
93
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
-32768 to 32767
94
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
String
95
When nesting loops, the variable in the outer loop changes more frequently.
False'.
96
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
switch
97
Even if a statement occupies multiple lines, the statement is not complete until the semicolon is reached.
True'.
98
What is the output of relational operators? Select one: a. Characters b. Integer c. Double d. Boolean
Boolean
99
``` 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
11
100
The extension of the bytecode file that is generated after successful compilation is .java
False'.
101
Boolean is a primitive data type in Java.
true