Results 1 to 7 of 7
  1. #1
    gpr
    gpr is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default How import statements are included

    Hi Friends
    I am new to Java. I have a simple program wherein I am try to use some regex functions and it works fine. But, I am not able to understand how the import statement works.

    My program has the following import statement:

    Java Code:
    import java.util.regex.*;
    And this regex is inside a jar file which is located in C:\Program Files\Java\jdk1.6.0_07\jre\lib\rt.jar. My CLASSPATH variable is not set and is empty.

    My question is: When I run the java program, how is it able to find out that my regex is inside rt.jar which is in so and so path since we dont have anything pointing to the location?

  2. #2
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    May be the IDE your using is pointing to that JAR file, or there is another one your are unaware of. Fairly sure that path is also the default (not sure, on Linux myself).

  3. #3
    liyuyu_852000 is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default

    yes ,rp181,I think you are right,
    the IDE has contain the jar

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by gpr View Post
    My CLASSPATH variable is not set and is empty.
    Check your JAVA_HOME environment variable.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    rt.jar is the basic runtime jar, containing all the standard java classes.
    If you can run java programs then that jar file is accessible by the JVM.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    rt.jar, as well as a large number of additional jars are on the bootstrap classpath which is based upon the directory in which the executing java command resides (unless you change it on the command line), and many other jars (a directoriey actually) are included as part of the "extension dirs" property which is also predetermined, and configurable, in the same manner.

    Edit: There is also a bootstrap extension property, but that, normally, is empty.

  7. #7
    gpr
    gpr is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default

    Thanks a lot masijade. Understood the bootstrap classpath now.

Similar Threads

  1. error - I think involving my Import Statements
    By Sparky in forum New To Java
    Replies: 2
    Last Post: 02-02-2011, 02:31 PM
  2. JDBC code not included into JAR file??
    By friday in forum Advanced Java
    Replies: 1
    Last Post: 12-17-2010, 07:13 PM
  3. Replies: 0
    Last Post: 10-31-2010, 08:51 AM
  4. Included file throws error.
    By killerf2006 in forum New To Java
    Replies: 3
    Last Post: 08-20-2010, 11:18 AM
  5. Problems with packages (import statements)
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 06-29-2007, 11:57 AM

Posting Permissions

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