Thursday 5 May 2022

10 Java Programming (MCQs)

Java Programming (MCQs) 

1. Who invented Java Programming?

a) Guido van Rossum
b) James Gosling
c) Dennis Ritchie
d) Bjarne Stroustrup

Answer: b
Explanation: Java programming was developed by James Gosling at Sun Microsystems in 1995. James Gosling is well known as the father of Java.

2. Which statement is true about Java?
a) Java is a sequence-dependent programming language
b) Java is a code dependent programming language
c) Java is a platform-dependent programming language
d) Java is a platform-independent programming language

Answer: d
Explanation: Java is called ‘Platform Independent Language’ as it primarily works on the principle of ‘compile once, run everywhere’.

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

Answer: c
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.

4. Which one of the following is not a Java feature?
a) Object-oriented
b) Use of pointers
c) Portable
d) Dynamic and Extensible

Answer: b
Explanation: Pointers is not a Java feature. Java provides an efficient abstraction layer for developing without using a pointer in Java. Features of Java Programming are Portable, Architectural Neutral, Object-Oriented, Robust, Secure, Dynamic and Extensible, etc.

5. Which of these cannot be used for a variable name in Java?
a) identifier & keyword
b) identifier
c) keyword
d) none of the mentioned

Answer: c
Explanation: Keywords are specially reserved words that can not be used for naming a user-defined variable, for example, class, int, for, etc.

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

Answer: d
Explanation: Java files have .java extension.

7. What will be the output of the following Java code?

  1.     class increment {
  2.         public static void main(String args[]) 
  3.         {        
  4.              int g = 3;
  5.              System.out.print(++g * 8);
  6.         } 
  7.     }

a) 32
b) 33
c) 24
d) 25

Answer: a
Explanation: Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32.
output:

$ javac increment.java
$ java increment
32

8. Which environment variable is used to set the java path?
a) MAVEN_Path
b) JavaPATH
c) JAVA
d) JAVA_HOME

Answer: d
Explanation: JAVA_HOME is used to store a path to the java installation.

9. What will be the output of the following Java program?

  1. class output {
  2.         public static void main(String args[]) 
  3.         {
  4.             double a, b,c;
  5.             a = 3.0/0;
  6.             b = 0/4.0;
  7.             c=0/0.0;
  8.  
  9. 	    System.out.println(a);
  10.             System.out.println(b);
  11.             System.out.println(c);
  12.         } 
  13.     }

a) NaN
b) Infinity
c) 0.0
d) all of the mentioned

Answer: d
Explanation: For floating-point literals, we have a constant value to represent (10/0.0) infinity either positive or negative, and also have NaN (not a number for undefined like 0/0.0), but for the integral type, we don’t have any constant that’s why we get an arithmetic exception.

10. Which of the following is not an OOPS concept in Java?
a) Polymorphism
b) Inheritance
c) Compilation
d) Encapsulation

Answer: c
Explanation: There are 4 OOPS concepts in Java. Inheritance, Encapsulation, Polymorphism, and Abstraction.