package and import efficiency

Discussion in 'Java' started by Sal, Jun 19, 2010.

  1. Sal

    Sal Guest

    I have a directory that contains many classes in the same package and
    a program that uses just one of those classes. Is there any advantage
    to moving that program outside the directory and import only the class
    it needs over keeping it in the directory and making it part of the
    same package, eliminating the need for the import?
    Sal, Jun 19, 2010
    #1
    1. Advertising

  2. Sal

    Arne Vajhøj Guest

    On 19-06-2010 11:49, Sal wrote:
    > I have a directory that contains many classes in the same package and
    > a program that uses just one of those classes. Is there any advantage
    > to moving that program outside the directory and import only the class
    > it needs over keeping it in the directory and making it part of the
    > same package, eliminating the need for the import?


    I am not quite sure that I understand the question.

    But anyway:
    * directory structure and package structure should match
    * package structure should reflect the logical structure
    in your software
    * full name vs import vs same package is only relevant at compile
    time - at runtime all classes are referenced using full names

    Arne
    Arne Vajhøj, Jun 19, 2010
    #2
    1. Advertising

  3. Sal

    Lew Guest

    Sal wrote:
    > I have a directory that contains many classes in the same package and
    > a program that uses just one of those classes. Is there any advantage
    > to moving that program outside the directory and import only the class
    > it needs over keeping it in the directory and making it part of the
    > same package, eliminating the need for the import?


    No.

    There isn't any need for the import in the first place.

    Imports are compile-time occurrences only. Class load takes the same time
    regardless, and is on demand. If a class is used, it's loaded at runtime.

    If the "just one" class uses any of the other classes in that package, they'll
    get loaded on demand, too.

    Classes don't have directories, they have packages. Class *files* are stored
    in directories, though not necessarily.

    --
    Lew
    Lew, Jun 19, 2010
    #3
  4. On Sat, 19 Jun 2010 08:49:33 -0700, Sal wrote:

    > I have a directory that contains many classes in the same package and a
    > program that uses just one of those classes. Is there any advantage to
    > moving that program outside the directory and import only the class it
    > needs over keeping it in the directory and making it part of the same
    > package, eliminating the need for the import?


    I'd say its fine the way it is provided that the classes are only used by
    one or more programs that are all part of the same package. If the list
    of classes is large there may be a case for leaving the program(s) where
    they are and making the classes into an inner package but I'd only do
    that if it will make maintenance, etc. easier. Of course, if other
    programs are likely to use the same classes, then there's a clear case
    for moving the program somewhere else so the package is purely a class
    library.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
    Martin Gregorie, Jun 19, 2010
    #4
  5. Sal

    Roedy Green Guest

    On Sat, 19 Jun 2010 08:49:33 -0700 (PDT), Sal <>
    wrote, quoted or indirectly quoted someone who said :

    >I have a directory that contains many classes in the same package and
    >a program that uses just one of those classes. Is there any advantage
    >to moving that program outside the directory and import only the class
    >it needs over keeping it in the directory and making it part of the
    >same package, eliminating the need for the import?


    If you just want to use the class as is, there is no advantage. If
    you moved it, you could access the default scope methods and
    variables.

    However, cloning a class is generally a very very bad thing to do. You
    will update one and forget to update the other.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    There is no harm in being sometimes wrong especially if one is promptly found out.
    ~ John Maynard Keynes (born: 1883-06-05 died: 1946-04-21 at age: 62)
    Roedy Green, Jun 28, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parvinder
    Replies:
    6
    Views:
    745
    Thomas G. Marshall
    Feb 27, 2005
  2. Dave
    Replies:
    2
    Views:
    467
  3. George P
    Replies:
    3
    Views:
    680
    Alex Martelli
    Sep 11, 2004
  4. Crouchez

    Import efficiency

    Crouchez, Dec 17, 2007, in forum: Java
    Replies:
    7
    Views:
    980
    Crouchez
    Dec 18, 2007
  5. Gabriel Rossetti
    Replies:
    1
    Views:
    495
    ryles
    Sep 20, 2009
Loading...

Share This Page