This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem Compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem Compiling" Watch "Problem Compiling" New topic
Author

Problem Compiling

T Dreezy
Greenhorn

Joined: Jan 25, 2011
Posts: 6
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
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

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.


Mohamed Sanaulla | My Blog
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

As Mohamed said, type "dir" and see if the class file was generated.


[My Blog]
All roads lead to JavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

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".


Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38031
    
  22
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

Joined: Jan 25, 2011
Posts: 6
Thanks everyone I finally got it to work!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

By the way, you can make him talk by using "javac -verbose MyFirstApp.java".
 
 
subject: Problem Compiling
 
Similar Threads
SOURCEPATH
Running Java Programs from the command prompt
Execution problems
Package
Javac.exe not staying open