Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

HelloWorld.java Runs In Cmd Prompt, But Blank Result  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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:

 
Saloon Keeper
Posts: 5145
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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: 61753
193
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 5145
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 5448
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!