Font size
WorksheetsJava Easy
Total questions: 40
Worksheet time: 20mins
Which data type is used if you want to store the value "Welcome"?
Text
Characters
String
Boolean
Which data type is used to represent the value True?
float
boolean
Array
ٍString
Which is the correct statement for output in Java?
system.out.print();
System.out.println();
System.Out.Printf();
System.out.show();
Which is the correct way to define a String variable?
String name = "John";
String name = "John"
String name = John;
String name "John";
Which statement about choosing variable names is FALSE?
Variable names can contain letters, digits, underscores, and dollar signs.
Variable names are NOT case sensitive
Reserved words (like Java keywords, such as int or String) cannot be used as variable names
Variable names can also begin with $ and _
Which of the following is a reference data type?
byte
Array
char
boolean
Which of the following is the correct way of defining a char variable?
char myGrade = 'B';
char myGrade = "B";
char myGrade 'B';
char myGrade = 'B'
x /= 3
Which of the following statements will produce the exact same results as the statement above?
x = 3 / x
x = x / 3
x / 3
x /x = 3
What is the output of the code below?
int x = 5;
System.out.println(x++);
System.out.println(x);
5
5
6
6
5
6
6
5
Which of these commands has errors? Select multiple
System.out.print("Hello World")
System.out.print(Hello World);
System.out.Print("Hello World);
System.out.print("Hello World");
A data type which is typical in form and make use of digits and a decimal point
integer
double
char
boolean
True or False : Java is case sensitive, which means identifier Hello and hello would have different meaning in Java
True
False
A Java statement is one or more lines of code terminated by a semicolon. True or False?
False
True
A Java block is formed by enclosing statements by open and close parentheses. True or False?
True
False
Indentation plays an important role in Python. What about indentation in Java?
It plays the same role
It causes an error
Indentation is used for readability purposes only. Adding extra space at the beginning of lines of java code would not cause an error.
It cannot be determined
What is the ‘\n’ in the following code called?
System.out.println(" Hello \n world!");
newline character
tab character
jump line
no line character
What are \n \t all examples of?
keywords
escape sequence
functions
none of the mentioned
Which statement is used to exit a LOOP in Java?
Which statement is used to skip the current iteration of a loop in Java and start back at the top?
Which of the following lines of code will throw an error?
String hello = "hello";
char letter = 'A';
String name = 'Montse';
int num = 15;
Which of the following lines of code will throw an error?
String name = "Ana";
double price = 10.99
int age = 22;
char grade = 'B';
What is the correct boolean statement for the writing the logic of the following statement:
I buy pizza if it is cheap and I am hungry.
boolean buyPizza = isCheap && amHungry;
boolean buyPizza = !isCheap && amHungry;
boolean buyPizza = isCheap || amHungry;
boolean buyPizza = isCheap || !amHungry;
What is the best variable type for storing a single letter grade of an exam? (Without a + or -, just the letter)
char
String
int
double
What is the correct way to write the code for the following statement:
I will buy coffee if I am tired or it is not expensive.
boolean buyCoffee = amTired && !expensive;
boolean buyCoffee = amTired || !expensive;
boolean buyCoffee = !amTired || expensive;
boolean buyCoffee = !amTired || !expensive;
Which of the following lines of code contains an error?
float number = 10.00f;
int number = 10;
long number = 10.00f;
String number = "10";
What is the purpose of the 'main' method in Java?
It is the entry point of the program
It declares variables
It creates objects
It imports external libraries
What does the 'import' keyword do in Java?
It defines the main method
It creates objects
It declares variables
It imports external libraries
What is the purpose of the 'import java.util.Scanner;' statement in the given code?
To define the main method
To read input from a file
To bring in the Scanner class from the java.util library
To create a new Scanner object
What is the default value of a String variable in Java?
void
null
0
undefined
int z=1.5;
What will be the value of z?
z=1.5
run time error
compilation error
z=1.15
This loop will output
0
1
2
3
4
5
6
7
8
9
10
1 10
x
0 1 2 3 4 5 6 7 8 9 10
What will be the output for the following?
int num=15;
System.out.println(2*num++);
System.out.println(num);
15
16
30
16
16
17
32
16
What would be the output for the following:
System.out.println(20/3);
6.66666666667
6.7
7
6
What would be the output for the following:
int num = 5;
do{
System.out.println(++num);
while (num<10);
6
7
8
9
10
6
7
8
9
5
6
7
8
9
10
5
6
7
8
9
