• 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

Really beginner question

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When doing just java Shuffle1 I'm getting the next attachment
Capture.JPG
[Thumbnail for Capture.JPG]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).......
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go through this tutorial first. It should help you getting started.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay Hale,
Your post was moved to a new topic.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic