How is it possible to see if a specific import command has succeeded or if it's necessary to install the library?
I am using ubuntu linux.
Printable View
How is it possible to see if a specific import command has succeeded or if it's necessary to install the library?
I am using ubuntu linux.
The 'import' statement is a compiler directive; all that happens during runtime is loading of classes; if loading a class fails an Exception is thrown. If the compiler can't find the classes/packages specified with an import statement it will tell you so.
kind regards,
Jos
You will get an error if you try and compile code that imports something that the compiler can't locate on the classpath.
Eclipse reports "The import foo cannot be found". The command line compiler might be different. Eg the JDK7 compiler tells me:
In Java imports don't actually ... import anything. They are a compile time thing which tells the compiler the packages that various classes belong to. This enables you to refer to classes by the last part of their name. Eg if you say "import java.util.List" then you can just talk about List rather than having to refer to it as java.util.List every time.Code:Data.java:1: error: package foo does not exist
import foo.Bar;
^
1 error
[Edit] 11 min slow! :( That's because I had to locate where the Java compiler is on this laptop.
As above.
For the second part of your question, you can remove the command and recompile. If you get an error, an import statement is required.
Some import statements use wildcards and may be replaced by something more specific. You would have to examine code usage to determine this.