Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classpath

 
Christopher Collier
Greenhorn
Posts: 22
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,
I've been ducking this issue for a while and it's finally caught up with me (and in Chapter 1 of my new book, no doubt).

This question applies to a Windows system (I dual-boot Linux, but I'm still learning it, so I code in Windows).

Also, I'm compiling with an IDE, not from the command line.

Anyways, the Bates/Sierra SCJP 6 book has tasked me with creating a package, which I was able to ignore in school because my professor didn't delve into package access at all. Specially, the question says to:

"Create a directory called food off the directory in your class path setting."

My question is simply, where is this? My system's classpath variable is listed as:

.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip

But my IDE lists the default classpath as C:\Program Files\Java\jdk1.6.0_23\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_23\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_23\lib\tools.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\ext\sunpkcs11.jar.

I know I should (and eventually will) switch everything over to my Linux partition. Also, I clearly had some trouble when I was installing the JDK. Still, I'd appreciate advice and thoughts on this. Thanks!
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

Creating package is nothing but creating directory in Java.

if you are not using IDE then just create directory "mkdir -p com/test" and now create a class call "HelloWorld.java" and in the top of this
file put "package com.test" and keep this find inside directory "com/test".

essentially package com.test tells Java compiler / interpreter to where to look for this particular file in classpath. In case if you classpath contains
current directory "." then Java will look for class called HelloWorld.class inside directory ./com/test/

so if you are using IDE its even simpler if you are using Eclipse then it gives you option of create a new package and corresponding directory get created inside "src" folder of your project directory in Eclipse workspace.

hope this would be useful.

if you like to read more about classpath you can check my blog post http://javarevisited.blogspot.com/2011/01/how-classpath-work-in-java.html
 
Christopher Collier
Greenhorn
Posts: 22
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That helps, thanks.

I read your blog and got a lot of useful information out of it. Good stuff.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic