Import (package? module?...)

R

R12y

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?
 
M

Monique Y. Mudama

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.
 
R

R12y

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.
 
M

Monique Y. Mudama

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top