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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give edge cases for imports !

A
  1. import java.nio.; // NO GOOD – a wildcard only matches
    //class names, not “file.
    Files”
  2. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly