Mark E Hansen wrote:You're not posting in the correct forum. You question is on beginner Java, so that would be a better forum.
Paul Clapham wrote:
Mark E Hansen wrote:You're not posting in the correct forum. You question is on beginner Java, so that would be a better forum.
Thanks Mark, let me move it there.
James O'Reilly wrote:
Paul Clapham wrote:
Mark E Hansen wrote:You're not posting in the correct forum. You question is on beginner Java, so that would be a better forum.
Thanks Mark, let me move it there.
Actually, the compilation works correctly and I am actually a 20 year programming veteran. I'm just a little confused as to why I can use the "javac" command and compile from a different directory than "C:\Sun\SDK\jdk\bin, but not execute the program as well. One cammand seems to work from a differnt directory than the above mentioned directory, but the other "java" command does not.'
James O'Reilly wrote:... but not execute the program as well. One cammand seems to work from a differnt directory than the above mentioned directory, but the other "java" command does not.'
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Vijitha Kumara wrote:
James O'Reilly wrote:... but not execute the program as well. One cammand seems to work from a differnt directory than the above mentioned directory, but the other "java" command does not.'
If you are running the "java" command from the directory where the class file resides and you don't have CLASSPATH defined it should work fine, by default it searches for the current directory for class files. But you can use "-cp" switch with java (i.e: "java -cp <PathToClassFile> <ClassFile>") to point to class files.
Non-English text deleted.Vijitha Kumara wrote:Please use English . . .
James O'Reilly wrote:Thank you for getting back to me Mark. I did not set the classpath at all. I will try it later on to see if it works. The confusing thing is that I am sitting in the direrctory where the class file resides when I type" java MyFirstApp" and I get an error. However I can compile from this directory just fine with all in the java commands being in another direcoty. One command works (the compile command), but the other doesn't (the run command). I will investigate the class path command though. I guess that is what I get for "jumping ahead". I just wanted to make sure that I could compile and run java programs before I started really readin the java book. Thanks!
Jim O
Mark E Hansen wrote:
James O'Reilly wrote:Thank you for getting back to me Mark. I did not set the classpath at all. I will try it later on to see if it works. The confusing thing is that I am sitting in the direrctory where the class file resides when I type" java MyFirstApp" and I get an error. However I can compile from this directory just fine with all in the java commands being in another direcoty. One command works (the compile command), but the other doesn't (the run command). I will investigate the class path command though. I guess that is what I get for "jumping ahead". I just wanted to make sure that I could compile and run java programs before I started really readin the java book. Thanks!
Jim O
When you compile, the CLASSPATH has to be set so the compiler can find any classes which the source being compiled depends on. Note that the class path automatically includes the built-in Java classes. When you run the application, CLASSPATH needs to be set so the Java VM can find any classes that need to be loaded - even if they're in the current directory. I suspect that the book you're reading will cover this in better detail.
James O'Reilly wrote:when I type" java MyFirstApp" and I get an error.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:
James O'Reilly wrote:when I type" java MyFirstApp" and I get an error.
it helps people help you if you tell us EXACTLY WHAT THE ERROR IS. Otherwise, folks are just guessing. are you getting a 'command not found' error? then it's a PATH issue or you don't have the JRE installed.
is it a 'class not found' erorr? then it could be a classpath issue.
Is it an exception at runtime? then it's something else. My point is that if you don't tell us exactly what the problem is, we're all just guessing, which is pretty much a waste of time.
Suggest when you open your command line and wriite something like thisC:\MyJavaWork > javac MyClass.java
C:\MyJavaWork > Java MyClass
Whatever the output from MyClass is ;)
C:\MyJavaWork >
That way you can easily get to your Java work directory, and calling the second line will get your there next time you need it.mkdir MyJavaWork
cd MyJavaWork
You aren't inconveniencing us or wasting our time, and there is nothing to say sorry about.James O'Reilly wrote:I don't wish to inconvienience you your or waste your time. Sorry for the trouble.
Campbell Ritchie wrote:
You aren't inconveniencing us or wasting our time, and there is nothing to say sorry about.James O'Reilly wrote:I don't wish to inconvienience you your or waste your time. Sorry for the trouble.
Ireneusz Kordal wrote:This kind of error is caused when you compile a source file with javac command that is newer version
than java launcher (java command).
Probably beside JDK there is also an older version of JRE installed on this computer,
and probably the PATH variable contains both references to the JRE/bin and JDK/bin directories,
but JRE/bin is earlier on the PATH than JDK/bin. So if you type javac command, you compile source with javac from JDK/bin
(javac command is only available in JDK/bin directory), but if you type java, the command from jre/bin is invoked.
Compare java & javac versions with commands:
javac --version
java --version
If this is the case, you can try to repair your environment manually, but I think the best and easiest remedy to this
is to completely uninstall/delete all versions of jre/jdk from your computer,
then download and install the latest version of JDK. Before renstalling check also:
- the PATH variable - remove all references to JRE/JDK,
- delete JAVA_HOME and JDK_HOME variables from the XP environment (if exist)
- it is also a good idea to remove java entries from the registry (run regedit, locate HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft and delete it),
and delete files from java cache (run start/run, enter %APPDATA% hit Enter, locate 'Sun' subdirectory and delete 'Java' subdirectory).
After this your machine should be completely cleaned from Java and you can install JDK again.
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Vijitha Kumara wrote:You may confirm the JDK version used by your system by "java -version" in the command prompt...
How long have you been using Windows? You definitely don't need to set the PATH at the beginning of each command window you launch. This isn't a Java issue, it is a Windows issue. However, this isn't the forum for basic Windows stuff. This is why I recommended a Windows for Beginners book earlier in this thread. It will teach you about topics like PATH, user environments, etc. - Without a firm understanding of such topics, you're going to have a real hard time.James O'Reilly wrote:I can live with typing PATH=C:\Sun\SDK\jdk\bin at the beginning of every windows command prompt session for the time being, if the JRE download of 5.0 doesn't fix the problem.
Campbell Ritchie wrote:The reason you are using a Java1.4.... file is that it is in the directory quoted first in the system PATH. I have already quoted the "common problems" link, which links to instructions about how to set your PATH.
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|