Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Programming Quiz

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.

What is Java primarily known as?

a)

A high-level programming language

b)

A low-level programming language

c)

A web server

d)

A database management system

2.

Who is known as the father of Java?

a)

James Gosling

b)

Bjarne Stroustrup

c)

Dennis Ritchie

d)

Guido van Rossum

3.

What does JRE stand for?

a)

Java Runtime Execution

b)

Java Resource Environment

c)

Java Runtime Environment

d)

Java Resource Execution

4.

Which of the following is NOT a feature of Java?

a)

Low-level

b)

Dynamic

c)

Robust

d)

Object-Oriented

5.

What is the purpose of the Java Virtual Machine (JVM)?

a)

To execute Java bytecode

b)

To compile Java code

c)

To manage memory

d)

To provide a graphical interface

6.

Which keyword is used to define a class in Java?

a)

class

b)

define

c)

object

d)

new

7.

What is the default value of a boolean variable in Java?

a)

1

b)

true

c)

false

d)

0

8.

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

a)

String

b)

ArrayList

c)

int

d)

HashMap

9.

What does the 'static' keyword indicate in Java?

a)

The method is private

b)

The method is abstract

c)

The method can be overridden

d)

The method belongs to the class rather than instances

10.

Which of the following is used for exception handling in Java?

a)

try-catch

b)

if-else

c)

for-loop

d)

switch-case

11.

What is the output of the following code: System.out.println(5 + 3);?

a)

5 + 3

b)

Error

c)

53

d)

8

12.

Which of the following is a valid declaration of a String in Java?

a)

String str = 'Hello';

b)

String str = "Hello";

c)

String str = 'H' + 'e' + 'l' + 'l' + 'o';

d)

String str = Hello;

13.

What is the purpose of the 'main' method in Java?

a)

To start the execution of a program

b)

To define a class

c)

To handle exceptions

d)

To declare variables

14.

Which of the following is NOT a control statement in Java?

a)

if

b)

for

c)

while

d)

define

15.

What is the result of 10 % 3 in Java?

a)

10

b)

0

c)

1

d)

3

16.

Which of the following is used to create an object in Java?

a)

new

b)

create

c)

init

d)

object

17.

What is the purpose of the 'break' statement in Java?

a)

To exit a loop

b)

To continue to the next iteration

c)

To define a method

d)

To declare a variable

18.

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

a)

int arr[5];

b)

int[] arr = int[5];

c)

int arr = new int[5];

d)

int arr[] = new int[5];

19.

What is the output of the following code: System.out.println(3 + 4 + '5');?

a)

Error

b)

34

c)

12

d)

75

20.

Which of the following is a valid comment in Java?

a)

# This is a comment

b)

<-- This is a comment -->

c)

/* This is a comment

d)

// This is a comment

21.

What is the purpose of the 'return' statement in a method?

a)

To create an object

b)

To declare a variable

c)

To return a value to the caller

d)

To exit the method

22.

Which of the following is a valid way to handle exceptions in Java?

a)

try-catch

b)

if-else

c)

switch-case

d)

for-loop

23.

What is the default value of an integer variable in Java?

a)

0

b)

1

c)

null

d)

undefined

24.

Which of the following is a method to convert a string to an integer in Java?

a)

convert()

b)

intValue()

c)

toInt()

d)

parseInt()

25.

What is the purpose of the 'this' keyword in Java?

a)

To refer to the current object

b)

To create a new object

c)

To call a method

d)

To define a class

26.

Which of the following is a valid way to declare a method in Java?

a)

public myMethod() void {}

b)

public void myMethod() {}

c)

void myMethod() public {}

d)

myMethod() public void {}

27.

What is the output of the following code: System.out.println(10 / 3);?

a)

3

b)

3.33

c)

Error

d)

3.0

28.

Which of the following is a valid way to create a new thread in Java?

a)

new Thread()

b)

create Thread()

c)

Thread.new()

d)

start Thread()

29.

What is the purpose of the 'synchronized' keyword in Java?

a)

To define a method

b)

To declare a variable

c)

To create a new thread

d)

To prevent thread interference

30.

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

a)

int x = final 10;

b)

const int x = 10;

c)

final int x = 10;

d)

int const x = 10;

31.

What is the output of the following code: System.out.println('A' + 1);?

a)

66

b)

B

c)

A1

d)

Error

32.

Which of the following is a valid way to declare a multi-dimensional array in Java?

a)

int arr = new int[3][3];

b)

int arr[3][3];

c)

int arr[][] = new int[3][3];

d)

int[][] arr = new int[3][3];

33.

What is the purpose of the 'volatile' keyword in Java?

a)

To define a method

b)

To declare a variable

c)

To create a new thread

d)

To indicate that a variable may be changed unexpectedly

34.

Which of the following is a valid way to declare an interface in Java?

a)

interface MyInterface {}

b)

MyInterface {}

c)

MyInterface interface {}

d)

interface MyInterface() {}

35.

What is the output of the following code: System.out.println(5 == 5);?

a)

5

b)

Error

c)

false

d)

true

36.

Which of the following is a valid way to declare a constructor in Java?

a)

public void MyClass() {}

b)

MyClass() public {}

c)

constructor MyClass() {}

d)

public MyClass() {}

37.

What is the purpose of the 'abstract' keyword in Java?

a)

To declare a class that cannot be instantiated

b)

To create a new thread

c)

To define a variable

d)

To declare a method

38.

Which of the following is a valid way to declare a package in Java?

a)

package myPackage;

b)

myPackage: package;

c)

myPackage package;

d)

package: myPackage;

39.

What is the output of the following code: System.out.println(10 > 5);?

a)

10

b)

Error

c)

false

d)

true

40.

Which of the following is a valid way to declare a method that returns a value in Java?

a)

int myMethod() void {}

b)

void myMethod() int {}

c)

public int myMethod() {}

d)

myMethod() public int {}

41.

What is the purpose of the 'interface' keyword in Java?

a)

To define a contract for classes

b)

To create a new thread

c)

To declare a variable

d)

To define a method

42.

Which of the following is a valid way to declare a final variable in Java?

a)

int x = final 10;

b)

final int x = 10;

c)

const int x = 10;

d)

int final x = 10;

43.

What is the output of the following code: System.out.println(5 + 3 * 2);?

a)

11

b)

8

c)

16

d)

10

44.

Which of the following is a valid way to declare a method with parameters in Java?

a)

myMethod(int x) public void {}

b)

void myMethod(int x) public {}

c)

public myMethod(int x) void {}

d)

public void myMethod(int x) {}

45.

What is the purpose of the 'native' keyword in Java?

a)

To define a method

b)

To declare a variable

c)

To create a new thread

d)

To indicate that a method is implemented in native code

46.

Which of the following is a valid way to declare a synchronized method in Java?

a)

public myMethod() synchronized {}

b)

synchronized public void myMethod() {}

c)

public synchronized void myMethod() {}

d)

myMethod() synchronized public {}

47.

What is the output of the following code: System.out.println(5 != 5);?

a)

5

b)

false

c)

true

d)

Error

48.

Which of the following is a valid way to declare a method that takes no parameters in Java?

a)

public myMethod() void {}

b)

public void myMethod() {}

c)

void myMethod() public {}

d)

myMethod() public void {}

49.

What is the purpose of the 'strictfp' keyword in Java?

a)

To restrict floating-point calculations to ensure portability

b)

To create a new thread

c)

To declare a variable

d)

To define a method

50.

Which of the following is a valid way to declare a method that throws an exception in Java?

a)

void myMethod() throws Exception public {}

b)

public myMethod() void throws Exception {}

c)

myMethod() public void throws Exception {}

d)

public void myMethod() throws Exception {}

51.

What is the output of the following code: System.out.println(5 & 3);?

a)

5

b)

3

c)

1

d)

0

52.

Which of the following is a valid way to declare a method that is abstract in Java?

a)

myMethod() abstract public;

b)

public myMethod() abstract;

c)

abstract public void myMethod();

d)

public abstract void myMethod();

53.

What is the purpose of the 'transient' keyword in Java?

a)

To define a method

b)

To create a new thread

c)

To declare a variable

d)

To indicate that a field should not be serialized

54.

Which of the following is a valid way to declare a method that is final in Java?

a)

public myMethod() final {}

b)

public final void myMethod() {}

c)

final public void myMethod() {}

d)

myMethod() final public {}

55.

What is the output of the following code: System.out.println(5 | 3);?

a)

5

b)

7

c)

3

d)

1

56.

Which of the following is a valid way to declare a method that is synchronized in Java?

a)

public synchronized void myMethod() {}

b)

synchronized public void myMethod() {}

c)

public myMethod() synchronized {}

d)

myMethod() synchronized public {}

57.

What is the purpose of the 'default' keyword in Java?

a)

To specify a default case in a switch statement

b)

To define a method

c)

To declare a variable

d)

To create a new thread

58.

Which of the following is a valid way to declare a method that is native in Java?

a)

public native void myMethod();

b)

native public void myMethod();

c)

public myMethod() native;

d)

myMethod() native public;

59.

What is the output of the following code: System.out.println(5 ^ 3);?

a)

6

b)

5

c)

3

d)

1

60.

Which of the following is a valid way to declare a method that is strictfp in Java?

a)

public myMethod() strictfp;

b)

myMethod() strictfp public;

c)

strictfp public void myMethod();

d)

public strictfp void myMethod();