Results 1 to 7 of 7
  1. #1
    javajames is offline Member
    Join Date
    May 2011
    Posts
    32
    Rep Power
    0

    Question importing classes

    i understand how to create objects from classes within your java file, but i cant seem to get my head around importing classes from other files. I know that you have to use import, but i have heard you have to create packages, also, how do i find the file location (as in folder/folder/file), what do i need to do to either creat and import these packages or import classes?

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Suggested reading : Using Package Members

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default

    The import statement is an extension of the classpath. It helps the compiler find class definitions.
    If you use classes that are in packages, the classpath must point to the folder containing the starting folder of the package name. For example if your package is MyCode and then the classpath should point to the folder containing the MyCode folder. In the code that uses classes in the MyCode package you'd code:
    import MyCode.*;

  4. #4
    javajames is offline Member
    Join Date
    May 2011
    Posts
    32
    Rep Power
    0

    Default

    Thank you for the website and the info, errm... any sites for creating a package (or info on how to do so)

  5. #5
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by javajames View Post
    any sites for creating a package (or info on how to do so)
    Seems like you didn't see the link that I gave or else you would have found the same thing over there.

    Anyways, follow here: Creating and Using Packages

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  6. #6
    javajames is offline Member
    Join Date
    May 2011
    Posts
    32
    Rep Power
    0

    Default

    sorry, its just that didn't really make much sense to me, (that link)

  7. #7
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Most IDE's allow you to just right click>new package.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. Dynamically interpreting/importing code/classes
    By ~ in forum Advanced Java
    Replies: 1
    Last Post: 04-27-2011, 04:06 AM
  2. Importing classes in upper directory.
    By PrinceSendai in forum New To Java
    Replies: 2
    Last Post: 02-25-2011, 04:28 AM
  3. importing other classes or using a Jar
    By xhane in forum New To Java
    Replies: 3
    Last Post: 01-31-2009, 05:20 AM
  4. Need help with importing classes
    By Deathmonger in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 10:03 AM
  5. Importing classes
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-06-2007, 02:27 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
  •