• 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

println

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!");
}
}
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what command are you using at the command line to run the program?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Marshal
    Posts: 79239
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 23
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Marshal
    Posts: 79239
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic