aspose file tools*
The moose likes Beginning Java and the fly likes I need Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I need Help" Watch "I need Help" New topic
Author

I need Help

Dennis Jensen
Greenhorn

Joined: Jan 04, 2009
Posts: 4
I got the head first java book. I havent even got past page 3 when it tells me to type this code, save it as a .java which I can't seem to be able to do. It still wants to save it as a .txt. Then it tells me compile it using javac. That is where I got really stuck. As soon as i double click it to start it pops up and goes away. Does anyone have any idea where I went wrong?
Thanks
Dennis
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

i think you are doing it in a wrong way(by clicking on java)
you have to do as.....(in windows)
go to command prompt(Ctrl+R, cmd) and navigate to jdk/bin
and once you are there you can create a file by the command
edit filename.java ( other wise you can you textpad or you can use IDE like NetBeans )
once you write the code in the file. save and exit.
Back in command prompt(jdk/bin)
use the command
javac filename.java to complie
after that , give the command,
java classname


SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

HI Dennis,

Welcome to JavaRanch!

1) Use "WordPad" rather than "Notepad" to edit your files; you'll find it a little more agreeable about saving them under the names you choose. You still probably want to change the Windows Explorer setting for "Hide file extensions" to "false" so that Windows, by default, shows you the real names of files. You're a programmer now, you need to know that information!

There are much better editors than Wordpad available for programmers; soon, you'll want to investigate your choices. A good editor is the programmer's best friend.

2) javac.exe is a command-line program. You have to actually run the Windows command shell CMD.EXE, navigate to the location of your files using the "cd" command, and then type the javac command; i.e., if your Java source file HelloWorld.java was in c:\Java, then you'd type something like this in cmd.exe:

cd \Java
javac HelloWorld.java
java -cp . HelloWorld

That last line (java space dash cp space dot space HelloWorld) will actually run the HelloWorld program you've written.

Hope this helps. I'm sure you'll want a few more details; c'mon back and ask your questions by replying right in this same thread, please.


[Jess in Action][AskingGoodQuestions]
Claude Cundiff
Ranch Hand

Joined: Mar 20, 2008
Posts: 78
What operating system are you using?

Suppose you are trying to run a "Hello World" program. After you write this, simply type Hello.java and save it that way.

Are you typing in statements in a text file and saving them as a .bat file?

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

James Tharakan wrote:navigate to jdk/bin


Do not do this! Do not follow this advice!

Do not save your source files in the "bin" directory inside your JDK installation. It's a very bad practice. Use something like "C:\Java" to store your source code, and just make sure that the "bin" directory of your JDK in on your PATH (as directed in the JDK install instructions.)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
Ernest Friedman-Hill wrote:HI Dennis,

Welcome to JavaRanch!
There are much better editors than Wordpad available for programmers; soon, you'll want to investigate your choices. A good editor is the programmer's best friend.
I agree: try NotePad++ or Notepad2 which both work on Windows and are much much better than Notepad.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
And please use thread titles which tell us more than "I need Help".
Dennis Jensen
Greenhorn

Joined: Jan 04, 2009
Posts: 4
Thank you for your help. I will try the things listed. As far as my system goes, I have Win XP. I will look up a better editor. I had just started and I was following the book to the T, unfortunately it doesn't say what if it doesn't work. And I will use better titles from now on.


Thanks
Dennis
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
You're welcome. I presume you have worked out how to run a Java program from the command line? If not, there is a lot about it in the Java Tutorials. Note the useful "common problems" page! You want the Hello World page for Windows. Don't use NetBeans at this stage.
Jacob Steingart
Ranch Hand

Joined: Mar 28, 2008
Posts: 63
If you are a beginner to Java, I have a few tips/ recommendations.

1. Get a text editor more programming oriented. I suggest jGrasp (natural habitat found here.

2. This might not seem deserving of its own number, but I feel rather strongly about this. Use a text editor, NOT some fancy IDE with modes that let you edit your GUI directly, etc. If you use one of these, you'll learn your IDE, not Java. (Also, jGrasp has compile and run buttons, life savers IMHO)

3. Take it easy. Learn OO. Build up to the hard stuff. Head First Java was a good pick. It was what I used to start Java myself.

4. Have fun! Unless you're programming for a job, which you shouldn't be if you're still at the Hello World stage, you're probably coding to learn/have fun. It can be frustrating at times.

So yeah, welcome to Java! As for compiling... I recommend jGrasp XD.


I never know what to put in my signature...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
Jacob Steingart wrote:If you are a beginner to Java, . . .
2. This might not seem deserving of its own number, but I feel rather strongly about this. Use a text editor, NOT some fancy IDE . . .
Yes, it does "deserve its own number." Useful piece of advice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I need Help