wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 5: IPS_Ch 01-04

Total questions: 48

Worksheet time: 26mins

Name
Class
Date
1.

Given an IntelliJ workspace without any projects, how can you create and run a simple 'Hello World' program?

a)

Use the command line to compile and run the file outside Eclipse

b)

Create a new Java project, add a package, create a class, and run the class

c)

Open a text editor and save a .java file in the workspace

d)

Install a new plugin for running Java applications

2.

If you are given source code for a Java class, what is the first step in running it in IntelliJ?

a)

Convert it into bytecode manually before importing

b)

Save the file to any folder on your computer

c)

Open IntelliJ and import or create a project for the code

d)

Double-click the file to execute it

3.

Which of the following is a key difference between Java, Python, and JavaScript?

a)

Java is interpreted, while Python and JavaScript are compiled

b)

Python is typically slower but easier to learn than Java

c)

JavaScript is strongly typed, unlike Java

d)

Java cannot be used on multiple platforms

4.

What role does the JVM play in running a Java program?

a)

It executes Java bytecode on any platform

b)

It stores compiled programs permanently

c)

It is used only for debugging Java applications

d)

It directly translates Java source code into machine code

5.

Java’s 'write once, run anywhere' principle is possible because:

a)

Source code is identical on every computer

b)

Bytecode can run on any JVM implementation

c)

Java uses the same compiler on all platforms

d)

Java applications never need recompilation

6.

What is one major benefit of using IntelliJ instead of a plain text editor?

a)

IntelliJ runs faster than any other IDE

b)

IntelliJ automatically writes code for you

c)

IntelliJ can only be used for Java

d)

IntelliJ has built-in compiling, debugging, and project management

7.

Why don’t you need to compile Java source code manually before running it in IntelliJ?

a)

IntelliJ runs the code as plain text

b)

IntelliJ automatically compiles the code in the background

c)

IntelliJ translates Java directly into machine code

d)

Java does not require compilation

8.

Java program does not run without below function

a)

main()

b)

system()

c)

void()

d)

user()

9.

Which IDE is known for its built-in compiling, debugging, and project management features?

a)

Atom

b)

Visual Studio Code

c)

NetBeans

d)

IntelliJ

10.

What is the primary purpose of Java bytecode?

a)

To be converted into Python code

b)

To be directly executed by the CPU

c)

To be used for web development

d)

To be interpreted by the JVM

11.

What is the function of the Java compiler?

a)

To execute Java programs directly

b)

To convert Java source code into bytecode

c)

To debug Java applications

d)

To convert Java source code into machine code

12.

Which of the following is not a Java IDE?

a)

NetBeans

b)

Eclipse

c)

Sublime Text

d)

IntelliJ IDEA

13.

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

a)

int

b)

String

c)

boolean

d)

double

14.

What is the default value of a Java `int` variable that is declared as a class member but not initialized?

a)

0

b)

null

c)

false

d)

undefined

15.

Which keyword is used to declare a constant variable in Java?

a)

static

b)

final

c)

const

d)

constant

16.

Which of the following is the correct syntax to declare a variable of type `double` in Java?

a)

double value;

b)

Double value;

c)

double = value;

d)

value double;

17.

Which primitive data type would you use to store a single Unicode character in Java?

a)

char

b)

byte

c)

String

d)

boolean

18.

Which of the following statements correctly casts an `int` variable named `num` to a `double` in Java?

a)

double num = (double) num;

b)

double num = double(num);

c)

double num = num.toDouble();

d)

double num = (int) num;

19.

Which of the following code snippets will result in a compilation error due to type incompatibility?

a)

int a = 5.5;

b)

double b = 5;

c)

char c = 'A';

d)

boolean d = true;

20.

What will be the output of the following code? ```java final int MAX = 100; MAX = 200; System.out.println(MAX); ```

a)

100

b)

200

c)

Compilation error

d)

0

21.

Given the following code, what will be printed? ```java int a = 5; double b = a / 2; System.out.println(b); ```

a)

2.5

b)

2.0

c)

2

d)

2.00

22.

Consider the following code: ```java public class Test { public static void main(String[] args) { int x = 10; { int x = 20; System.out.println(x); } System.out.println(x); } } ``` What will happen when you try to compile and run this code?

a)

It prints 20 and then 10

b)

It prints 10 and then 20

c)

Compilation error due to variable redeclaration

d)

It prints 20 twice

23.

Suppose you want to declare a constant for the value of π\pi in Java. Which of the following is the best way to do it?

a)

final double pi = 3.14159;

b)

double pi = 3.14159;

c)

const double pi = 3.14159;

d)

static double pi = 3.14159;

24.

What is the value stored in x?

double x = (int) (1.8 * 2.0)

a)

3.0

b)

3

c)

3.6

d)

Error

25.

What is the resulting value of

(int)23.5

a)

24

b)

23

c)

23.5

d)

trick question, it's an error

26.

Match the following

a)
int
1.

5

b)

double

2.

5.2

c)
char
3.

'a'

d)
String
4.

"abc"

e)
boolean
5.

true

27.

Which of the following is NOT a numeric data type

a)

int

b)

double

c)

float

d)

decimal

28.
Which type is incorrect?
a)
int
b)
double
c)
float
d)
array
29.

What is the correct syntax for a simple if statement in Java?

a)

if condition { }

b)

if (condition) { }

c)

if [condition] { }

d)

if: (condition) { }

30.

Which of the following is a valid comparison operator in Java?

a)

:=

b)

==

c)

=

d)

!==

31.

Which logical operator represents "AND" in Java?

a)

&&

b)

||

c)

!

d)

&

32.

What is the output of the following code? ```java int x = 5; if (x > 3) { System.out.print("A"); } ```

a)

No output

b)

A

c)

5

d)

Error

33.

Which of the following is the correct way to write an if-else statement in Java?

a)

if (condition) { } else { }

b)

if condition then { } else { }

c)

if (condition) else { }

d)

if { } else (condition) { }

34.

Given the code: ```java int a = 10, b = 20; if (a < b && b > 15) { System.out.print("True"); } ``` What will be printed?

a)

True

b)

False

c)

10

d)

20

35.

Which of the following statements will evaluate to true if x=7x = 7 ?

a)

if (x == 8)

b)

if (x > 10)

c)

if (x <= 7)

d)

if (x != 7)

36.

What is the output of the following code? ```java int y = 4; if (y % 2 == 0) { System.out.print("Even"); } else { System.out.print("Odd"); } ```

a)

Even

b)

Odd

c)

4

d)

No output

37.

Which of the following best describes a nested if statement?

a)

An if statement inside a loop

b)

An if statement inside another if statement

c)

An if statement with multiple conditions

d)

An if statement with an else block

38.

Given the code: ```java int score = 85; if (score >= 90) { System.out.print("A"); } else if (score >= 80) { System.out.print("B"); } else { System.out.print("C"); } ``` What will be printed?

a)

A

b)

B

c)

C

d)

No output

39.

Which of the following conditions will be true if a=5a = 5 and b=10b = 10 ?

a)

(a > b) && (b > 0)

b)

(a < b) || (b < 0)

c)

(a == b) && (a > 0)

d)

(a > 0) && (b < 0)

40.

What will be the output of the following code? ```java int n = 3; if (n > 0) { if (n < 5) { System.out.print("Small"); } } ```

a)

Small

b)

3

c)

No output

d)

Error

41.

Given the code: ```java int x = 8; if (x % 2 == 0) { if (x > 5) { System.out.print("A"); } else { System.out.print("B"); } } else { System.out.print("C"); } ``` What will be printed?

a)

A

b)

B

c)

C

d)

No output

42.

You want to check if a number is both positive and even in Java. Which condition should you use?

a)

if (num > 0 || num % 2 == 0)

b)

if (num > 0 && num % 2 == 0)

c)

if (num < 0 && num % 2 == 0)

d)

if (num > 0 && num % 2 != 0)

43.

What will be the output of the following code? ```java int a = 6, b = 3; if (a > b) { if (a % b == 0) { System.out.print("Divisible"); } else { System.out.print("Not Divisible"); } } else { System.out.print("Invalid"); } ```

a)

Divisible

b)

Not Divisible

c)

Invalid

d)

No output

44.

Which of the following code snippets will print "Yes" only if xx is greater than 10 and yy is less than 5?

a)

if (x > 10 || y < 5) { System.out.print("Yes"); }

b)

if (x > 10 && y < 5) { System.out.print("Yes"); }

c)

if (x >= 10 && y <= 5) { System.out.print("Yes"); }

d)

if (x < 10 && y > 5) { System.out.print("Yes"); }

45.

Given the code: ```java int num = -2; if (num > 0) { System.out.print("Positive"); } else if (num < 0) { System.out.print("Negative"); } else { System.out.print("Zero"); } ``` What will be printed?

a)

Positive

b)

Negative

c)

Zero

d)

No output

46.

Which of the following best explains the use of logical operators in if statements?

a)

They allow combining multiple conditions in a single if statement.

b)

They are used to declare variables.

c)

They are used to print output.

d)

They are used to define classes.

47.

Given the code: ```java int x = 4, y = 7; if (x < y) { if (x + y > 10) { System.out.print("Sum is large"); } else { System.out.print("Sum is small"); } } else { System.out.print("x is not less than y"); } ``` What will be printed?

a)

Sum is large

b)

Sum is small

c)

x is not less than y

d)

No output

48.

Which of the following statements will print "Valid" only if aa is not equal to bb and both are positive?

a)

if (a != b && a > 0 && b > 0) { System.out.print("Valid"); }

b)

if (a == b && a > 0 && b > 0) { System.out.print("Valid"); }

c)

if (a != b || a > 0 || b > 0) { System.out.print("Valid"); }

d)

if (a != b && (a > 0 || b > 0)) { System.out.print("Valid"); }