wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Basics Self-Check

Total questions: 46

Worksheet time: 24mins

Name
Class
Date
1.

Which of the following is a comment in the Java language?

a)

/ comment /

b)

//comment

c)

/ comment */

d)

<-- comment -->

2.

Which of the following is the correct main() method signature in Java?

a)

public static void main (String [] args)

b)

public static void Main (String [] args)

c)

public static void main (string [] args)

d)

public static void main (String args)

3.

Which of this command does not have errors?

a)

System.out.print("Hello World")

b)

System.out.print(Hello World);

c)

System.out.Print("Hello World);

d)

System.out.print("Hello World");

4.

What will be output of below program?

public class Test {

public static void main(String[] args) {

int x = 10*20-20;

System.out.println(x);

}

}

a)

Runtime Error

b)

Prints 180

c)

Prints 0

d)

None of the above

5.

What is the output for the following statement:

System.out.print("1"+"1");

a)

11

b)

2

c)

Error Message

6.

Indicate the actual output of the statements below:

int thisYear = 2020;

System.out.println("The current year is "+thisYear);

a)

The current year is thisYear

b)

The current year is 2020

c)

No output; an error exists

d)

The current year is

7.

Which of the following is used as a terminator in Java programming?

a)

)

b)

;

c)

.

d)

>

8.

int x= 10;

int y = 20;

int z = x + y;

System.out.println(z);

Guess the output.

a)

1020

b)

10 20

c)

30

d)

"10 20"

9.

Which of this command has errors? Select multiple

a)

System.out.print("Hello World")

b)

System.out.print(Hello World);

c)

System.out.Print("Hello World);

d)

System.out.print("Hello World");

10.

It is an optional statement used to describe what a program or a line of program is doing.

a)

tag

b)

command

c)

code

d)

comment

11.

A data type which is typical in form and make use of digits and a decimal point

a)

integer

b)

float

c)

char

d)

boolean

12.

What data type is classified as a sequenced of characters with double quotes.

a)

Char

b)

String

c)

boolean

d)

Float

13.

True or False : Java is case sensitive, which means identifier Hello and hello would have different meaning in Java

a)

True

b)

False

14.

Comment lines are not ignored by the compiler. True or False?

a)

True

b)

False

15.
A variable that holds a whole number
a)
String
b)
boolean
c)
int
d)
float
16.

A variable that holds words

a)

String

b)

boolean

c)

int

d)

float

e)

A dictionary

17.

A variable that holds true or false

a)

String

b)

boolean

c)

int

d)

float

e)

Alex Trebek

18.

Name the data type: 1.0

a)

double

b)

int

c)

char

d)

boolean

19.

Name the data type: "true"

a)

boolean

b)

char

c)

String

d)

double

20.

Name the data type: false

a)

String

b)

boolean

c)

int

d)

None of the above

21.

What data type would you use for storing the number of students in a class?

a)

boolean

b)

String

c)

double

d)

int

22.

What data type would you use for storing the average test score in a class?

a)

double

b)

String

c)

int

d)

char

23.

What data type would you use to store names of students?

a)

String

b)

char

c)

boolean

d)

None of these

e)

blonde

24.

How would you declare a variable storing the tax rate?

a)

int taxRate = 5.1;

b)

taxRate = "5.1";

c)

double taxRate = 5.1;

d)

double taxRate = "5.1";

e)

I do hereby declare thee Sir Tax Rate

25.

How would you declare a variable storing a person's name?

a)

string name = "Elroy";

b)

name String = "Elroy";

c)

String name = Elroy;

d)

String name = "Elroy";

e)

Me llamo Elroy

26.

How would you declare a variable that tells you that someone passed a class?

a)

boolean passed = 'true';

b)

boolean passed = true;

c)

passed = true;

d)

String passed = "true";

e)

Trick question - no one passes this class

27.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

28.

What prints out "I love Java" successfully?

a)

System.out.println(I love Java);

b)

Systemoutprintln("I love Java);

c)

System.out.println("I love" + " Java");

d)

System.out.println("I love Java")

e)

What is love? Baby dont hurt me. Dont hurt me. No more.

29.

4 % 6

a)

4

b)

6

c)

2

d)

3

30.

6 % 4

a)

4

b)

6

c)

2

d)

3

31.

int a = 7;

int b = 2 + a;

a)

b = 9

b)

b = 2

c)

b = 7

d)

b = 5

32.

int a = 5;

a++;

What is a now?

a)

4

b)

7

c)

5

d)

6

33.

int a = 5;

a--;

What is a now?

a)

4

b)

3

c)

5

d)

6

34.

What will print?

System.out.println( 1 / 4 );

a)

0

b)

0.25

c)

1

d)

4

35.

What will print?

System.out.println( 1.0 / 4 );

a)

0

b)

0.25

c)

1

d)

4

36.

What will print?

System.out.println( (double) 1 / 4 );

a)

0

b)

0.25

c)

1

d)

4

37.

int x = 4;

x *= 10;

Which is true?

a)

x is now 40

b)

x is now 10

c)

x is still 4

d)

x is now 14

38.

What is the value of b after this code segment?

int a = 4;

int b = a++;

a = a * 2;

b /= 2;

a)

2

b)

4

c)

5

d)

8

39.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

40.

What's the value of below?


int i=5;

System.out.println(i++);

System.out.println(i);

System.out.println(++i);

a)

5

6

7

b)

6

6

7

c)

6

7

8

d)

5

5

6

41.

Which statement(s) are equivalent to i = i + 1?

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

42.

what is modulo operation used for ?

a)

performs division

b)

performs division and gives no remainder

c)

performs division and gives remainder

d)

does not perform division

43.

arithmetic operators return a value. True or false?

a)

true

b)

false

44.

conditional operators does not return a value

a)

true

b)

false

45.

which type of operator it is? i + =5

a)

addition assignment operator

b)

conditional operator

c)

arithmetic operator

d)

equality operator

46.

Find the output for the following.

public class IncDec

{

public static void main(String s[])

{

int a = 1;

int b = 2;

int c;

int d;


c = ++b;

d = a++;


c++;


System.out.println("a = " + a);

System.out.print("b = " + b);

System.out.println("c = " + c);

System.out.print("d = " + d);

}

}

a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2