Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By pbrockway2

Thread: import class java where is it?

  1. #1
    javing is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default import class java where is it?

    Hello, I need to ask a question from newbie.
    when I create a new java project and amount of other classes of java with example:
    import java.awt.event. *;

    how does the compiler know where the java classes?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: import class java where is it?

    It is part of the java installation process that the jar and zip files with the java classes are located where the javac and java commands can find them. It is not something you need to worry about unless you go into the jre and jdk folders and start moving files around.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default Re: import class java where is it?

    how does the compiler know where the java classes?
    I agree with Norm: the location of java.awt.event.* classes, for example, is part of the configuration of Java (both the runtime and the compiler) when it is installed.

    For other classes - the classes you, yourself, create or third party libraries - the java executables (java, javac, etc) will look in a series of places known as the classpath. Typically the classpath is told to the compiler or the runtime when it starts. Often IDEs hide the setting of this classpath within what they call "project settings", but it important to realise that the Java "way of doing things" is different from other languages where the separate parts of a programs are specially "linked" at the time they are compiled. Having a classpath (=="place where classes and other resources are located") that is set at runtime results in a great deal of flexibility. For instance the classes can come from all over the internet, be stored in archives or databases etc, and be altered somewhat independently of one another.

    To begin with it is enough to be confident that classes are found. But, sooner or later, you will want to configure an IDEs "project settings", or compile your programs from the command line and setting this classpath will be part of that. If you understand what this classpath is (ie it is the answer to your question!) then you will be in a good position to understand the documentation and the advice you might get in forums like this about setting it.

    I might add that the classpath, understood in this general sense, is different from the CLASSPATH environment variable which is supposed to be a general purpose classpath that all java executables will use. Advice you often see on the web to set this variable to one value or another is not good advice, imho, in as much as it fights against the idea of gaining flexibility by setting the classpath when the executable is run.
    jfabian likes this.

Similar Threads

  1. Iterator next import class?
    By daydreamer in forum New To Java
    Replies: 7
    Last Post: 10-04-2010, 11:32 PM
  2. import class
    By Dipke in forum New To Java
    Replies: 5
    Last Post: 08-09-2010, 10:54 AM
  3. how to Import my Java Class in Jsp Page
    By pos in forum JavaServer Pages (JSP) and JSTL
    Replies: 20
    Last Post: 04-06-2010, 02:51 PM
  4. can't import my own class
    By Splat in forum New To Java
    Replies: 5
    Last Post: 10-13-2009, 04:53 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
  •