Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA FUNDAMENTALS

Total questions: 20

Worksheet time: 34mins

Name
Class
Date
1.

Which of the following can be operands of arithmetic operators?

a)

Numeric

b)

Boolean

c)

Both Numeric & Characters

d)

Characters

2.

What will be the output of the following Java program?

class Output {

public static void main(String args[]) {

int a = 1;

int b = 2;

int c;

int d;

c = ++b;

d = a++;

c++;

b++;

++a;

System.out.println(a + " " + b + " " + c); }

}

a)

324

b)

323

c)

244

d)

234

e)

344

3.

What will be the output of the following Java code?

class operators {

public static void main(String args[]) {

int x = 8;

System.out.println(++x * 3 + " " + x); }

a)

24 8

b)

27 9

c)

24 9

d)

27 8

4.

What will be the output of the following Java code?

class Relational_operator {

public static void main(String args[]) {

int var1 = 5;

int var2 = 6;

System.out.print(var1 > var2); }

}

a)

5

b)

6

c)

FALSE

d)

TRUE

5.

Which of these is not an Assignment Operator?

a)

&=

b)

|=

c)

+=

d)

<=

6.

What will be the output of the following Java program?

class booloperators {

public static void main(String args[]) {

boolean var1 = true;

boolean var2 = false;

System.out.println((var1 & var2));

}

}

a)

True

b)

False

c)

1

d)

0

7.

What will be the output of the following Java program?

public static void main(String args[]) {

char a = 65;

char b = 66;

char d = 68;

d--;

char c = --b;

a++;

System.out.println(b);

System.out.println(d);

System.out.println(b);

System.out.println(a);

}

}

a)

A

C

A

B

b)

B

A

B

A

c)

B

A

C

A

d)

A

D

A

B

8.

What will be the output of the following Java program?

class squareroot {

public static void main(String args[]) {

double a, b;

a = 3.0;

b = 4.0;

double c = Math.sqrt(a * a + b * b);

System.out.println(c); } }

a)

compilation error

b)

25

c)

7

d)

5

9.

Fill in the blanks

Every line of code that runs in java must be inside a ........

A ........... should always start with an uppercase first letter

(a)  

10.

Use the addition assignment operator to add the value 5 to the variable x.


int x = 10;

x (a)   5;

11.

Java is used for :

a)

Web applications

b)

Database connection

c)

Games

d)

Desktop applications

e)

Text Editing

12.

Evaluate the following Java expression, if x=3, y=5, and z=10:

++z + y - y + z + x++

a)

23

b)

24

c)

25

d)

20

13.

Java was originally named:

a)

ISLAND

b)

OAK

c)

NEW C++

d)

JOJO

14.

Is Android based on Java?

a)

TRUE

b)

FALSE

15.

Who invented Java?

Steve Jobs, Bill Gates, James Gosling, Trump, Smeagol ?

a)
b)
c)
d)
e)
16.

Where does a java program start executing instructions from:

a)

class

b)

source file

c)

main method

d)

object

17.

Which is not a primitive data type in Java?

a)

character

b)

integer

c)

boolean

d)

class

18.

What is the result of the following statement

int a=023;

int b=0x45;

System.out.println(a+b);

a)

64

b)

74

c)

68

d)

88

19.

What is the result of the following statement

public static void main(String args[])

{

int var1 = 5;

int var2 = 6;

if ((var2 = 1) == var1)

System.out.print(var2);

else

System.out.print(++var2);

} }

a)

3

b)

5

c)

6

d)

2

20.

Which output would be produced by

System.out.print("\\* This is not \n a comment *\\");

a)

* This is not a comment *

b)

\* This is not

a comment *\

c)

\\* This is not

a comment *\\

d)

\* This is not a comment *\