Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Import (package? module?...)

Thread view: 
R12y - 23 Mar 2006 00:23 GMT
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?
Signature

Debian/apt Repo: http://locataire-serveur.info/sections/liens/debian-repository
Fedora/yum Repo: http://locataire-serveur.info/sections/liens/fedora-core-yum

Monique Y. Mudama - 23 Mar 2006 01:01 GMT
> Hi,
>
[quoted text clipped - 17 lines]
> "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.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

R12y - 23 Mar 2006 15:32 GMT
> 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.

Signature

Debian/apt Repo: http://locataire-serveur.info/sections/liens/debian-repository
Fedora/yum Repo: http://locataire-serveur.info/sections/liens/fedora-core-yum

Monique Y. Mudama - 23 Mar 2006 16:07 GMT
>> So, since my domain is bounceswoosh.org, a proper package name
>> might be 'org.bounceswoosh.grokulator' (assuming I have a
[quoted text clipped - 4 lines]
> 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.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.