Java Questions & Answers – Java.lang Introduction

This section of our 1000+ Java MCQs focuses on java.lang library of Java Programming Language.

1. Which of these classes is not included in java.lang?
a) Byte
b) Integer
c) Array
d) Class
View Answer

Answer: c
Explanation: Array class is a member of java.util.

2. Which of these is a process of converting a simple data type into a class?
a) type wrapping
b) type conversion
c) type casting
d) none of the Mentioned
View Answer

Answer: a
Explanation: None.

3. Which of these is a super class of wrappers Double & Integer?
a) Long
b) Digits
c) Float
d) Number
View Answer

Answer: d
Explanation: Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.
advertisement
advertisement

4. Which of these is a wrapper for simple data type float?
a) float
b) double
c) Float
d) Double
View Answer

Answer: c
Explanation: None.

5. Which of the following is a method of wrapper Float for converting the value of an object into byte?
a) bytevalue()
b) byte byteValue()
c) Bytevalue()
d) Byte Bytevalue()
View Answer

Answer: b
Explanation: None.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which of these methods is used to check for infinitely large and small values?
a) isInfinite()
b) isNaN()
c) Isinfinite()
d) IsNaN()
View Answer

Answer: a
Explanation: isinfinite() method returns true is the value being tested is infinitely large or small in magnitude.

7. Which of the following package stores all the simple data types in java?
a) lang
b) java
c) util
d) java.packages
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     class isinfinite_output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             Double d = new Double(1 / 0.);  
  6.             boolean x = d.isInfinite();
  7.             System.out.print(x);
  8.         }
  9.     }

a) 0
b) 1
c) true
d) false
View Answer

Answer: c
Explanation: isInfinite() method returns true is the value being tested is infinitely large or small in magnitude. 1/0. is infinitely large in magnitude hence true is stored in x.
Output:

advertisement
$ javac isinfinite_output.java
$ java isinfinite_output
true

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

  1.     class isNaN_output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             Double d = new Double(1 / 0.);  
  6.             boolean x = d.isNaN();
  7.             System.out.print(x);
  8.         }
  9.     }

a) 0
b) 1
c) true
d) false
View Answer

Answer: d
Explanation: isisNaN() method returns true is the value being tested is a number. 1/0. is infinitely large in magnitude, which cannot be defined as a number hence false is stored in x.
Output:

$ javac isNaN_output.java
$ java isNaN_output
false

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

  1.     class binary 
  2.     {
  3.          public static void main(String args[]) 
  4.          {
  5.              int num = 17;
  6.              System.out.print(Integer.toBinaryString(num));
  7.          }
  8.     }

a) 1001
b) 10011
c) 11011
d) 10001
View Answer

Answer: d
Explanation: None.
output:

$ javac binary.java
$ java binary 
10001

Sanfoundry Global Education & Learning Series – Java Programming Language.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.