300+ [LATEST] Java.lang Package Interview Questions and Answers

Q1. What Will Math.min () Do?

The min () method returns smaller value out of the supplied values.

Q2. What Will Math. Ceil() Do?

This method returns always double, which is not less than the supplied value. It returns next available whole number.

Q3. How Many Objects Are In The Memory After The Exaction Of Following Code Segment?

String str1 = “ABC”;

String str2 = “XYZ”;

String str1 = str1 + str2;

There are 3 Objects.

Q4. What Will Math.abs () Do?

It simply returns the absolute value of the value supplied to the method, i.e. gives you the same value. If you supply negative value it simply removes the sign.

Q5. What Is The Use Of Java.lang. Class Class?

The java.lang. Class class is used to represent the classes and interfaces that are loaded by a java program.

Q6. How Will You Find Length Of A String Object?

Using length () method of String class.

Q7. Why Most Of The Thread Functionality Is Specified In Object Class?

Basically for interthread communication.

Q8. What Is The Difference Between String And String Buffer?

Object’s of String class is immutable and object’s of StringBuffer class is mutable moreover String buffer is faster in concatenation.

Q9. What Will Math.max () Do?

The max () method returns greater value out of the supplied values.

Q10. What Will Math. Random () Do?

The random () method returns random number between 0.0 and 1.@It always returns double.

Q11. Can You Instantiate Math Class?

No. It cannot be instantiated. The class is final and its constructor is private. But all the methods are static, so we can use them without instantiating the Math class.

Q12. What Is The Difference Between An Object And Object Reference?

An object is an instance of a class. Object reference is a pointer to the object. There can be many references  to the same object.

Q13. What Is The Base Class Of All Classes?

java.lang.Object

Q14. Is String A Wrapper Class Or Not?

No. String is not a Wrapper class.

Q15. What Is The Possible Runtime Exception Thrown By Sub String () Method?

ArrayIndexOutOfBoundsException.

Q16. What Do You Think Is The Logic Behind Having A Single Base Class For All Classes?

  1. Casting
  2. Hierarchical and object oriented structure.

Q17. What Is The Use Of Math Class?

Math class provides methods for mathematical functions.

Q18. What Will Trim () Method Of String Class Do?

Trim () eliminate spaces from both the ends of a string.

Q19. What Will Math. Floor () Do?

This method returns always double, which is not greater than the supplied value.