• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Suspected class path problem

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. It sure seems obvious now that
you describe is so well.

Thanks, Linze
 
reply
    Bookmark Topic Watch Topic
  • New Topic