• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting started  RSS feed

 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have downloaded Java 1.5 onto my Windows XP machine but am having trouble getting it to run. First, does anyone have any suggestions what text editor is best to use? Also, when I type % javac at the Windows C:\ command prompt, I get this error: "% is not recognised as an internal or external command"

if I type javac, I get this output: Usage javac <options> <source files>, etc.

Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

First, the "%" thing is a very common beginner mistake. Remember that Java is a cross-platform language, so it runs not only on Windows, where the command prompt looks like "C:\>", but also on UNIX and it's cousin Mac OS X, where the command prompt is... "%". You don't type it -- just pretend it says "C:\>".

Second, there are a lot of different opinions about what editor to use, but there are few disagreements that the ones that come with Windows -- Notepad and WordPad -- are both insanely poorly suited for programming. Head over to our IDEs forum, look at the threads over the last month or two, and you'll find several with titles like "what's the best IDE?" and "What editor to use?" There will be many recommendations. Pick any one, give it a try, and see what you think. But don't try to use Notepad. Seriously.
 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for your prompt replay and for the help, I have the path problem solved now and will go to look for a better editor. Any idea why this code won't run (it is from Head First Java): I am running it by typing java Iftest.java and get this error:""exception in thread "main" java.lang.NoClassDefFoundError IfTest/java""

class IfTest {
public static void main (String[] args) {
int x=3;
if (x==3){
System.out.println("x must be 3");
}else{
System.out.println("x is not 3");
}
system.out.println("This runs no matter what");
}
}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The argument to "javac" is a filename: "javac IfTest.java". This produces a new file named "IfTest.class". The "java" program uses this file to run the program. But the argument to java isn't the name of this file: it's the name of the class "IfTest". java.exe knows that to find "IfTest" it has to look in "IfTest.class". So you just type "java IfTest".
 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. Now, if I run javac IfTest.java, I get the error:
Iftest.java:9 package system does not exist
system.out.println("This runs no matter what");
(carrot sign)
1 error
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi -

Java is case-sensitive. Change the "system" on line 9 to "System", and you should be good:

[ October 22, 2005: Message edited by: Paul Santa Maria ]
 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Thanks, that worked to generate the IfTest.class file! Now, when I run the class file IfTest.class by typing java IfTest (or by trying java IfTest.class), I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: IfTest

Thanks again.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can type "dir" to check that the IfTest.class file was created. Make sure you are in the same directory that it is located in. Also, you need to check what the global CLASSPATH is set to. It should NOT be set at this point, so if it is, it may be causing this problem. Type "echo %CLASSPATH%" to see the value of this variable. Feel free to copy and paste the output here. We can help you from there.

Layne
 
Eric McIntyre
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also I should point out that the source you posted declares "class IfTest", which is much different from "public class IfTest". You'll discover what the difference is as you go through your book, but suffice to say for now that the JVM won't be able to run your class unless it is a public class.

Eric
 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eric and Layne! The IfTest.class was created ok, the problem was that CLASSPATH existed so I deleted it and now it runs fine! The code seems to run ok whether or not I use declare the class IfTest to public or if I don't. Now I can start to work on examples from the book, thanks so much.
[ October 23, 2005: Message edited by: Larry Reynolds ]
 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, that should have been Eric and Layne, my apologies.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eric McIntyre:
the JVM won't be able to run your class unless it is a public class.


As Larry has already found, this is not true.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Larry Reynolds:
Sorry, that should have been Eric and Layne, my apologies.


You can go back and edit your own posts when you make mistakes like this. Click on the pencil-and-paper icon to the right of your name.

Layne
 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Layne, done, thanks.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well good luck learning more Java. Please come back with more questions and we will continue to help you.

And Welcome to the Ranch!

Layne
[ October 24, 2005: Message edited by: Layne Lund ]
 
Eric McIntyre
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
As Larry has already found, this is not true.


Oops. I seemed to remember a limitation like this from Java 1.1. I did a test before I posted, but my own classpath wasn't configured correctly (oh, the irony). Sorry if I led anyone astray.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!