WorksheetsQuiz
Total questions: 46
Worksheet time: 23mins
Java is case-sensitive. Choose the correct statement.
Java treats 'A' and 'a' as the same.
Java treats 'A' and 'a' as different.
In Java, class names should start with an uppercase letter. Pick the correct option.
uppercase letter
lowercase letter
any symbol
In Java, method names should start with a lowercase letter. Which choice is correct?
lowercase letter
uppercase letter
a number
When a class is public, the filename must match the class name. Select the correct statement.
The filename can be any name.
The filename must match the public class name.
The filename must be in all lowercase.
Every Java statement must end with a semicolon. Choose the correct punctuation that should appear at the end.
comma ,
semicolon ;
colon :
How many primitive data types does Java have?
six
seven
eight
nine
Choose the Java primitive type that stores true or false values.
int
boolean
char
double
Choose the Java primitive type that stores a single Unicode character.
char
boolean
long
float
Which pair lists Java floating-point types?
int and short
float and double
byte and long
char and boolean
In the PrimitiveTypes example, variables are declared with a type followed by a name. Select the declaration that matches this pattern.
byte myByte = 127;
127 = byte myByte;
myByte byte = 127;
Variables are containers for storing data values. Choose the statement that matches this idea.
Variables are pictures in a program.
Variables hold data values like numbers or text.
Variables are only for printing messages.
Select the Java syntax pattern for declaring a variable before using it.
value = type name;
type variableName = value;
name = value type;
Which keyword is used in Java to declare a constant whose value cannot change?
static
final
class
return
Which category includes operators like +, -, *, /, %?
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Which category includes operators like ==, !=, >, <, >=, <=?
Assignment Operators
Relational Operators
Increment and Decrement Operators
Logical Operators
Which category includes operators like &&, ||, ! ?
Logical Operators
Bitwise Operators
Arithmetic Operators
Assignment Operators
Which category includes operators like ++ and -- ?
Increment and Decrement Operators
Arithmetic Operators
Relational Operators
Bitwise Operators
Which category includes operators like =, +=, -=, *=, /=, %= ?
Assignment Operators
Logical Operators
Arithmetic Operators
Relational Operators
Which category includes operators like ?
Bitwise Operators
Logical Operators
Arithmetic Operators
Relational Operators
In the OperatorsExample code, a and b are integers. Choose the expression that prints their sum.
System.out.println("a + b = " + (a + b));
System.out.println("a - b = " + (a - b));
System.out.println("a * b = " + (a * b));
Basic Calculator: Create a program that takes two numbers and an operator (+, -, *, /) as input, and performs the corresponding operation. What should the program take as input?
Two numbers and one operator
Two operators only
One number only
A temperature and its scale
Temperature Converter: Write a program that converts temperatures between Celsius and Fahrenheit. The program should ask the user for the source scale (C or F), then the temperature, and output the converted temperature. What is the first thing the program should ask the user?
The source scale (C or F)
The destination city
The interest rate
The number of operators
Simple Interest Calculator: Develop a program that calculates simple interest. It should take the principal amount, rate of interest (in percentage), and period (in years) as input, and output the interest amount. Which set of inputs should the program collect?
Principal amount, rate of interest, and period in years
Temperature and source scale
Two numbers and an operator
Username and password
Array Reversal: Which array is the reverse of [2, 4, 6]?
[6, 4, 2]
[2, 6, 4]
[4, 2, 6]
[2, 4, 6]
Unique Elements: After removing duplicate strings from ["apple", "banana", "apple", "banana"], which list shows only unique items?
["apple", "banana"]
["apple", "banana", "apple"]
["banana"]
["apple", "banana", "banana"]
Word Frequency Counter: A text file says "cat dog cat bird cat." Which word appears most often?
cat
dog
bird
fish
Generic Stack: In a stack, which operation removes the top item?
push
pop
peek
add
Custom Iterator: For a circular buffer, what should the iterator do when it reaches the end?
Stop and return nothing more
Wrap around to the beginning
Delete the buffer
Jump to the middle
ArrayList exercise: Which step creates an ArrayList of strings named URColleges?
Create an ArrayList of strings and call it URColleges.
Store in the created list all the colleges of the University of Rwanda.
Display all the colleges in the list.
Remove any one of the colleges.
ArrayList exercise: Which step adds the colleges of the University of Rwanda to the URColleges list?
Store in the created list all the colleges of the University of Rwanda.
Create an ArrayList of strings and call it URColleges.
Display all the colleges in the list.
Remove any one of the colleges.
ArrayList exercise: Which step shows every college currently in the URColleges list?
Display all the colleges in the list.
Remove any one of the colleges.
Create an ArrayList of strings and call it URColleges.
Display the number of remaining colleges.
ArrayList exercise: Which step takes one college out of the URColleges list?
Remove any one of the colleges.
Display all the colleges in the list.
Store in the created list all the colleges of the University of Rwanda.
Display the number of remaining colleges.
ArrayList exercise: Which step shows how many colleges remain in the URColleges list after changes?
Display the number of remaining colleges.
Create an ArrayList of strings and call it URColleges.
Remove any one of the colleges.
Store in the created list all the colleges of the University of Rwanda.
HashMap exercise: Which step creates a HashMap object named carDetails to store car information?
Create a HashMap object named carDetails that should store the details of a car.
Add the name of the owner of the car to the carDetails object.
Add the year of manufacturing of the car.
Remove the year of manufacturing that you stored.
HashMap exercise: Which step adds the car owner's name into carDetails?
Add the name of the owner of the car to the carDetails object.
Create a HashMap object named carDetails that should store the details of a car.
Add the year of manufacturing of the car.
Remove the year of manufacturing that you stored.
HashMap exercise: Which step stores the car's manufacturing year in carDetails?
Add the year of manufacturing of the car (any year of your choice).
Add the name of the owner of the car to the carDetails object.
Create a HashMap object named carDetails that should store the details of a car.
Remove the year of manufacturing that you stored.
HashMap exercise: Which step gets the owner name from carDetails and saves it in a String variable named carOwner?
Get the name of the owner that you stored and store it in the String variable carOwner.
Create a HashMap object named carDetails that should store the details of a car.
Add the year of manufacturing of the car.
Remove the year of manufacturing that you stored.
HashMap exercise: Which step deletes the manufacturing year from carDetails?
Remove the year of manufacturing that you stored.
Add the year of manufacturing of the car.
Add the name of the owner of the car to the carDetails object.
Create a HashMap object named carDetails that should store the details of a car.
Look at the code. What is the abstract base class name?
Shape
Circle
Rectangle
Resizable
In the Circle class shown, which method is overridden?
getPerimeter
getArea
displayInfo
resize
According to the Circle class code, which formula is used to return the perimeter of a circle?
radius + radius
2 * Math.PI * radius
Math.PI * radius * radius
width + height
In the Rectangle class code, which expression is used to compute area?
width + height
width * height
2 * (width + height)
Math.PI * radius * radius
What kind of type is Resizable in the code?
A class
An interface
An enum
A package
According to the Square class header, what does Square extend?
Shape
Rectangle
Circle
Main
In the Main class code, which object is resized with factor 1.5?
circle
rectangle
square
shape
Which concept from the list is shown by Circle and Rectangle extending Shape?
Polymorphism
Inheritance
Interfaces
Method overriding
