wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Inntro and Variables

Total questions: 20

Worksheet time: 22mins

Name
Class
Date
1.

Identify the INCORRECT statement about compilation and execution of Java programs.

a) Javac helps in compiling the java program and creates the .class files
b) Java runs the programs using the bytecode in .class files
c) Java runs the programs using the source code in .java files
d) Javac is in the JDK package and java is in the JRE package

a)

a

b)

b

c)

c

d)

d

2.

Which component is responsible for converting byte code into machine specific code?

a) JIT
b) JDK
c) JVM
d) JRE

a)

a

b)

b

c)

c

d)

d

3.

Which statement is TRUE about Java?

a) Platform independent programming language
b) Code dependent programming language
c) Sequence dependent programming language
d) Code dependent programming language

a)

a

b)

b

c)

c

d)

d

4.

What will be the output of the following program?

a)

Compilation error since "Hello Wrold" has spelling mistake, it should be "Hello World"

b)

Compilation error since the class name does not contain at least one capital letter. It works fine if the class name was HelloWorld

c)

Compilation error for some other reason

d)

Hello Wrold

5.

What is the extension of source code files?

a) .class
b) .java
c) .txt
d) .js

a)

a

b)

b

c)

c

d)

d

6.

Identify the invalid java keyword in the below list.

a) integer
b) float
c) char
d) case

a)

a

b)

b

c)

c

d)

d

7.

Which data type is used to create a variable that should store sequence of characters?

a) Txt
b) String
c) char
d) string

a)

a

b)

b

c)

c

d)

d

8.

Choose ALL the invalid variables' names.

a) roll_number
b) MIB2
c) name with spaces
d) $arya
e) with_lot_of_under_scores_
f) startingwith_under_score_
g) numberOfStudents
h) runsCount!
i) 3idiots
j) i
k) j
l) ABC345
m) PI

a)

c,d,e,h,i

b)

b,d,h,i,l

c)

c,d,h,i,l

d)

c,h,i

9.

Which of the below is invalid identifier with the main method?

a) public
b) static
c) private
d) none of the aboves

a)

a

b)

b

c)

c

d)

d

10.

What is the output of the  following program?

a) true
b) false
c) compile error
d) 21

a)

a

b)

b

c)

c

d)

d

11.

What are the Type Conversions available in Java language?

a)  Narrowing Type Conversion
b)  Widening Type Conversion
c)  A and B
d)  None of the above

a)

a

b)

b

c)

c

d)

d

12.

What is the output of the Java code snippet below?

a) 25
b) 26
c) 27
d) Compiler error

a)

a

b)

b

c)

c

d)

d

13.

How is a line of code convert to COMMENTS in Java?

a) /* This is a comment
b) // this is a comment
c) # this is a comment
d) -- this is a comment

a)

a

b)

b

c)

c

d)

d

14.

Which of the followings are legal lines of Java code?

1. int w=(int)888.8;
2. byte x=(byte)100L;
3. long y=(byte)100;
4. byte z=(byte)10.1F;




a) 1 and 2
b) 2 and3
c) 3 and 4
d) All statemnets are correct

a)

a

b)

b

c)

c

d)

d

15.

What is output of code below?

a)    30EuroTech
        EuroTech1020

b)     30EuroTech
        EuroTech30

c)     1020EuroTech
        EuroTech1020

d)     1020EuroTech
        EuroTech30

a)

a

b)

b

c)

c

d)

d

16.

What is the output of code below?

a) 7 = 7
    7 + 7

b) 5 + 2 = 34 
    5 + 2 = 7

c) 5 + 2 = 34
    5 + 2 = 34

d) 5 + 2 = 3 + 4
    5 + 2 = 7

a)

a

b)

b

c)

c

d)

d

17.

What's the result?

a) 10.5
b) 10
c) 0
d) Compilation fails

a)

a

b)

b

c)

c

d)

d

18.

What's the value of c ?

a) 1
b) 4
c) -1
d) 0

a)

a

b)

b

c)

c

d)

d

19.

What is the output of code below?

a) 3
b) Compilation fails
c) 3.333333335
d) 3.0

a)

a

b)

b

c)

c

d)

d

20.

What is output of this code?
    line 1: int x = 15.2;
    line 2: System.out.println ("x is now + x");

   a) 15
   b) 15.2
   c) error line 1
   d) error line 2
   e)  x is now + x

a)

a

b)

b

c)

c

d)

d

e)

e