Redundant Imports Flashcards
1
Q
Which package is implicitly imported ?
A
There’s one special package in the Java world called java.lang. This package is special in that it is automatically imported
2
Q
Give a tricky case of redundant import !
A
Same Package: When you have classes within the same package, you do not need to use an import statement to access them. Classes in the same package can directly reference each other using their class names.
Java automatically looks in the current package for other classes.
3
Q
Give edge cases for imports !
A
- import java.nio.; // NO GOOD – a wildcard only matches
//class names, not “file.Files” - import java.nio..; // NO GOOD – you can only have one wildcard
//and it must be at the end
3.import java.nio.files.Paths.*; // NO GOOD – you cannot import methods
//only class names