Import (package? module?...)

Discussion in 'Java' started by R12y, Mar 22, 2006.

  1. R12y

    R12y Guest

    Hi,

    I have a homework to do and I want to try a "test driven" programming.
    The treeview of the project is like this:

    $HOME/
    src/
    Pair.java
    tests/
    Tests.java


    Suppose in Pair.java there is a function:

    public static int generatePairNumber(void)
    {
    ...
    }

    I need to test this function in Test.java, but dont know the usage of
    "importing". How should I?
    What keyword should I use to find the solution?
    --
    Debian/apt Repo: http://locataire-serveur.info/sections/liens/debian-repository
    Fedora/yum Repo: http://locataire-serveur.info/sections/liens/fedora-core-yum
    R12y, Mar 22, 2006
    #1
    1. Advertising

  2. On 2006-03-22, R12y penned:
    > Hi,
    >
    > I have a homework to do and I want to try a "test driven" programming.
    > The treeview of the project is like this:
    >
    > $HOME/
    > src/
    > Pair.java
    > tests/
    > Tests.java
    >
    >
    > Suppose in Pair.java there is a function:
    >
    > public static int generatePairNumber(void)
    > {
    > ...
    > }
    >
    > I need to test this function in Test.java, but dont know the usage of
    > "importing". How should I?
    > What keyword should I use to find the solution?


    You need more than one piece of the puzzle.

    My bet is that currently you don't specify a "package" in either of
    your java files. That means they're both in the "default package,"
    and I don't think you'll be able to use import successfully.

    Package statements go on the very first line of a file. So you could
    add 'package src;' to the top of Pair.java and 'package tests;' to the
    top of Tests.java. Then you would add 'import src.Pair;' to Tests.java
    between the package statement and the class definition.

    Strictly speaking, packages should follow a naming convention that is
    unique to you. The preferred convention is to use a reversed domain
    name. So, since my domain is bounceswoosh.org, a proper package name
    might be 'org.bounceswoosh.grokulator' (assuming I have a grokulator
    application) or 'org.bounceswoosh.lib' (for common stuff).

    Hope that's slightly clearer than mud.

    --
    monique

    Ask smart questions, get good answers:
    http://www.catb.org/~esr/faqs/smart-questions.html
    Monique Y. Mudama, Mar 23, 2006
    #2
    1. Advertising

  3. R12y

    R12y Guest

    On Wed, 22 Mar 2006 17:01:59 -0700, Monique Y. Mudama wrote:

    > So, since my domain is bounceswoosh.org, a proper package name
    > might be 'org.bounceswoosh.grokulator' (assuming I have a grokulator
    > application) or 'org.bounceswoosh.lib' (for common stuff).


    Could this be the unix domainname of the machine (localdomain by default)?
    I also heard about CLASSPATH, but dont like it since it could not be
    useable on another machine.

    --
    Debian/apt Repo: http://locataire-serveur.info/sections/liens/debian-repository
    Fedora/yum Repo: http://locataire-serveur.info/sections/liens/fedora-core-yum
    R12y, Mar 23, 2006
    #3
  4. On 2006-03-23, R12y penned:
    > On Wed, 22 Mar 2006 17:01:59 -0700, Monique Y. Mudama wrote:
    >
    >> So, since my domain is bounceswoosh.org, a proper package name
    >> might be 'org.bounceswoosh.grokulator' (assuming I have a
    >> grokulator application) or 'org.bounceswoosh.lib' (for common
    >> stuff).

    >
    > Could this be the unix domainname of the machine (localdomain by
    > default)? I also heard about CLASSPATH, but dont like it since it
    > could not be useable on another machine.


    Well, the idea is that your package structure is unique. I think
    that's why the reversed net domain is used; the theory (however
    optimistic) is that a domain will remain attached to you for as long
    as the package remains relevant.

    Maybe the top entry here will help a little:

    http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html

    But this is really only important for big apps that might see the
    light of day. There's no harm in creating an impromptu package
    structure when you're just learning the language and running test
    apps.

    --
    monique

    Ask smart questions, get good answers:
    http://www.catb.org/~esr/faqs/smart-questions.html
    Monique Y. Mudama, Mar 23, 2006
    #4
    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.

Share This Page