NEW
Font size
WorksheetsQ2 CT G1
Total questions: 47
Worksheet time: 49mins
Who is widely recognized as the “father of Java”?
Bill Gates
James Gosling
Steve Jobs
Dennis Ritchie
What was Java originally designed for?
Desktop applications
Mobile games
Interactive television
Banking systems
The principle “Write Once, Run Anywhere” (WORA) is made possible by:
Source code
Bytecode and JVM
IDEs like NetBeans
Application servers
Which of the following is NOT a feature of Java?
Platform independence
Pointers for direct memory access
Multithreading support
Object-orientation
JDK1 was officially released in:
1989
1991
1996
1999
How did Java contribute to the rise of Object-Oriented Programming (OOP)?
By replacing C++ in teaching programming
By eliminating OOP features completely
By using only procedural programming
By creating new hardware for OOP
Which of the following best explains Java’s portability?
Java runs only on Windows and Linux.
Java code is compiled into machine code directly.
Java uses only one type of compiler for all platforms.
Java bytecode can run on any JVM regardless of OS.
Java is still widely used today in areas such as banking, healthcare, and e-commerce. Which TWO features best explain this continuing relevance?
Platform independence and security
Operator overloading and pointers
Simple syntax and lack of garbage collection
Proprietary frameworks only
What does JDK stand for?
Java Development Kernel
Java Development Kit
Java Deployment Kit
Java Data Knowledge
The JDT is specifically associated with which IDE?
NetBeans
IntelliJ IDEA
Eclipse
Visual Studio
What feature of an IDE helps detect errors while coding?
Syntax highlighting
Garbage collection
Sandbox security
Operator overloading
Which operator is used to find the remainder of a division in Java?
/
//
*
%
What is the result of 10 / 3 in Java (using int)?
3.33
3
4
0
Which relational operator returns true if two values are equal?
!
==
<=
=
What is the output of (5 > 3) && (8 > 6)?
TRUE
FALSE
8
5
Which operator increments a variable by 1?
++
--
+=2
**
Which of the following is the correct way to declare a class in Java?
public class HelloWorld { }
public HelloWorld class { }
Public class HelloWorld { }
public class: HelloWorld { }
What is the correct signature of the main method in Java?
public void main(String args)
public static void main{String[] args}
static public void main(String args[])
public static void main(String[] args)
Every Java statement ends with:
. (period)
: (colon)
; (semicolon)
, (comma)
Which of the following is a reserved keyword in Java?
function
class
variable
define
If a file is named HelloWorld.java, which of the following must be true?
The public class must be named HelloWorld.
The public class must be named Hello.
The class can be named anything.
There is no restriction on file names.
Which data type would you use to store the value 19.99 with maximum precision?
String
int
double
long
Which of the following variable declarations best follows Java naming conventions?
int StudentAge = 18;
int studentAge = 18;
int student_age = 18;
int studentage = 18;
You are asked to document your code for API reference. Which comment type is best used?
//
/*...*/
/**...**/
Which package must be imported to use the Scanner class?
java.io.Scanner;
java.util.Scanner;
java.lang.Scanner;
java.system.Scanner;
Which package contains the PrintStream class?
java.io
java.util
java.print
java.output
What is the purpose of the Scanner class in Java?
To write output to the console
To read input from sources like keyboard, files, or strings
To perform arithmetic operations
To manage file permissions
What does System.out.println("Hello"); do?
Prints "Hello" and keeps the cursor on the same line
Prints "Hello" and moves the cursor to the next line
Prints Hello twice
Prints Hello in bold
Which method of Scanner is used to read an integer input?
nextLine()
nextInteger()
nextInt()
getInt()
Which method of Scanner is used to read a String input?
nextline()
nextString()
getLine()
nextLine()
What is the difference between print() and println() in Java?
print() moves the cursor to the next line, println() does not
println() moves the cursor to the next line, print() does not
Both behave exactly the same
None of the above
Which statement correctly concatenates two strings for output?
System.out.println("Hello" + "World");
System.out.print("Hello", "World");
System.out.println("Hello" - "World");
System.out.concat("Hello", "World");
Which of the following is the simplest decision-making statement in Java?
if-else
switch
if
else-if
What will happen if the condition in an if statement evaluates to false?
The program will stop
The compiler shows an error
The code inside the if block is executed anyway
The code inside the if block is skipped
Which operator is used for comparison in Java?
=
::=
==
equals
What is the correct syntax of an if-else statement?
if (condition); { } else { }
if (condition) { } else { }
if condition { } else { }
if (condition) else { }
What is the main purpose of the else-if ladder?
To execute multiple blocks at once
To check a series of conditions in order
To replace loops
To avoid using switch
Which statement allows multiple selections in Java?
switch
if
if else
while
What will happen if a semicolon is placed after the condition in an if statement?
No effect
Causes compilation error
Ends the if statement early
Makes the program run faster
Which of the following data types can be used in a switch expression?
float
double
String
long
Which of the following conditions is not valid in an if statement?
a. a > b
b. x == y
c. 5
d. a != b
Suppose you mistakenly write if(a = 10) instead of if(a == 10). What will happen?
Runtime error
Prints "true"
It will check equality correctly
Compilation error because a = 10 is assignment
What is the output of this code? int age = 20; if(age >= 18) { System.out.println("Adult"); } else { System.out.println("Minor"); }
Minor
Adult
Error
Nothing
You want a program that prints "Pass" if the grade ≥ 75, otherwise "Fail". Which construct is most appropriate?
if-else
if-else ladder
switch
Nested if
A teacher wants to categorize scores:
• 90 and above: Excellent
• 75-89: Passed
• Below 75: Failed
Which control structure is most appropriate?
Simple if
if-else
if-else-if ladder
switch
What will be printed by this code?
int day = 2;
switch(day) {
case 1: System.out.println("Monday");
break;
case 2: System.out.println("Tuesday");
break;
case 3: System.out.println("Wednesday");
break;
default: System.out.println("Invalid day"); }
Monday
Tuesday
Wednesday
Invalid day
Consider this code:
int number = 0;
if(number > 0) {
System.out.println("Positive");
} else if(number < 0) {
System.out.println("Negative");
} else {
System.out.println("Zero");
}
What is the output after execution?
Positive
Negative
Zero
Error
