Font size
WorksheetsQuiz 5: IPS_Ch 01-04
Total questions: 48
Worksheet time: 26mins
Given an IntelliJ workspace without any projects, how can you create and run a simple 'Hello World' program?
Use the command line to compile and run the file outside Eclipse
Create a new Java project, add a package, create a class, and run the class
Open a text editor and save a .java file in the workspace
Install a new plugin for running Java applications
If you are given source code for a Java class, what is the first step in running it in IntelliJ?
Convert it into bytecode manually before importing
Save the file to any folder on your computer
Open IntelliJ and import or create a project for the code
Double-click the file to execute it
Which of the following is a key difference between Java, Python, and JavaScript?
Java is interpreted, while Python and JavaScript are compiled
Python is typically slower but easier to learn than Java
JavaScript is strongly typed, unlike Java
Java cannot be used on multiple platforms
What role does the JVM play in running a Java program?
It executes Java bytecode on any platform
It stores compiled programs permanently
It is used only for debugging Java applications
It directly translates Java source code into machine code
Java’s 'write once, run anywhere' principle is possible because:
Source code is identical on every computer
Bytecode can run on any JVM implementation
Java uses the same compiler on all platforms
Java applications never need recompilation
What is one major benefit of using IntelliJ instead of a plain text editor?
IntelliJ runs faster than any other IDE
IntelliJ automatically writes code for you
IntelliJ can only be used for Java
IntelliJ has built-in compiling, debugging, and project management
Why don’t you need to compile Java source code manually before running it in IntelliJ?
IntelliJ runs the code as plain text
IntelliJ automatically compiles the code in the background
IntelliJ translates Java directly into machine code
Java does not require compilation
Java program does not run without below function
main()
system()
void()
user()
Which IDE is known for its built-in compiling, debugging, and project management features?
Atom
Visual Studio Code
NetBeans
IntelliJ
What is the primary purpose of Java bytecode?
To be converted into Python code
To be directly executed by the CPU
To be used for web development
To be interpreted by the JVM
What is the function of the Java compiler?
To execute Java programs directly
To convert Java source code into bytecode
To debug Java applications
To convert Java source code into machine code
Which of the following is not a Java IDE?
NetBeans
Eclipse
Sublime Text
IntelliJ IDEA
Which of the following is NOT a primitive data type in Java?
int
String
boolean
double
What is the default value of a Java `int` variable that is declared as a class member but not initialized?
0
null
false
undefined
Which keyword is used to declare a constant variable in Java?
static
final
const
constant
Which of the following is the correct syntax to declare a variable of type `double` in Java?
double value;
Double value;
double = value;
value double;
Which primitive data type would you use to store a single Unicode character in Java?
char
byte
String
boolean
Which of the following statements correctly casts an `int` variable named `num` to a `double` in Java?
double num = (double) num;
double num = double(num);
double num = num.toDouble();
double num = (int) num;
Which of the following code snippets will result in a compilation error due to type incompatibility?
int a = 5.5;
double b = 5;
char c = 'A';
boolean d = true;
What will be the output of the following code? ```java final int MAX = 100; MAX = 200; System.out.println(MAX); ```
100
200
Compilation error
0
Given the following code, what will be printed? ```java int a = 5; double b = a / 2; System.out.println(b); ```
2.5
2.0
2
2.00
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?
It prints 20 and then 10
It prints 10 and then 20
Compilation error due to variable redeclaration
It prints 20 twice
Suppose you want to declare a constant for the value of π in Java. Which of the following is the best way to do it?
final double pi = 3.14159;
double pi = 3.14159;
const double pi = 3.14159;
static double pi = 3.14159;
What is the value stored in x?
double x = (int) (1.8 * 2.0)
3.0
3
3.6
Error
What is the resulting value of
(int)23.5
24
23
23.5
trick question, it's an error
Match the following
5
double
5.2
'a'
"abc"
true
Which of the following is NOT a numeric data type
int
double
float
decimal
What is the correct syntax for a simple if statement in Java?
if condition { }
if (condition) { }
if [condition] { }
if: (condition) { }
Which of the following is a valid comparison operator in Java?
:=
==
=
!==
Which logical operator represents "AND" in Java?
&&
||
!
&
What is the output of the following code? ```java int x = 5; if (x > 3) { System.out.print("A"); } ```
No output
A
5
Error
Which of the following is the correct way to write an if-else statement in Java?
if (condition) { } else { }
if condition then { } else { }
if (condition) else { }
if { } else (condition) { }
Given the code: ```java int a = 10, b = 20; if (a < b && b > 15) { System.out.print("True"); } ``` What will be printed?
True
False
10
20
Which of the following statements will evaluate to true if x=7 ?
if (x == 8)
if (x > 10)
if (x <= 7)
if (x != 7)
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"); } ```
Even
Odd
4
No output
Which of the following best describes a nested if statement?
An if statement inside a loop
An if statement inside another if statement
An if statement with multiple conditions
An if statement with an else block
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
B
C
No output
Which of the following conditions will be true if a=5 and b=10 ?
(a > b) && (b > 0)
(a < b) || (b < 0)
(a == b) && (a > 0)
(a > 0) && (b < 0)
What will be the output of the following code? ```java int n = 3; if (n > 0) { if (n < 5) { System.out.print("Small"); } } ```
Small
3
No output
Error
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
B
C
No output
You want to check if a number is both positive and even in Java. Which condition should you use?
if (num > 0 || num % 2 == 0)
if (num > 0 && num % 2 == 0)
if (num < 0 && num % 2 == 0)
if (num > 0 && num % 2 != 0)
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"); } ```
Divisible
Not Divisible
Invalid
No output
Which of the following code snippets will print "Yes" only if x is greater than 10 and y is less than 5?
if (x > 10 || y < 5) { System.out.print("Yes"); }
if (x > 10 && y < 5) { System.out.print("Yes"); }
if (x >= 10 && y <= 5) { System.out.print("Yes"); }
if (x < 10 && y > 5) { System.out.print("Yes"); }
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?
Positive
Negative
Zero
No output
Which of the following best explains the use of logical operators in if statements?
They allow combining multiple conditions in a single if statement.
They are used to declare variables.
They are used to print output.
They are used to define classes.
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?
Sum is large
Sum is small
x is not less than y
No output
Which of the following statements will print "Valid" only if a is not equal to b and both are positive?
if (a != b && a > 0 && b > 0) { System.out.print("Valid"); }
if (a == b && a > 0 && b > 0) { System.out.print("Valid"); }
if (a != b || a > 0 || b > 0) { System.out.print("Valid"); }
if (a != b && (a > 0 || b > 0)) { System.out.print("Valid"); }
