Results 1 to 4 of 4
  1. #1
    liber77 is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default How to know if import succeeded

    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.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default Re: How to know if import succeeded

    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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: How to know if import succeeded

    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:

    Java Code:
    Data.java:1: error: package foo does not exist
    import foo.Bar;
              ^
    1 error
    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.

    [Edit] 11 min slow! :( That's because I had to locate where the Java compiler is on this laptop.
    Last edited by pbrockway2; 12-13-2011 at 05:58 AM.

  4. #4
    2by4 is offline Banned
    Join Date
    Dec 2011
    Posts
    143
    Rep Power
    0

    Default Re: How to know if import succeeded

    Quote Originally Posted by liber77 View Post
    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.
    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.

Similar Threads

  1. import.acm ?
    By javajosh in forum New To Java
    Replies: 4
    Last Post: 07-12-2012, 06:41 PM
  2. How do you import?
    By Gary20 in forum New To Java
    Replies: 2
    Last Post: 01-28-2011, 06:12 PM
  3. Help with import
    By eel in forum New To Java
    Replies: 2
    Last Post: 09-19-2010, 10:51 AM
  4. Import
    By gothrog in forum Java Applets
    Replies: 2
    Last Post: 05-13-2010, 11:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •