Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Really beginner question

 
Steve Grosz
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I am going through the O'Reilly Head First Java book, and am playing with the code sample below


When I try to run this from the command line I'm getting the error in the attached image.

Why is this?
Sorry for the basic question........
Capture.JPG
[Thumbnail for Capture.JPG]
Error
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to run it as "java Shuffle1" rather than "java Shuffle". We pass .java when compiling; not when running.

And welcome to CodeRanch!
 
Steve Grosz
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When doing just java Shuffle1 I'm getting the next attachment
Capture.JPG
[Thumbnail for Capture.JPG]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, this suggests something has set a CLASSPATH environment variable on your machine, which is telling Java to look elsewhere than your current directory for class files. You need to tell Java, "No, look RIGHT HERE!" Which you can do by typing:

java -cp . Shuffle1

(That's java space dash cp space dot space Shuffle1).

P.S. Did you compile the code first? If not, then before typing the above, type

javac Shuffle1.java

You need to do this every time you change Shuffle1.java .
 
Steve Grosz
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate all the help for this new Java guy, but I'm still having issues.......

I don't have a program called javac (searched Windows 7 and came up dry).......
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through this tutorial first. It should help you getting started.
 
Henry Wong
author
Marshal
Pie
Posts: 21498
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Grosz wrote:
I don't have a program called javac (searched Windows 7 and came up dry).......


Then there is a chance that you installed the JRE -- and not the JDK. The JRE is used only for running java programs, it isn't for development, and hence, doesn't include the compiler.

Henry
 
Steve Grosz
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did find it, had to modify the path.....

Now, now issue....... When I run javac Shuffle1.java, I'm getting:
Capture.JPG
[Thumbnail for Capture.JPG]
Capture
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is case-sensitive. String should be String, not string. System should be System, not system.
 
Steve Grosz
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, so thanks to EVERYONE who helped this newbie get his really exciting 1st program to work!!

So, Java is that picky that certain commands are case sensitive??? Wow........hopefully I get used to that!!
I'm just using Notepad right now, if I use something like Eclipse later on, will it make the change for me for those reserved words??
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Grosz wrote:if I use something like Eclipse later on, will it make the change for me for those reserved words??

It will tell you right away that it cannot find the symbol. It can help you fix it in most cases.

(by the way, in the previous case, these are not reserved words, but API classes)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15483
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Grosz wrote:So, Java is that picky that certain commands are case sensitive??? Wow........hopefully I get used to that!!
I'm just using Notepad right now, if I use something like Eclipse later on, will it make the change for me for those reserved words??

Yes, and fortunately it is case sensitive! Suppose that it wasn't, and people would start writing programs with the case of words differently each time. One time you'd write "System", the other time "system" or "SYSTEM", or "sYsTeM". It would make the program look very messy and make it really hard to understand.

IDEs like Eclipse have lots of built-in editing help features, like warning you if you make a typo.

The standard Windows Notepad is very basic. You could have a look at an editor such as Notepad++ (free), which has syntax color highlighting for Java (and lots of other languages) but not all the complication of a full IDE such as Eclipse.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50211
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree about Notepad++. Excellent product. Yes, Eclipse will help you correct such errors, but it is probably a good idea to stick to a text editor at this stage.
And in Java™, all commands are case-sensitive, except possibly the "L" or "F" you append to long and float numbers, and the "x" in hexdaecimal numbers.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50211
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Hale,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic