Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package Statment for Directories with a period in the name

 
Tim Moore
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have installed 1.4.2 on my machine. I have created a subdirectory called "work" to hold my work. The full path is c:\j2sdk1.4.2\bin\work. How do I specify that directory as a package name in my .java source files? Won't the periods in the directory c:\j2sdk1.4.2 create confusion in package statement? In the future, I plan to save my work to another directory that has no periods in the path name, away from the JDK directory, however, the question still remains. What do you think?
Thanks,
Tim
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tim Moore:
Hi,
I have installed 1.4.2 on my machine. I have created a subdirectory called "work" to hold my work. The full path is c:\j2sdk1.4.2\bin\work. How do I specify that directory as a package name in my .java source files? Won't the periods in the directory c:\j2sdk1.4.2 create confusion in package statement? In the future, I plan to save my work to another directory that has no periods in the path name, away from the JDK directory, however, the question still remains. What do you think?
Thanks,
Tim

If you are just going to be doing 'work' on your own and everything is going to reside in this folder, then a better structure would be to make subdirectories under your work folder for each project you are doing.
EX: c:\j2sdk1.4.2\bin\work\proj1
Then when you want to use a class from another project, all you have to do is:
import projX.*;
or
import projX.ClassName;
This is a benefit from setting your classpath.
However, if you are going to be distributing your 'work' to other people, then consider setting up a structure such as:
These examples
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Won't the periods in the directory c:\j2sdk1.4.2 create confusion in package statement?

Yes, according to my simple experiment.

>javac sdk1.4\util\Test.java
sdk1.4\util\Test.java:1: ';' expected
package sdk1.4.util;
^
1 error
But you could solve this problem, by skipping the sdk1.4 directory in the package name and including sdk1.4 in the classpath:

>javac sdk1.4\util\Test.java
>java -classpath sdk1.4 util.Test
util.Test
[ July 09, 2003: Message edited by: Marlene Miller ]
 
Tim Moore
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks for the input. It is appreciated.
Tim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic