• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

I need Help

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.)
 
Marshal
Posts: 80749
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 80749
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And please use thread titles which tell us more than "I need Help".
 
Dennis Jensen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80749
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 80749
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic