Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

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);

Can anyone tell me what’s the best way to import the class in Java? 

1 Answer

0 votes
by (19.7k points)

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. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...