Beginning Java with BlueJay online Test
What is a variable?
A variable is the value a user inputs.
A variable is an unknown value in an equation.
A variable is a datatype.
A variable can hold a value based on its datatype.
This statement will not throw an error (True or False)-
String newvalue=5;
True
False
Can you assign any value to a variable?
No. You can assign any variable to only a String variable.
Yes. Variables are memory locations, and you can place any value in that particular memory location.
No. You can only assign a value to its respective type of variable.
None of the above.
What is a method?
A method is a section of code that receives an input, and might return an output.
A method is similiar to a function in math.
A method is used to break down the code in easily manageable parts.
All of the above.
What is the Java command to print 'test' to the console (Pick the one with the correct syntax)?
System.out.println('test');
System.out.println('test')
System.println('test');
None of the above
What does the command 'new' do?
The new command is a type of a variable.
The keyword 'new' will allocate some RAM
The keyword 'new' will create a new object for you and initialize
all its fields to zeros/nulls
Only 2 and 3.
None of the above.
What does null mean (Select the best answer)?
Null means that the variable is empty.
It will cause a null pointer exception.
A null value means that the variable has no value or that the value doesn't exist.
None of the above.
What is one way to get input from a user?
You can use the JOptionPane.InputDialog.
You can ask the user to input a value.
You can use the Input Object.
You can use the JOptionPane.showInputDialog.
What does import do?
Import will import the needed libraries for the class you are going to use.
Import will get input from a user.
Import is not a Java command.
Only 1 and 2.
Where is the syntax error in this program (Ignore the line numbers)?
1) int x=0;
2) x=x+5;
3) y=5;
4) y=y+x;
5) System.out.println('The value is: '+y);
Line 1
Line 2
Line 3
Line 4
Line 5
What is the multiplication command in Java?
>
/
*
@
What is printed to the console?
int y=0;
int x=2;
y=10;
y=10/x;
x=5;
y=y*x;
System.out.println(y);
2
30
5
25
What will print to the console?
String myString=”1”;
String myString2=”2”;
String newString=myString+myString2;
System.out.println(newString);
3
12
1
2
What is the correct way to comment your code?
a)
/**
* This is a comment
*/
b)
--This is a comment
c)
//This is a comment
d)
**This is a comment
Choice a and c
Choice a and b
choice b and d
choice c and d
How to you handle an error in Java?
You should use a block statement.
You should let Java handle the errors.
You should use a try-catch Block.
None of the above.
The main method is the starting of a Java program (True or False)?
True
False
What is a syntax error?
Your code has an error
Your code has an error when compiling
All of the above
None of the above
What is the best way to print “this is a test” 5 times?
a)
System.out.println(“this is a test”);
System.out.println(“this is a test”);
System.out.println(“this is a test”);
System.out.println(“this is a test”);
System.out.println(“this is a test”);
b)
for(int x=0;x<5;x++)
{
System.out.println('this is a test');
}
Choice a
Choice b
None of the above
All of the above
What does this code do?
int x=0;
for(x=0;x<5;x++)
{
if(x==5)
{
System.out.println(“this is a test”);
}
}
System.out.println(x);
It will print 5 to the console.
It will do nothing.
It will print 4 to the console.
It will print “this is a test” to the console.
What will this block of code do?
String inputValue='5r';
Integer count=0;
try
{
count=new Integer(inputValue).intValue();
System.out.println(count):
}
catch(NumberFormatException e)
{
System.out.println(“You received an error.”);
}
It will print 5 to the System console.
It will print “You received an error” to the System console.
It will print 5r to the System console.
It will print, “NumberFormatException”.
Description:
This test is for my Beginning Java part 1 class which covers installing Java and BlueJay, variables, datatypes, basic understanding of methods and functions, creating a workspace with BlueJay, compiling and running an application, basic understanding of classes and objects, Errors, Try-Catch blocks, math, Strings, For loops, and if-else statements.