wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Intro to Java Exam Review

Total questions: 40

Worksheet time: 3hrs 7mins

Name
Class
Date
1.

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

a)

I only

b)

I and II

c)

I, II, and III

d)

I, II, III, IV

2.

How can we teach Karel new commands?

a)

A for loop

b)

A while loop

c)

Define a new method

d)

The run method

3.

Why does a programmer indent their code?

a)

Helps show the structure of the code.

b)

Easier for other people to understand.

c)

A key part of good programming style!

d)

All of the above

4.

Which of these is a valid Karel command in Java?

a)

turnLeft();

b)

turnleft();

c)

turnLeft()

d)

TurnLeft

5.

Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?

a)

An if statement

b)

A for loop

c)

A while loop

d)

A nested while loop

6.

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?

a)

An if statement

b)

A for loop

c)

A while loop

d)

An if/else statement

7.

What is the name of this class?

a)

Karel

b)

FunKarel

c)

Run

d)

SuperKarel

8.

Which of these methods will create a method called turnRight that will have Karel turn left three times?

a)

b)

c)

d)

9.

Which of these is a valid way to write a single line comment in Java?

a)

// This is a comment

b)

++ This is a comment

c)

This is a comment //

d)

/* This is a comment

10.

In the code snippet pictured, how many times will the putBall command run?

a)

100

b)

1

c)

106

d)

107

11.

What is the name of the method to print out text in Java?

a)

System.out.println()

b)

System.out.printline()

c)

System.output()

d)

System.out.PRINTLN()

12.

What is the output of the following lines?

a)

The total is 24

b)

The total is 2424

c)

The total is 48

d)

The total is x + x

13.

Which of the following is not a primitive type?

a)

int

b)

double

c)

String

d)

boolean

14.

What is the value of x after this code?

a)

5

b)

10

c)

4

d)

true

15.

What is the result of this expression?

a)

5

b)

6

c)

6.67

d)

0

16.

Which expression is true?

a)

true && !true

b)

!false || !true

c)

true && false

d)

false || false || !true

17.

Which of these is not a logical operator?

a)

&&

b)

!

c)

||

d)

++

18.

What is the output of this for loop?

a)

The even numbers from 0 to 98, inclusive

b)

The even numbers from 0 to 100, inclusive

c)

All of the numbers from 0 to 100

d)

The odd numbers from 0 to 98, inclusive

19.

What will this program print if the value of grade is 80?

a)

A

b)

B

c)

C

d)

Nothing

20.

What output will be produced by

a)

Hello Karel

b)

HelloKarelHello Karel

c)

Hello

Karel

d)

Error

21.

What are parameters?

a)

The value that a method returns.

b)

The values that a method prints to the screen.

c)

The formal names given to the data that gets passed into a method.

d)

The type that is given to a variable.

22.

What is a method?

a)

A procedure that is defined by the user.

b)

A keyword used to loop for a fixed amount of time.

c)

A place where we can store data.

d)

The type that is given to a variable.

23.

What is a return value?

a)

The value that a method prints to the screen.

b)

The value that is inputted to a method.

c)

The value that a user inputs to a program.

d)

The value that a method outputs.

24.

Why do we use methods in Java programming?

a)

Break down our program into smaller parts

b)

Avoid repeating code

c)

Make our program more readable

d)

All of the above

25.

What function do you need to call to get the width of the screen?

a)

width()

b)

getWidth()

c)

screenWidth()

d)

getScreenWidth()

26.

What are the coordinates of the top right corner of the screen?

a)

(0,0)

b)

(0, getWidth())

c)

(getWidth(), 0)

d)

(getWidth(), getHeight())

27.

What does this program do?

a)

Animates a ball by moving it down and to the right once every 20 milliseconds.

b)

Animates a ball by moving it up and to the right once every 20 milliseconds

c)

Animates a ball by moving it down and to the right every 20 seconds

d)

Animates a ball by moving it up and to the right once every 20 seconds

28.

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

a)

III and IV

b)

I and II

c)

III only

d)

I, II, III, and IV

29.

Which statement would stop the animation in this program?

a)

stopTimer(ball.move(2, 2));

b)

stopTimer(draw);

c)

stopTimer(draw());

d)

stopTimer(draw, 20);

30.

How many times will the ball be moved before the animation stops?

a)

20

b)

40

c)

2

d)

25

31.

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

a)

I, II, and III

b)

II and IV

c)

I and III, and IV

d)

I, II, III, and IV

32.

Which function has better reusability?

a)

b)

33.

Which of the following statements will call the function paint every time the mouse is moved?

a)

mouseMoveMethod(paint, e);

b)

mouseMoveMethod(paint);

c)

mouseMoveMethod(paint());

d)

mouseMoveMethod(paint(e));

34.
a)

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.

b)

e is a variable that paint can store a shape inside of so that start can access it.

c)

e is a parameter of paint that determines what exactly will be painted

d)

e is the callback function of paint

35.

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?

a)

b)

c)

d)

36.

How can a user move the square up on the screen?

a)

Pressing down the ‘F’ key

b)

Pressing down the UP arrow key

c)

Pressing down the ‘R’ key

d)

Pressing down the LEFT arrow key

37.

In a graphics canvas,, what are the coordinates of the center of the canvas?

a)

getWidth(), getHeight()

b)

getHeight() - getWidth(), getWidth() - getHeight()

c)

getHeight() / 2, getWidth() / 2

d)

getWidth() / 2, getHeight() / 2

38.

What symbol represents the or operator in Java?

a)

OR

b)

or

c)

||

d)

|

39.

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?

a)

We never set the circle’s radius. We need to add the line

circle.setRadius(40);

After line 4

b)

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);

c)

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);

d)

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

40.

What does the following code output?

a)

8

b)

daysLeft

c)

The number of days left is daysLeft

d)

The number of days left is 8