wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java

Total questions: 51

Worksheet time: 30mins

Name
Class
Date
1.

Is a high-level, class-based, object-oriented programming language. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA).

a)

Java

b)

JavaScript

c)

C++

d)

C#

2.

What was the original name of the programming language now known as Java?

a)

Green

b)

Oak

c)

Silk

d)

Sun

3.

Used for developing general-purpose applications for desktops, servers, and small-scale applications.

a)

Java SE

b)

Java EE

c)

Java ME

d)

Java FX

4.

Used for developing applications for embedded systems, mobile devices, and IoT devices.

a)

Java SE

b)

Java EE

c)

Java ME

d)

Java FX

5.

Who is commonly referred to as the "father of Java"?

a)

James Gosling

b)

Mike Sheridan

c)

Patrick Naughton

d)

Bill Gates

6.

A software development environment used for developing Java applications

a)

Java Development Kit (JDK)

b)

Java Runtime Environment (JRE)

c)

Java Virtual Machine (JVM)

d)

Java Execution Kit (JEK)

7.

Is an installation package that provides an environment to only run(not develop) the java program(or application)onto your machine.

a)

Java Development Kit (JDK)

b)

Java Runtime Environment (JRE)

c)

Java Virtual Machine (JVM)

d)

Java Execution Kit (JEK)

8.

Is responsible for executing the java program line by line, hence it is also known as an interpreter.

a)

Java Development Kit (JDK)

b)

Java Runtime Environment (JRE)

c)

Java Virtual Machine (JVM)

d)

Java Execution Kit (JEK)

9.

What is a variable in Java?

a)

A method used for performing calculations

b)

A special type of loop in Java

c)

A fixed value that cannot be changed

d)

It is used to store the data temporarily in the computer's memory.

10.

Which naming convention is typically used for class names in Java?

a)

camelCase

b)

PascalCase

c)

snake_case

d)

kebab-case

11.

Which naming convention is commonly used for variable and method names in Java?

a)

camelCase

b)

PascalCase

c)

snake_case

d)

kebab-case

12.

Which of the following naming conventions is typically used for constants (final variables) in Java?

a)

camelCase

b)

PascalCase

c)

UPPER_CASE_SNAKE_CASE

d)

kebab-case

13.

What is the correct naming convention for a Java class name?

a)

employeeDetails

b)

employee_details

c)

EmployeeDetails

d)

employee-details

14.

Which of the following correctly describes the two main categories of data types in Java?

a)

Primitive Types and Object Types

b)

Simple Types and Advanced Types

c)

Primitive Types and Reference Types

d)

Integer Types and Floating Types

15.

Which type of data type is used to store simple values like numbers and characters in Java?

a)

Primitive Types

b)

Reference Types

c)

Object Types

d)

none

16.

Which type of data type is used to store complex values like objects, arrays, and strings in Java?

a)

Primitive Types

b)

Reference Types

c)

Object Types

d)

Array Types

17.

What is the default value of an int in Java?

a)

0

b)

null

c)

undefined

d)

1

18.

Which of the following is NOT a primitive data type in Java?

a)

int

b)

boolean

c)

String

d)

char

19.

What is the default value of a boolean in Java?

a)

0

b)

false

c)

undefined

d)

1

20.

What is type casting in Java?

a)

A method to store multiple values in a single variable

b)

A process of converting the value of one data type to another data type

c)

A way to define custom data types

d)

A process of securing data in Java

21.

Which of the following is an example of Widening Type Casting in Java?

a)

int → short

b)

short → byte

c)

float → double

d)

long → int

22.

Which of the following is an example of Widening Type Casting in Java?

a)

int → short

b)

short → byte

c)

double → float

d)

none

23.

Which of the following is an example of Narrowing Type Casting in Java?

a)

long → int

b)

byte → long

c)

byte → short

d)

none

24.

Which of the following logical operators in Java returns true only if both operands are true?

a)

||

b)

&&

c)

!

d)

^

25.

Which of the following relational operators checks if two values are NOT equal?

a)

==

b)

>=

c)

!=

d)

<

26.

What is the purpose of the switch statement in Java?

a)

It allows us to execute a block of code among many alternatives based on the value of an expression.

b)

It allows us to execute a block of code based on whether a condition is true or false.

c)

It repeats a block of code a certain number of times.

d)

It lets us choose between multiple values without using if statements.

27.

Which of the following is true about the condition in an if statement?

a)

The condition in an if statement must always evaluate to an integer.

b)

The condition in an if statement must evaluate to true or false (a boolean value).

c)

The condition in an if statement must always evaluate to a non-zero value.

d)

The condition in an if statement can be a string.

28.

It handles 2 conditional expressions, it either does the first code block or the second code block.

a)

If-Else Statement

b)

If Statement

c)

If-Else-If Statement

d)

none

29.

Statement hands 3 or more conditional expressions, the possibility of these statements are limitless.

a)

If-Else Statement

b)

If Statement

c)

If-Else-If Statement

d)

none

30.

Repeats a block of code while a condition is true (condition is checked before execution).

a)

While Loop

b)

Do While Loop

c)

For Loop

d)

For each Loop

31.

Used for a known number of iterations with initialization, condition, and increment/decrement.

a)

While Loop

b)

Do While Loop

c)

For Loop

d)

For each Loop

32.

Repeats a block of code at least once and continues as long as the condition is true (condition is checked after execution).

a)

While Loop

b)

Do While Loop

c)

For Loop

d)

For each Loop

33.

It is similar to a conditional statement but only checks for equality and only works with strings, char, int, and enums.

a)

Switch Statements

b)

Variable

c)

Conditional Statements

d)

For each Loop

34.

What is the key difference between a while loop and a do-while loop in Java?

a)

A while loop always executes at least once, while a do-while loop may not execute if the condition is false.

b)

A while loop evaluates the condition before each iteration, while a do-while loop evaluates the condition after each iteration.

c)

A while loop executes only when the condition is false, while a do-while loop executes only when the condition is true.

d)

There is no difference; both loops work the same way.

35.

Which data structure in Java is used to store similar elements and allows only a fixed set of elements?

a)

Stack

b)

Queue

c)

Array

d)

Loop

36.

Which of the following is NOT a valid rule for declaring an array in Java?

a)

An array must have a fixed size once declared.

b)

An array can store multiple data types in a single declaration.

c)

An array can be declared using int[] arr; or int arr[];

d)

An array index starts from 0.

37.

Which of the following is the correct way to declare an array in Java?

a)

int[] numbers = {1, 2, 3, 4, 5};

b)

int numbers(5) = {1, 2, 3, 4, 5};

c)

int numbers = {1, 2, 3, 4, 5};

d)

array numbers[] = {1, 2, 3, 4, 5};

38.

What is the length of this array? String[] fruits = {"Apple", "Banana", "Orange", "Mango", "Grape"};

a)

4

b)

5

c)

6

d)

8

39.

What is the index of "Grape" in the array?

a)

4

b)

3

c)

2

d)

0

40.

If System.out.println(fruits[3]); is printed, what will be the output?

a)

“Apple”

b)

“Banana”

c)

“Orange”

d)

“Mango”

41.

What is the correct way to get the length of this array?

a)

fruits.length()

b)

length(fruits)

c)

fruits.length

d)

Fruits.length()

42.

If System.out.println(fruits[9]); is printed, what will be the output?

a)

“Apple”

b)

“Banana”

c)

“Orange”

d)

Index 5 out of bounds

43.

Which of the following best describes memory allocation in Java?

a)

Java manually manages memory allocation for variables and objects.

b)

The Java Virtual Machine (JVM) automatically allocates memory for variables, objects, and methods.

c)

Memory in Java is only allocated at compile time.

d)

Java does not have a memory management system.

44.

What does the isEmpty() method check?

a)

None

b)

(missing in source)

c)

If the string has whitespace

d)

If the string has a length of 0

45.

What does the replaceAll() do?

a)

Replaces all occurrences of a pattern in a string

b)

Replaces only the first occurrence of a substring

c)

Removes a specific word from a string

d)

Converts a string into an array

46.

This String method returns a unique integer (hash code) for an object, based on its contents.

a)

hashCode()

b)

replaceAll()

c)

trim()

d)

isEmpty()

47.

This String method checks if a string contains a specific sequence of characters and returns true or false.

a)

hashCode()

b)

replaceAll()

c)

contains()

d)

isEmpty()

48.

This String method removes leading and trailing spaces from a string and returns a new string.

a)

hashCode()

b)

replaceAll()

c)

trim()

d)

isEmpty()

49.

This String method converts all characters in a string to uppercase and returns a new string.

a)

toUpperCase()

b)

replaceAll()

c)

trim()

d)

isEmpty()

50.

It is a block of code that performs a specific task and can be called (invoked) from other parts of your program.

a)

Method

b)

String

c)

Loop

d)

Operators

51.

Laboratory Exam (Coding) (100 points)


Instruction: Create a Java class named LastnameFirstnameInstitutionalExam.

In the main method:

  • Prompt the user for the student's name.

  • Prompt the user for scores (0–100) in three subjects: Math, English, and Science.

  • Calculate the average score by adding the three scores and dividing by 3.0.

  • Determine the final letter grade based on the average score using if-else conditions:

    • 90–100 → A

    • 80–89 → B

    • 70–79 → C

    • 60–69 → D

    • Below 60 → F

  • Display the student's name, the average score, and the final letter grade.


Sample Output:

Enter student name: John Doe

Enter Math score (0-100): 87

Enter English score (0-100): 92

Enter Science score (0-100): 85


--- Grading Report ---

Student: John Doe

Average score: 88.00

Final grade: B

51.

Paste your code here:

4 lines