Worksheetsjava basics
Total questions: 25
Worksheet time: 13mins
What is a correct syntax to output "Hello World" in Java?
echo("Hello World");
System.out.println("Hello World");
print("Hello World");
console.log("Hello World");
Java is short for "JavaScript".
True
False
How do you insert COMMENTS in Java code?
/* This is a comment
# This is a comment
// This is a comment
Which data type is used to create a variable that should store text?
String
myString
string
char
How do you create a variable with the numeric value 5?
num x = 5
float x = 5;
x = 5;
int x = 5;
How do you create a variable with the floating number 2.8?
byte x = 2.8f
x = 2.8f;
float x = 2.8f;
int x = 2.8f;
Which method can be used to find the length of a string?
len()
getSize()
length()
getLength()
Which operator is used to add together two values?
The * sign
The + sign
The & sign
The && sign
The value of a string variable can be surrounded by single quotes.
True
False
Which method can be used to return a string in upper case letters?
touppercase()
toUpperCase()
upperCase()
tuc()
Which operator can be used to compare two values?
><
=
==
<>
To declare an array in Java, define the variable type with:
()
[]
{}
<>
Array indexes start with:
null
0
1
How do you create a method in Java?
(methodName)
methodName()
methodName.
methodName[]
How do you call a method in Java?
methodName;
(methodName);
methodName[];
methodName();
Which keyword is used to create a class in Java?
class()
className
class
object
What is the correct way to create an object called myObj of MyClass?
class myObj = new MyClass();
class MyClass = new myObj();
new myObj = MyClass();
MyClass myObj = new MyClass();
In Java, it is possible to inherit attributes and methods from one class to another.
True
False
Which method can be used to find the highest value of x and y?
Math.maximum(x,y)
Math.maxNum(x,y)
Math.max(x,y)
Math.largest(x,y)
Which operator is used to multiply numbers?
#
*
%
x
Which keyword is used to import a package from the Java API library?
import
package
lib
getlib
How do you start writing an if statement in Java?
if (x > y)
if x > y then:
if x > y:
How do you start writing a while loop in Java?
x > y while {
while x > y {
while x > y:
while (x > y)
Which keyword is used to return a value inside a method?
break
return
get
void
Which statement is used to stop a loop?
stop
break
exit
return
