• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

HelloWorld.java Runs In Cmd Prompt, But Blank Result

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have HelloWorld written and I am trying to run it in command prompt to test it out, but when I javac HelloWorld.java (in the correct directory) it runs for a second, and then a new command line pops up, without the "Hello World" text being displayed. I have JDK 10 installed.

My code:

 
Bartender
Posts: 11226
91
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
compiles your java file which should result in HelloWorld.class file being created.
will run the .class file.
 
Marshal
Posts: 82459
594
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please indent your code correctly. You don't need the empty lines, and lines 33 and 5 should be farther to the right. It might not make much difference now, but once you get into longer classes, you can cause yourself no end of confusion if you haven't got the code indented properly.
What do you mean by a “new commend line”? Do you mean a new window opens, or simply that the display goes back to the prompt. If it means going back to the prompt, that is normal. That is what you get after invoking javac: stony silence if there aren't any error messages. That is good, but it is only half the procedure. You need to invoke the main method, which you do with the java tool. The instruction is
java HelloWorld
Note there is no extension: that bit often confuses beginners.
 
Chad Dunlosky
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please indent your code correctly. You don't need the empty lines, and lines 33 and 5 should be farther to the right. It might not make much difference now, but once you get into longer classes, you can cause yourself no end of confusion if you haven't got the code indented properly.
What do you mean by a “new commend line”? Do you mean a new window opens, or simply that the display goes back to the prompt. If it means going back to the prompt, that is normal. That is what you get after invoking javac: stony silence if there aren't any error messages. That is good, but it is only half the procedure. You need to invoke the main method, which you do with the java tool. The instruction is
java HelloWorld
Note there is no extension: that bit often confuses beginners.



Thanks for the detailed post! I indeed got it working from another reply, I realize now the difference between javac and just java in cmd prompt. Everything worked like it should, but I think I'll use Eclipse to better practice java, even though there's nothing wrong with the command prompt, all guides I read have Eclipse as recommended.
 
Carey Brown
Bartender
Posts: 11226
91
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chad Dunlosky wrote:Everything worked like it should, but I think I'll use Eclipse to better practice java, even though there's nothing wrong with the command prompt, all guides I read have Eclipse as recommended.

Eclipse is an excellent tool but I caution against it for the short term. If you are just starting out with HelloWorld, using the command line will help you understand how the organization of a Java project works. Eclipse, of course, helps with this, but you may have trouble understanding errors in Eclipse without some of this background knowledge. Eclipse also has its own learning curve.
 
Chad Dunlosky
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Chad Dunlosky wrote:Everything worked like it should, but I think I'll use Eclipse to better practice java, even though there's nothing wrong with the command prompt, all guides I read have Eclipse as recommended.

Eclipse is an excellent tool but I caution against it for the short term. If you are just starting out with HelloWorld, using the command line will help you understand how the organization of a Java project works. Eclipse, of course, helps with this, but you may have trouble understanding errors in Eclipse without some of this background knowledge. Eclipse also has its own learning curve.



Ah okay, that's sort of what kept me from starting with it, I'd like to learn the bare bones of coding first before allowing programs to cut the edges off for me.
 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you read this? How to create your first program
 
Chad Dunlosky
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Have you read this? How to create your first program



Just took a look at it, I did not but I wish I had!
reply
    Bookmark Topic Watch Topic
  • New Topic