WorksheetsJava Programming Quiz
Total questions: 60
Worksheet time: 30mins
What is Java primarily known as?
A high-level programming language
A low-level programming language
A web server
A database management system
Who is known as the father of Java?
James Gosling
Bjarne Stroustrup
Dennis Ritchie
Guido van Rossum
What does JRE stand for?
Java Runtime Execution
Java Resource Environment
Java Runtime Environment
Java Resource Execution
Which of the following is NOT a feature of Java?
Low-level
Dynamic
Robust
Object-Oriented
What is the purpose of the Java Virtual Machine (JVM)?
To execute Java bytecode
To compile Java code
To manage memory
To provide a graphical interface
Which keyword is used to define a class in Java?
class
define
object
new
What is the default value of a boolean variable in Java?
1
true
false
0
Which of the following is a primitive data type in Java?
String
ArrayList
int
HashMap
What does the 'static' keyword indicate in Java?
The method is private
The method is abstract
The method can be overridden
The method belongs to the class rather than instances
Which of the following is used for exception handling in Java?
try-catch
if-else
for-loop
switch-case
What is the output of the following code: System.out.println(5 + 3);?
5 + 3
Error
53
8
Which of the following is a valid declaration of a String in Java?
String str = 'Hello';
String str = "Hello";
String str = 'H' + 'e' + 'l' + 'l' + 'o';
String str = Hello;
What is the purpose of the 'main' method in Java?
To start the execution of a program
To define a class
To handle exceptions
To declare variables
Which of the following is NOT a control statement in Java?
if
for
while
define
What is the result of 10 % 3 in Java?
10
0
1
3
Which of the following is used to create an object in Java?
new
create
init
object
What is the purpose of the 'break' statement in Java?
To exit a loop
To continue to the next iteration
To define a method
To declare a variable
Which of the following is a valid way to declare an array in Java?
int arr[5];
int[] arr = int[5];
int arr = new int[5];
int arr[] = new int[5];
What is the output of the following code: System.out.println(3 + 4 + '5');?
Error
34
12
75
Which of the following is a valid comment in Java?
# This is a comment
<-- This is a comment -->
/* This is a comment
// This is a comment
What is the purpose of the 'return' statement in a method?
To create an object
To declare a variable
To return a value to the caller
To exit the method
Which of the following is a valid way to handle exceptions in Java?
try-catch
if-else
switch-case
for-loop
What is the default value of an integer variable in Java?
0
1
null
undefined
Which of the following is a method to convert a string to an integer in Java?
convert()
intValue()
toInt()
parseInt()
What is the purpose of the 'this' keyword in Java?
To refer to the current object
To create a new object
To call a method
To define a class
Which of the following is a valid way to declare a method in Java?
public myMethod() void {}
public void myMethod() {}
void myMethod() public {}
myMethod() public void {}
What is the output of the following code: System.out.println(10 / 3);?
3
3.33
Error
3.0
Which of the following is a valid way to create a new thread in Java?
new Thread()
create Thread()
Thread.new()
start Thread()
What is the purpose of the 'synchronized' keyword in Java?
To define a method
To declare a variable
To create a new thread
To prevent thread interference
Which of the following is a valid way to declare a constant in Java?
int x = final 10;
const int x = 10;
final int x = 10;
int const x = 10;
What is the output of the following code: System.out.println('A' + 1);?
66
B
A1
Error
Which of the following is a valid way to declare a multi-dimensional array in Java?
int arr = new int[3][3];
int arr[3][3];
int arr[][] = new int[3][3];
int[][] arr = new int[3][3];
What is the purpose of the 'volatile' keyword in Java?
To define a method
To declare a variable
To create a new thread
To indicate that a variable may be changed unexpectedly
Which of the following is a valid way to declare an interface in Java?
interface MyInterface {}
MyInterface {}
MyInterface interface {}
interface MyInterface() {}
What is the output of the following code: System.out.println(5 == 5);?
5
Error
false
true
Which of the following is a valid way to declare a constructor in Java?
public void MyClass() {}
MyClass() public {}
constructor MyClass() {}
public MyClass() {}
What is the purpose of the 'abstract' keyword in Java?
To declare a class that cannot be instantiated
To create a new thread
To define a variable
To declare a method
Which of the following is a valid way to declare a package in Java?
package myPackage;
myPackage: package;
myPackage package;
package: myPackage;
What is the output of the following code: System.out.println(10 > 5);?
10
Error
false
true
Which of the following is a valid way to declare a method that returns a value in Java?
int myMethod() void {}
void myMethod() int {}
public int myMethod() {}
myMethod() public int {}
What is the purpose of the 'interface' keyword in Java?
To define a contract for classes
To create a new thread
To declare a variable
To define a method
Which of the following is a valid way to declare a final variable in Java?
int x = final 10;
final int x = 10;
const int x = 10;
int final x = 10;
What is the output of the following code: System.out.println(5 + 3 * 2);?
11
8
16
10
Which of the following is a valid way to declare a method with parameters in Java?
myMethod(int x) public void {}
void myMethod(int x) public {}
public myMethod(int x) void {}
public void myMethod(int x) {}
What is the purpose of the 'native' keyword in Java?
To define a method
To declare a variable
To create a new thread
To indicate that a method is implemented in native code
Which of the following is a valid way to declare a synchronized method in Java?
public myMethod() synchronized {}
synchronized public void myMethod() {}
public synchronized void myMethod() {}
myMethod() synchronized public {}
What is the output of the following code: System.out.println(5 != 5);?
5
false
true
Error
Which of the following is a valid way to declare a method that takes no parameters in Java?
public myMethod() void {}
public void myMethod() {}
void myMethod() public {}
myMethod() public void {}
What is the purpose of the 'strictfp' keyword in Java?
To restrict floating-point calculations to ensure portability
To create a new thread
To declare a variable
To define a method
Which of the following is a valid way to declare a method that throws an exception in Java?
void myMethod() throws Exception public {}
public myMethod() void throws Exception {}
myMethod() public void throws Exception {}
public void myMethod() throws Exception {}
What is the output of the following code: System.out.println(5 & 3);?
5
3
1
0
Which of the following is a valid way to declare a method that is abstract in Java?
myMethod() abstract public;
public myMethod() abstract;
abstract public void myMethod();
public abstract void myMethod();
What is the purpose of the 'transient' keyword in Java?
To define a method
To create a new thread
To declare a variable
To indicate that a field should not be serialized
Which of the following is a valid way to declare a method that is final in Java?
public myMethod() final {}
public final void myMethod() {}
final public void myMethod() {}
myMethod() final public {}
What is the output of the following code: System.out.println(5 | 3);?
5
7
3
1
Which of the following is a valid way to declare a method that is synchronized in Java?
public synchronized void myMethod() {}
synchronized public void myMethod() {}
public myMethod() synchronized {}
myMethod() synchronized public {}
What is the purpose of the 'default' keyword in Java?
To specify a default case in a switch statement
To define a method
To declare a variable
To create a new thread
Which of the following is a valid way to declare a method that is native in Java?
public native void myMethod();
native public void myMethod();
public myMethod() native;
myMethod() native public;
What is the output of the following code: System.out.println(5 ^ 3);?
6
5
3
1
Which of the following is a valid way to declare a method that is strictfp in Java?
public myMethod() strictfp;
myMethod() strictfp public;
strictfp public void myMethod();
public strictfp void myMethod();
