wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

AP CSA Unit One Review

Total questions: 23

Worksheet time: 12mins

Name
Class
Date
1.

Which of the following answer choices display the correct format for a Java main class?

a)

public static void main(String [] args)

b)

public void main static(String [] args)

c)

public static main static(String [] args);

d)

public static void main static(Int [] args)

e)

public static main static(String {} args);

2.

Which of the following answer choices shows the output of the following snippet of code?

System.out.print(“Welcome back”);

System.out.println(“IA!”);

System.out.println(“Hope you had a great summer!”);

a)

Welcome back IA! Hope you had a great summer!

b)

Hope you had a great summer!

Welcome back IA!

c)

Welcome back IA!

Hope you had a great summer!

d)

Welcome backIA

Hope you had a great summer!

e)

Welcome back IA!Hope you had a great summer!

3.

Which of the following is NOT a Java Primitive Data Type

a)

String

b)

double

c)

integer

d)

char

e)

boolean

4.

True or False: This code will run with no errors

public class QuizOne

{

            public static void main(String[]args)

            {

System.out.println(“Today is Monday”)

}

            }

a)

True

b)

False

5.

Which of the following lines of code will print “Hello IA” to the console

a)

System.out.print(“Hello IA”)

b)

System.out.println(“Hello IA”);

c)

System.outprint(Hello IA);

d)

System.out.println(Hello IA)

6.

Assuming this code has a main class and runs with no errors, what will be the output on the console:

        double z = 6.7;

        int x = 4;

        int y = 8;

        z = x/y;

        System.out.println(z);

a)

0.5

b)

0

c)

0.0

d)

2

e)

2.0

7.

What is the primary use of the Scanner class in Java?

a)
  • To generate random numbers

b)

To create graphical user interfaces

c)

To read input of primitive data types and strings

d)

To manage database connections

e)

To handle file input/output

8.

How do you correctly create a Scanner object in Java

a)

Scanner myObj = new Scanner()

b)
  • Scanner myObj = new Scanner(java.util.Scanner)

c)

Scanner myObj = new Scanner(System.out)

d)

Scanner myObj = new Scanner(System.in)

e)

Scanner myObj = new Scanner(InputStream)

9.

Which method is used to read a string value using the Scanner class?

a)

nextLine()

b)

nextInt()

c)

nextString()

d)

nextLn()

e)

nextStr()

10.

What does the method nextLine() do in the Scanner class

a)

Reads a Boolean value

b)
  • Reads a String value

c)

Reads an Int value

d)

Reads a Double value

e)

Reads a Float value

11.

Which of the following is not a method of the Scanner class for reading specific data types?

a)

nextInt()

b)

nextFloat()

c)

nextChar()

d)

nextBoolean()

e)

nextByte()

12.

What does the Scanner class do with an input line such as “How are you”?

a)

Divides it into numbers

b)

Splits the line into tokens

c)

Converts it into an array

d)

Reads it as a single integer

e)

Ignores any whitespace characters

13.

What is the difference between .equals() and ==

a)

== is an operator that compares the references or memory addresses of objects to determine if they are the same, whereas . equals() is a method that compares the contents of the objects to check for value equality

b)

equals() is a method that compares the references or memory addresses of objects to determine if they are the same, whereas == is a operator that compares the contents of the objects to check for value equality

14.

A method must be declared within a _____________.

a)

variable

b)

object

c)

main

d)

class

15.

What will be the output of the following code snippet?

int a = 5;

int b = 10;

System.out.println(a + b);

a)

15

b)

510

c)

5 + 10

d)

Compilation Error

16.

What will be the output of the following code snippet?

int x = 7;

int y = 3;

System.out.println(x % y);

a)

1

b)

2

c)

3

d)

4

17.

Which of the following is the correct way to declare a constant in Java?

a)

final int MAX_VALUE = 100;

b)

const int MAX_VALUE = 100;

c)

int const MAX_VALUE = 100;

d)

int MAX_VALUE = 100;

18.

What will be the output of the following code snippet?

String str = "Hello";

str += " World";

System.out.println(str);

a)

Hello

b)

Hello World

c)

World

d)

Compilation Error

19.

What will be the output of the following code snippet?

int a = 10;

int b = 3;

System.out.println(a / b);

a)

3.3333

b)

3

c)

3.0

d)

Compilation Error

20.

What will be the output of the following code snippet?

String s1 = "Hello";

String s2 = "Hello";

System.out.println(s1 == s2);

a)

true

b)

false

c)

Compilation Error

d)

Runtime Error

21.

Which of the following is the correct way to create an object of the class 'Car' in Java?

a)

Car myCar = new Car();

b)

Car myCar = Car();

c)

Car myCar = new Car;

d)

Car myCar = Car.new();

22.

What will be the output of the following code snippet?

int a = 5;

int b = 2;

System.out.println(a * b);

a)

10

b)

7

c)

3

d)

2.5

23.

What will be the output of the following code snippet?

String str = "Hello";

System.out.println(str.length());

a)

4

b)

5

c)

6

d)

7