CSC300: Import [3/12] |
Python | Java | ||||
---|---|---|---|---|---|
|
|
System.out
and System.in
refer to objects.
I don't want to talk about objects yet, so we will use the version
about, which replaces System.out
with StdOut
.
StdOut
is a class in the stdlib
package.
System
is a class in the java.lang
package.
All of the classes in java.lang
are imported
implicitly into every java program. All other classes must be
imported explicitly.
The statement import stdlib.*
makes the classes
declared in stdlib
visible in our program.
Instead of importing every class from a package, you can also import a single class.
import stdlib.*
with import stdlib.StdOut
.
Unnecessary imports will generate a warning.
import stdlib.StdIn
.
If your code has a compiler error, it will not run.
If your code has a warning, you can run it. But you should fix the warning.