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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "println" Watch "println" New topic
Author

println

David McHugh
Greenhorn

Joined: Oct 01, 2008
Posts: 23
really basic one this folks! i created a simple helloworld.java program and it works ok with no errors but it does not display hello world, just goes to a new prompt? i have tested another wrong script and it throws back errors, so it is compiling ok, any ideas?

this is the code, i am using vista business sp1 and jdk1.6.0_07

/*
* HelloWorld.java
*
* Created on 01/10/2008
*/
class HelloWorld {

public static void main(String args[]) {
System.out.println("Hello World!");
}
}
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
what command are you using at the command line to run the program?


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11495
    
  16

please check our Naming Policy, and follow the links there to update your screen name. Accounts that don't meet our requirements can and will be disabled.

Your code works just fine for me, printing "Hello World!" to the screen.

how exactly are you running this? from an IDE or from the command window?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
David McHugh
Greenhorn

Joined: Oct 01, 2008
Posts: 23
i am typing,

javac helloworld.java

from the windows command prompt,

c:\program files\java\jdk1.6.0_07\bin>

and it just returns the following on the line underneath??

c:\program files\java\jdk1.6.0_07\bin>
Sue Ambekar
Greenhorn

Joined: Sep 24, 2008
Posts: 1
you need to see if the HelloWorld.class file exists in your directory or not and then give the command
-->java HelloWorld

This should show you the output.
David McHugh
Greenhorn

Joined: Oct 01, 2008
Posts: 23
hi sue,

there is no helloworld.class file in the directory, when i do java helloworld it works fine! cheers.. can you explain why i was told to type javac helloworld.java??? is that for more complex apps with seperate class files???
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Sue, welcome to JavaRanch

Darryl: There are two stages to running a Java class
  • Compile it to bytecode with the javac command
  • interpret and execute the bytecode with the java command.
  • You are reminded that the java command takes the file name without its extension.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 40034
        
      28
    By the way, why are you keeping your files in the bin directory? You ought to create another directory elsewhere for .java and .class files. The bin directory should be reserved for executable files included in the JVM.
    David McHugh
    Greenhorn

    Joined: Oct 01, 2008
    Posts: 23
    thanks for all the info guys. I was aware it was a two step approach to get it to work, i thought it was done automatically!! a bit wet behind the ears still.. I will move my files to a different folder, i was getting a bit frustrated at setting up the environment so i went straight to the root!!

    Just one more thing, i have downloaded the free version of jcreator and it seems quite easy to compile programs, would this be better than using the command prompt???

    Cheers
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 40034
        
      28
    Difficult to be sure; I used to use JCreator a bit like a posh text editor and save the files and compile them from the command line; that was before I realised JCreator would compile them for me!
    Most of us recommend not using an IDE when you are beginning because you need to get used to the command line and also there is enough of a learning curve with Java without having to learn an IDE as well. There are several text editors which work on Windows and are far better for programming than NotePad, eg NotePad2, NotePad++. These two are related to each other but not at all to the original NotePad.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: println