SkatZ SkatZ - 7 months ago 14
Java Question

Are Imports and Libraries the same?

So I am kind of confused, I am righting my dissertation for the software I made and i was wondering while explaining the code if the Imports that i used in each class like
"import java.io.IOException;" are in the same moment Libraries? Or Libraries is something else?

Answer

A Java library is a jar file containing classes and other resources. To be available, at compile time and at runtime, this library (the jar file) must be present in the classpath.

Imports have nothing to do with libraries. Imports are used to allow the source code to use short class names instead of fully qualified names. For example, being able to code

List<String> list = new ArrayList<String>();

instead of

java.util.List<String> list = new java.util.ArrayList<String>();

Whether you use an import or use the fully qualified name, the Java compiler or the Java runtime must be able to find the class in its classpath. If the class is part of a library, then this library must be in the classpath.

Comments