• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Problem Compiling

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone I'm TOTALLY new to Java/programming in general...

I typed in this source code:




However whenever I try and run it in the Command Prompt I don't get anything (I navigate to C:\(my java source file directory) javac MyFirstApp.java and press enter but nothing happens, the command prompt just shows C:\(java source file directory) again)

I already set the PATH environment variable. Before I did that I was getting an error.

Any help will be appreciated
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to have look if the .class file has been created. Usually if the compilation is successful you don't get any message. Only if there are compilation errors would you see some messages.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Mohamed said, type "dir" and see if the class file was generated.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Please UseCodeTags when you post source code.

After successfully compiling your program with javac, you should have a file named MyFirstApp.class in your directory. You can then run your program with a command like this:

java MyFirstApp

You can find good tutorials here; especially have a look at the Getting Started tutorial which explains in detail how to write your first Java app and how to compile and run it, and explains common errors and their solutions that you might run into.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:
You can find good tutorials here; especially have a look at the Getting Started tutorial which explains in detail how to write your first Java app and how to compile and run it, and explains common errors and their solutions that you might run into.


There's also a tutorial at the ranch
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A quick way to check if your classpath has been set properly - type javac and press enter on comman prompt in your source directory.
If it shows you - command not found, you may want to check your classpath otherwise as Mohamed said " type dir and check the class file".
 
Marshal
Posts: 76462
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

You have had some good advice, probably the best being from Mohammed Sanaulla:

. . . Usually if the compilation is successful you don't get any message. . . .

The stony silence of the compiler when all goes well can be a bit disconcerting at first, but the simplest thing to do is assume all is well and proceed to the command Jesper told you about.
I have added code tags, since you are new, and you can see how much better the posting looks.
 
T Dreezy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone I finally got it to work!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, you can make him talk by using "javac -verbose MyFirstApp.java".
 
I AM MIGHTY! Especially when I hold this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic