• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Suspected class path problem

 
Linze marin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Linze
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I do not understand you very well, but I do this as follows

compilation
C:\java\test\>javac HelloWorld.java
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.
 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Regards
Sandeep Jindal
 
Linze marin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is precisly what I would like to have happen:

compilation
C:\java\test\>javac HelloWorld.java
and running
C:\java\test\>java HelloWorld

This is what is actually happening:
compilation
c:\java\test\>javac HelloWorld.java
and running a DIFFERENT VERSION found on:
c:\java

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

Linze
 
Adrian Marti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Adrian
 
Linze marin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to be a bother,

I just set up the classpath to read:
c:\java;.;
(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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. It sure seems obvious now that
you describe is so well.

Thanks, Linze
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic