Do I need to import the Java.lang package anytime during running a program?

Java 8Object Oriented ProgrammingProgramming

No, java.lang package is a default package in Java therefore, there is no need to import it explicitly.

i.e. without importing you can access the classes of this package.

If you observe the following example here we haven’t imported the lang package explicitly but, still we are able to calculate the square root of a number using the sqrt() method of the java.lang.Math class.

Example

Live Demo

public class LangTest {
   public static void main(String args[]){
      int num = 100;
      double result = Math.sqrt(num);
      System.out.println("Square root of the number: "+result);
   }
}

Output

Square root of the number: 10.0
raja
Published on 02-Jan-2018 11:19:47
Advertisements