NEW
Font size
WorksheetsIntro to Java Exam Review
Total questions: 40
Worksheet time: 3hrs 7mins
What is wrong with this method declaration?
(I) Not using curly brackets
(II) Missing void
(III) Using public instead of private
(IV) Illegal characters in the method name
I only
I and II
I, II, and III
I, II, III, IV
How can we teach Karel new commands?
A for loop
A while loop
Define a new method
The run method
Why does a programmer indent their code?
Helps show the structure of the code.
Easier for other people to understand.
A key part of good programming style!
All of the above
Which of these is a valid Karel command in Java?
turnLeft();
turnleft();
turnLeft()
TurnLeft
Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?
An if statement
A for loop
A while loop
A nested while loop
Say you want to write a program to have Karel to pick up all of the tennis balls in a location, but you don’t know how many tennis balls there are. Which control structure would you use?
An if statement
A for loop
A while loop
An if/else statement
What is the name of this class?
Karel
FunKarel
Run
SuperKarel
Which of these methods will create a method called turnRight that will have Karel turn left three times?
Which of these is a valid way to write a single line comment in Java?
// This is a comment
++ This is a comment
This is a comment //
/* This is a comment
In the code snippet pictured, how many times will the putBall command run?
100
1
106
107
What is the name of the method to print out text in Java?
System.out.println()
System.out.printline()
System.output()
System.out.PRINTLN()
What is the output of the following lines?
The total is 24
The total is 2424
The total is 48
The total is x + x
Which of the following is not a primitive type?
int
double
String
boolean
What is the value of x after this code?
5
10
4
true
What is the result of this expression?
5
6
6.67
0
Which expression is true?
true && !true
!false || !true
true && false
false || false || !true
Which of these is not a logical operator?
&&
!
||
++
What is the output of this for loop?
The even numbers from 0 to 98, inclusive
The even numbers from 0 to 100, inclusive
All of the numbers from 0 to 100
The odd numbers from 0 to 98, inclusive
What will this program print if the value of grade is 80?
A
B
C
Nothing
What output will be produced by
Hello Karel
HelloKarelHello Karel
Hello
Karel
Error
What are parameters?
The value that a method returns.
The values that a method prints to the screen.
The formal names given to the data that gets passed into a method.
The type that is given to a variable.
What is a method?
A procedure that is defined by the user.
A keyword used to loop for a fixed amount of time.
A place where we can store data.
The type that is given to a variable.
What is a return value?
The value that a method prints to the screen.
The value that is inputted to a method.
The value that a user inputs to a program.
The value that a method outputs.
Why do we use methods in Java programming?
Break down our program into smaller parts
Avoid repeating code
Make our program more readable
All of the above
What function do you need to call to get the width of the screen?
width()
getWidth()
screenWidth()
getScreenWidth()
What are the coordinates of the top right corner of the screen?
(0,0)
(0, getWidth())
(getWidth(), 0)
(getWidth(), getHeight())
What does this program do?
Animates a ball by moving it down and to the right once every 20 milliseconds.
Animates a ball by moving it up and to the right once every 20 milliseconds
Animates a ball by moving it down and to the right every 20 seconds
Animates a ball by moving it up and to the right once every 20 seconds
Which of the following statements are true about ball?
I – ball is a local variable
II – the ball variable in draw is different from the ball variable in start
III – ball is a global variable
IV – ball’s scope includes both start and draw
III and IV
I and II
III only
I, II, III, and IV
Which statement would stop the animation in this program?
stopTimer(ball.move(2, 2));
stopTimer(draw);
stopTimer(draw());
stopTimer(draw, 20);
How many times will the ball be moved before the animation stops?
20
40
2
25
Which of the following are techniques that make our code more reusable?
I – Using constants instead of magic numbers
II – Using specific values in our functions rather than using parameters
III – Writing multiple functions that solve small subproblems rather than one function that solves the entire problem.
IV – Writing as few lines of code as possible
I, II, and III
II and IV
I and III, and IV
I, II, III, and IV
Which function has better reusability?
Which of the following statements will call the function paint every time the mouse is moved?
mouseMoveMethod(paint, e);
mouseMoveMethod(paint);
mouseMoveMethod(paint());
mouseMoveMethod(paint(e));
e is a parameter passed to the callback function paint that contains information about the Mouse Event, such as where on the window it occurred.
e is a variable that paint can store a shape inside of so that start can access it.
e is a parameter of paint that determines what exactly will be painted
e is the callback function of paint
We want to write a function that will remove any shape the user clicks on. Which of the following is the best implementation of the function removeShape?
How can a user move the square up on the screen?
Pressing down the ‘F’ key
Pressing down the UP arrow key
Pressing down the ‘R’ key
Pressing down the LEFT arrow key
In a graphics canvas,, what are the coordinates of the center of the canvas?
getWidth(), getHeight()
getHeight() - getWidth(), getWidth() - getHeight()
getHeight() / 2, getWidth() / 2
getWidth() / 2, getHeight() / 2
What symbol represents the or operator in Java?
OR
or
||
|
The following program should draw a circle on the screen, but when we run this code, we don’t see the circle. What is missing from our start function?
We never set the circle’s radius. We need to add the line
circle.setRadius(40);
After line 4
We are setting the position of the ball to be off the canvas. We need to change line 3 to be
circle.setPosition(0, 0);
We are creating the circle incorrectly. We need to specify the width and height. We need to change line 2 to be
var circle = new Circle(40, 40);
We create the circle and position it correctly on the screen, but we never add it to the screen. We need to add the line
add(circle); after line 4
What does the following code output?
8
daysLeft
The number of days left is daysLeft
The number of days left is 8
