aspose file tools*
The moose likes Beginning Java and the fly likes Really beginner question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Really beginner question" Watch "Really beginner question" New topic
Author

Really beginner question

Steve Grosz
Greenhorn

Joined: Jan 13, 2011
Posts: 7
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........



[Thumbnail for Capture.JPG]

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

You need to run it as "java Shuffle1" rather than "java Shuffle". We pass .java when compiling; not when running.

And welcome to CodeRanch!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Steve Grosz
Greenhorn

Joined: Jan 13, 2011
Posts: 7
When doing just java Shuffle1 I'm getting the next attachment


[Thumbnail for Capture.JPG]

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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 .


[Jess in Action][AskingGoodQuestions]
Steve Grosz
Greenhorn

Joined: Jan 13, 2011
Posts: 7
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

Go through this tutorial first. It should help you getting started.


[My Blog]
All roads lead to JavaRanch
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18103
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Steve Grosz
Greenhorn

Joined: Jan 13, 2011
Posts: 7
I did find it, had to modify the path.....

Now, now issue....... When I run javac Shuffle1.java, I'm getting:



[Thumbnail for Capture.JPG]

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Java is case-sensitive. String should be String, not string. System should be System, not system.
Steve Grosz
Greenhorn

Joined: Jan 13, 2011
Posts: 7
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Aug 16, 2005
Posts: 13868
    
  10

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36465
    
  15
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

Joined: Oct 13, 2005
Posts: 36465
    
  15
Jay Hale,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Really beginner question
 
Similar Threads
Head First Java - Is over complicated bad?
I thought I understood this stuff.....
While loop - Head's First Java example
Another Question from the book "Head First Java"
Exception in thread "main"