Java Questions and Answers Part-1

1. Which component is responsible to optimize bytecode to machine code?
a) JVM
b) JRE
c) JIT
d) JDK

Answer: c
Explanation: JIT optimizes bytecode to machine specific language code by compiling similar bytecodes at the same time. This reduces overall time taken for compilation of bytecode to machine specific language.

2. What is the extension of java code files?
a) .class
b) .txt
c) .js
d) .java

Answer: d
Explanation: Java files have .java extension

3. What is use of interpreter?
a) They are intermediated between JIT and JVM
b) They read high level code and execute them
c) They convert bytecode to machine language code
d) It is a synonym for JIT

Answer: b
Explanation: Interpreters read high level language (interprets it) and execute the program.

4. What is the extension of compiled java classes?
a) .txt
b) .class
c) .java
d) .js

Answer: b
Explanation: The compiled java files have .class extension

5. Which component is used to compile, debug and execute java program?
a) JDK
b) JRE
c) JIT
d) JVM

Answer: a
Explanation: JDK is a core component of Java Environment and provides all the tools, executables and binaries required to compile, debug and execute a Java Program.

6. Which statement is true about java?
a) Platform independent programming language
b) Platform dependent programming language
c) Code dependent programming language
d) Sequence dependent programming language

Answer: a
Explanation: Java is called platform independent language as it primarily works on the principle of ‘compile once, run everywhere’.

7. Which concept of Java is achieved by combining methods and attribute into a class?
a) Abstraction
b) Inheritance
c) Encapsulation
d) Polymorphism

Answer: c
Explanation: Encapsulation is implemented by combining methods and attribute into a class. The class acts like a container of encapsulating properties.

8. Which component is responsible to run java program?
a) JVM
b) JIT
c) JDK
d) JRE

Answer: d
Explanation: JRE is the implementation of JVM, it provides platform to execute java programs.

9. Which of the below is invalid identifier with the main method?
a) public
b) final
c) private
d) static

Answer: c
Explanation: main method cannot be private as it is invoked by external method. Other identifier are valid with main method.

10. Which component is responsible for converting bytecode into machine specific code?
a) JDK
b) JVM
c) JRE
d) JIT

Answer: b
Explanation: JVM is responsible to converting bytecode to the machine specific code.