• Post Reply Bookmark Topic Watch Topic
  • New Topic

Use java.lang.Math methods without import in IDE  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am able to use a Math method without importing the java.lang.Math. Which makes me think
1) What is the use of the import statement in java?
2) Is my IDE taking care of the import automatically?

I am using Eclipse IDE and JDK 1.7.
 
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All classes in the java.lang package are imported automatically by the compiler. But those are the only exceptions to the rule that you have to import classes in other packages for the compiler to recognize them.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sriniketh Kovin wrote:
2) Is my IDE taking care of the import automatically?


A good IDE will only import what it needs to import and it will tell you what it imports.
 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you don't need any import statement at all!
You could write your code using full class names including their package names.
Like this:
But the problem is... it looks ugly.

Import statements are for us humans. Java compiler don't need them
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!