This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Suspected class path problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Suspected class path problem" Watch "Suspected class path problem" New topic

Suspected class path problem

Linze marin

Joined: Jul 23, 2004
Posts: 12
I am a java beginner, attempting to teach myself the lang.
I think that I have a class path problem. My classpath is c:\java

when I write and execute a HelloWorld program in a directory
below c:\java (such as c:\java\test) I actually run the version in c:\java.

What do I need to do to fix this?

Second question: I am a procedural programmer who is struggling to
understand OOP. Can anyone recommend a book to me that helps me gain a better understanding of OOP specifically, and how to use classes and design
program logic using OOP?

Thanks much
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Maybe I do not understand you very well, but I do this as follows

and running
C:\java\test\>java HelloWorld

it works on current directory.
I think you don't need to setup classpath for such simple program as HelloWorld is. Class path should point to location where are the libraries which your code use.

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180

You can read the book "Thinking in Java" by Bruce Ecel. This book is for begineers, and in general an excelent book to start with.

Sandeep Jindal
Linze marin

Joined: Jul 23, 2004
Posts: 12
This is precisly what I would like to have happen:

and running
C:\java\test\>java HelloWorld

This is what is actually happening:
and running a DIFFERENT VERSION found on:

I know this, because the actual text printed out is unique in each version of the HelloWorld program.

Adrian Marti

Joined: Sep 07, 2004
Posts: 11
If u put . in ur classpath it will look for class files in the current directory so for example classpath=c:\java;.;

That should work i think.

Linze marin

Joined: Jul 23, 2004
Posts: 12
Sorry to be a bother,

I just set up the classpath to read:
(ending with: Semicolon dot Semicolon)

I then rebooted, and ran HelloWorld in c:\java\test
again, and the version in c:\java ran.

I am running this on a fairly new Dell D600 laptop,
running windows 2000.
I welcome any help and advice.
Thanks again, Linze
[ September 17, 2004: Message edited by: Linze marin ]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Of course.
The jvm searches the classpath for a HelloWorld.class and starts in C:\java.
Bingo - there is a HelloWorld.class!
It doesn't look further into your . dir, because it already found what it was searching for.

Rebooting your computer?
Even on windows you don't need to.
Redefine the classpath, and reopen a shell.
echo %CLASSPATH% and verify that it has changed.

For this atomic issue, you would set it to:

So it will look into the actual directory first.

I guess unsetting the classpath at all will be sufficient to run programs in the actual directory.

You may (un-)set the classpath temporary with:

but if you close your shell, it's lost.
Linze marin

Joined: Jul 23, 2004
Posts: 12
Thank you. It sure seems obvious now that
you describe is so well.

Thanks, Linze
I agree. Here's the link:
subject: Suspected class path problem
jQuery in Action, 3rd edition