NEW
Font size
WorksheetsJava Basics: Data Types and Operators
Total questions: 20
Worksheet time: 10mins
What is the size of an int data type in Java?
2 bytes
8 bytes
16 bytes
4 bytes
Which of the following is not a primitive data type in Java?
Integer
Boolean
String
Float
What will be the output of the expression 5 + 10 * 2?
15
25
30
20
What is the result of the expression 10 > 5?
true
false
10 < 5
5 > 10
Which operator is used to compare two values for equality?
<>
<=
== or ===
!=
What will be the output of the following code: int a = 5; int b = 10; System.out.println(a + b);?
15
10
5
20
What is the result of the expression true && false?
true || false
false && true
false
true
Which of the following is a logical operator in Java?
==
&&, ||, !
<=
!=
What will be the output of the expression 15 % 4?
2
4
1
3
What is the default value of a boolean variable in Java?
false
1
null
true
What will happen if you try to divide an integer by zero in Java?
The result will be zero.
A NullPointerException is thrown.
An ArithmeticException is thrown.
The program will crash immediately.
What is the result of the expression 10 <= 10?
false
true
10 == 9
10 > 10
Which data type is used to store a single character in Java?
int
boolean
char
string
What will be the output of the following code: int x = 10; x += 5; System.out.println(x);?
15
20
10
5
What is the result of the expression !(true || false)?
!(false && true)
false || false
true
false
Which of the following is a valid declaration of a float variable in Java?
float myFloat = '5.0f';
float myFloat = 5.0F;
float myFloat = 5.0f;
float myFloat = 5.0;
What will be the output of the expression 3 * (4 + 5)?
15
20
27
12
What is the result of the expression 7 != 7?
false
true
7
falsehood
What will be the output of the following code: String str = "Hello"; System.out.println(str.length());?
6
4
5
Hello
What is the purpose of the try-catch block in Java?
To handle exceptions and prevent program crashes.
To optimize performance of the program.
To define variables in a method.
To improve code readability.
