Font size
WorksheetsJava Programming Basics Quiz
Total questions: 50
Worksheet time: 40mins
What is the correct keyword to define a class in Java?
Class
public
class
ClassName
In Java, the filename must match the (a) .
Which of the following statements is true about Java keywords?
They are case-insensitive
They must start with a capital letter
They are written in lowercase
They must be enclosed in double quotes
In Java, curly braces {} are used to:
Initialize variables
Enclose code blocks
Add comments
End a line
Java is a __________ programming language.
case sensitive
case insensitive
What is the correct syntax to define the main method?
static public void Main()
public static void main(String[] args)
public void static main(String args[])
void main public static(String[] args)
Which method advances the cursor to the next line after displaying output?
System.out.print()
System.out.scan()
System.out.println()
System.out.display()
Which method keeps the output cursor on the same line?
System.out.cursor()
System.out.print()
System.out.nextLine()
System.out.println()
In Java, a string must be enclosed within (a) quotes.
Every Java statement must end with a:
comma(,)
period(.)
colon(:)
semicolon(;)
Identify 2 incorrect ways to print a string:
System.out.print("Hello");
System.out.println("Hello World!");
System.out.println(Hello);
system.out.println("Hello");
Which symbol is used for a single-line comment?
//
/**/
#
--
Which comment syntax allows multiple lines?
\ multi-line \
/* multi-line */
## multi-line ##
// multi-line \\
Choose the correctly commented line:
//This is a comment
\This is a comment\
-- This is a comment --
/** This is a comment /**
Which of the following are valid Java variable declaration?
double distance_4
int 2speed;
String $name;
final 5rate;
Which is the correct syntax to declare multiple int variables?
int width height length;
int width, height, length;
int(width, height, length);
int width: height: length;
When declaring a variable, what must come first?
variable name
value
data type
method
What is the data type for storing text in Java?
text
character
String
word
Which variable name is invalid in Java?
$price
_height
3score
totalAmount
Which statement initializes an integer variable named hours with value 40?
hours = 40 int;
int 40 = hours;
int hours = 40;
int hours 40;
Create a variable named myClass and save the value "Computer Lab":
(a)
In Java, MyAge and myAge are:
The same
Different
Both invalid
Compiled together
In Java, My-name and my=name are:
The same
Different
Both invalid
Compiled together
Which keyword is used to create a constant in Java?
static
const
final
private
Which of the following is a valid constant declaration?
final double MY_RATE = 0.2;
double FINAL_RATE = 0.2;
constant double RATE;
final RATE = 0.2 double;
Constant variable names are written in:
camelCase
PascalCase
all lowercase
all uppercase
The + operator when used with strings in Java:
adds numbers
concatenates strings
multiplies strings
divides strings
System.out.println("Java" + "Programming"); will output:
JavaProgramming
Java Programming
Java+Programming
Java, Programming
Which expression will correctly combine the value of int age = 20; with text?
System.out.println("Age" + age);
System.out.println("Age", age);
System.out.print("Age" * age);
System.out.print("Age" && age);
Which class must you import to use Scanner in Java?
java.input.Scanner
java.util.Scanner
scanner.util.java
import.scanner.java
What does keyboard.nextInt() do?
Reads a String input
Reads an integer input
Creates an integer variable
Scans the next character
Which method reads a double input using Scanner?
nextDouble()
scanDouble()
readDouble()
doubleInput()
Which method is used to read a full line of text input?
keyboard.readLine()
keyboard.inputString()
keyboard.nextLine()
scanner.getText()
To create a Scanner object, use: Scanner keyboard = new __________;
In Java, a block of code must be enclosed in (a) .
Each Java file can have:
multiple classes, but only one public class
multiple public classes
one class only
no classes
Which keyword is NOT part of the main method header?
public
void
main
private
The main method's name must always be written as __________.
When using Scanner, to avoid input mismatch errors, always:
input numbers in quotes
type matching input types
avoid using the import statement
input blank lines
What is the output of: System.out.print("Java"); System.out.println("Rocks");
Java Rocks
JavaRocks
Java Rocks
RocksJava
Choose the correct code to display: Welcome to Java! on the screen.
System.out.println(Welcome to Java!);
System.out.print("Welcome to Java!");
System.print("Welcome to Java!");
System.out.println("Welcome to Java!");
What is the result of: System.out.println(2 + 2);
22
4
"4"
2 + 2
Choose the correct way to create a Scanner object.
Scanner = new Scanner(System.in);
new Scanner(System.in);
Scanner input = new Scanner(System.in);
Scanner input = Scanner(System.in);
What is the correct way to import the Scanner class?
import scanner.util;
import java.util.Scanner;
java.util.Scanner.import;
import java.input.Scanner;
Which of the following will correctly declare and initialize a String variable?
String name = 'John';
String name = "John";
name String = "John";
String = "John" name;
Using + between a string and an integer automatically __________ the integer to a string.
What happens if you forget the semicolon after a Java statement?
Nothing
Syntax error
Logical error
Runtime error
Which option is a correct block comment?
// Block comment /* /
/ Block comment */
// Block comment //
*/ Block comment /
In Java, a class name usually starts with:
lowercase letter
uppercase letter
number
symbol
Name one company that mainly code using Java:
