wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

AP Java Quiz 1

Total questions: 50

Worksheet time: 30mins

Name
Class
Date
1.
How would the following evaluate in Java?
   
5%7
a)
5
b)
7
c)
2
d)
0
2.
How would the following evaluate in Java?
7%5
a)
5
b)
7
c)
2
d)
0
3.
What is the output?
System.out.println(2+3.0);
a)
23.0
b)
5
c)
5.0
d)
23
4.
What is the output?
System.out.println(5/2);
a)
2.5
b)
0.4
c)
2
d)
1
5.
What is the output?                          
System.out.println(5/2.0);
a)
2.5
b)
0.4
c)
2
d)
1
6.
An if statement must produce a boolean response of either true or false.
a)
True
b)
False
7.
The operator == means:
a)
Not equal to 
b)
Less than
c)
More than
d)
Equal to
8.
The operator != means:
a)
Equal to
b)
Less than
c)
Not equal to
d)
Greater than or equal to
9.
The operator <= means:
a)
Equal to
b)
Not equal to
c)
Less than
d)
Less than or equal to
10.
The operator > means:
a)
Equal to
b)
Not Equal to
c)
Less than
d)
Greater than
11.
In java, we can replace any single statement with a ______ statement. A _____ statement is a collection of statements enclosed in braces.  
a)
Block
b)
If
c)
If-else
d)
While
12.
Boolean logical operators include all of the following except:
a)
!!
b)
!
c)
&&
d)
||
13.
What does this operator  || mean? 
a)
Logical not
b)
Logical and
c)
Logical or
14.
What is the result of: a && b?
a)
True if a is false and false if a is true 
b)
True if a and b are both true and false otherwise
c)
True if a or b or both are true and false otherwise. 
15.
Sometimes we want to do one thing if a condition is true and another if the condition is false, the second statement is executed. To accomplish this, we use a:
a)
If statement
b)
While statment
c)
Block statement
d)
If-else statement
16.
Assignment operators: 
 What does the operator = do?
a)
Assignment
b)
Concatenation and then assignment
c)
Adding, then assignment
17.
Assignment operators: 
What does %= do: 
a)
Assignment
b)
Division, then assignment
c)
Remainder, then assignment
18.
 In Java, ‘a’ and ‘A’ are considered to be different values.
a)
True
b)
False
19.
The Random class has a method nextDouble( ) which returns a random double value between 0 and 1.
a)
True
b)
False
20.
If a, b and c are int variables with a = 5, b = 7, c = 12, then the statement int z = (a * b – c) / a; will result in z equal to 4.
a)
True
b)
False
21.
Java is a strongly typed language which means every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type.
a)
True
b)
False
22.
The mod operator, %, can only be performed on int values and its result is a double
a)
True
b)
False
23.
The operators * and + have the same precedence.
a)
True
b)
False
24.
If you want to output the text "hi there", including the quote marks, which of the following could do that?
a)
 System.out.println("hi there"); 
b)
System.out.println(""hi there"");
c)
System.out.println("\"hi there"); 
d)
System.out.println("\"hi there\""); 
25.
Which of the following will create space in memory for a variable?
a)
var = 1;
b)
var++;
c)
Pizza var = new Pizza();
d)
int var;
26.
Which of the following is used to output something to the monitor?
a)
println();
b)
System.print("...");
c)
System.out.print("...");
d)
System.out(monitor);
27.
Which symbol is used to create a line comment?
a)
/*...*/
b)
//...//
c)
*/.../*
d)
//
28.
The programming code you write is called ___ and the Java compiler converts it to___ for the Java Virtual Machine to execute.
a)
object code, source code
b)
source code, bytecode
c)
bytecode, object code
d)
object code, ASCII
29.
Which of the following assigns a value to the variable var?
a)
var = value;
b)
int var;
c)
System.out.println("var = value");
d)
value = var;
30.
Which will output "The sum of the numbers is 14"?
a)
System.out.println("The sum of the numbers is 14");
b)
sum = 14;
System.out.println("The sum of the numbers is " + sum);
c)
System.out.println("The sum of the numbers is " + (6 + 8));
d)
all of the above
31.
Which of the following gives the correct symbols for add, subtract, multiply, divide and remainder? (in that order)
a)
+ - x ÷ r
b)
+ - x / %
c)
+ - * / %
d)
+ - * \ %
32.
6 / 4 will result in an integer value of 1.
a)
TRUE
b)
FALSE
33.
The expression: 16.0 / 5  will result in 
a)
3
b)
3.0
c)
3.2
d)
1
34.
Which of the following code segments will  output "FHS" to the screen?
Assume this variable declaration:
Boolean cadet = true;
a)
if (!cadet == false) { System.out.println("FHS"); }
b)
if (cadet == true){ System.out.println("FHS"); }
c)
if(cadet) { System.out.println("FHS");}
d)
all of the above
35.
if x = 2 and y = 6 which of the following would result in the Boolean condition being true?
a)
if ( (x<3) && (y<6) ) {...}
b)
if ( (x<3) || (y<6) ) {...}
c)
if (x > 3) || (y < 6) ) {..}
d)
if ( (x >= 3) && (y <= 6) ) {..}
36.
If x =3, then the boolean condition in the if statement would be 
if ( !(x==2) {...}
a)
true
b)
false
37.
Source Code
a)
•An error in a program that makes it impossible to parse (and therefore impossible to compile).
b)
A program in a high-level language, before being compiled
c)
•To examine a program and analyze the syntactic structure. •
d)
•The process of finding and removing any of the three kinds of errors.
38.
Syntax Error
a)
•An error in a program that makes it impossible to parse (and therefore impossible to compile).
b)
•A statement that creates a new variable and determines its type. 
c)
•A statement that declares a new variable and assigns a value to it at the same time.
d)
•A symbol that represents a computation like addition, multiplication or string concatenation. •
39.
Exception
a)
•An error in a program that makes it fail at run-time. Also called a run-time error. •
b)
•An error in a program that makes it fail at run-time. Also called a run-time error. 
c)
•A statement that assigns a value to a variable.
d)
•A piece of information a method requires before it can run. Parameters are variables: they contain values and have types.
40.
Logic Error
a)
•A symbol that represents a computation like addition, multiplication or string concatenation
b)
•An error in a program that makes it do something other than what the programmer intended.
c)
•A statement that creates a new variable and determines its type.
d)
•A statement that declares a new variable and assigns a value to it at the same time.
41.
Debugging
a)
•The process of finding and removing any of the three kinds of errors.
b)
•To examine a program and analyze the syntactic structure.
c)
•An error in a program that makes it do something other than what the programmer intended.
d)
•An error in a program that makes it fail at run-time. Also called a run-time error.
42.
Declaration
a)
•To join two operands end-to-end.
b)
•A statement that creates a new variable and determines its type.
c)
•An error in a program that makes it do something other than what the programmer intended.
d)
•A piece of information a method requires before it can run. Parameters are variables: they contain values and have types.
43.
Assignment
a)
•taking an Object of one particular type and “turning it into” another Object type.
b)
•A piece of information a method requires before it can run. Parameters are variables: they contain values and have types.
c)
•A statement that assigns a value to a variable.
d)
•A statement that declares a new variable and assigns a value to it at the same time.
44.
Operator
a)
•An error in a program that makes it do something other than what the programmer intended.
b)
•taking an Object of one particular type and “turning it into” another Object type.
c)
•A piece of information a method requires before it can run. Parameters are variables: they contain values and have types.
d)
•A symbol that represents a computation like addition, multiplication or string concatenation.
45.
All the instructions a programmer uses to build the program
a)
Assignment 
b)
Source Code
c)
Operator 
d)
parameter
46.
Similar to sentences in the English language. A sentence forms a complete idea which can include one or more clauses. Likewise, a _______ in Java forms a complete command to be executed and can include one or more expressions.
a)
Declaration 
b)
Operator 
c)
Statement 
d)
Argument 
47.
An algorithm is 
a)
something used only in cooking.  
b)
a list of steps that allow you to complete a task.
c)
how you write the answer to a problem. 
d)
one step out of a list of directions. 
48.
Variable names must begin with a lowercase letter and cannot have any spaces.
a)
True
b)
False
49.
What does the escape sequences to in the output?
String myString = "\"Today's date:\t November 16, 2016\"";
System.out.println(myString);
a)
adds quotations & a tab
b)
adds extra space after the word date
c)
prints nothing 
d)
adds a back slash after the word date
50.
What does an IF statement do?
a)
Closes the program
b)
Makes a decision
c)
Asks a question