Back
Accessing the class within a package with the fully qualified name:
java.lang.Math.sqrt(x);
Importing the whole package:
import java.lang.Math;Math.sqrt(x);
import java.lang.Math;
Math.sqrt(x);
Can anyone tell me what’s the best way to import the class in Java?
There’s no better way since the import directive is not converted to Java byte code, so there will be no difference in memory usage or performance. But if you are using the import class multiple times in your code, importing the whole package saves you time.
Interested in Java? Check out this Java Certification by Intellipaat.
30.9k questions
32.9k answers
500 comments
665 users