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 Newbie question on javac 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 "Newbie question on javac" Watch "Newbie question on javac" New topic
Author

Newbie question on javac

Jose Kampilan
Greenhorn

Joined: Aug 04, 2012
Posts: 11
Hi.

I recently bought the Headfirst Java and it recommended this forum for questions regarding java.

Question: Is it correct to use the windows command prompt to access javac?

i'm not sure if what im doing with the command line is correct (or if thats the right tool i should be using). the picture of the command prompt in the book doesnt look similar to the command prompt i'm using. the one in the book has "File", "Edit", "Window", "Help" and uses the "%" sign. the command prompt im using is just a simple black screen, no buttons on the top just "C:\Users>" and doesnt recognize "%".

im more familiar with an ide but the book said that i shouldn't use one just yet.

Problem: when i, idk whats the term, run javac using the command prompt to compile a source file, it says it cannot find the file.

this is what i type: javac MyFirstApp.java. then it returns something like "file not found: MyFirstApp.java". Should i put the source file in a certain folder? It's currently on the desktop and not in any particular folder.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11166
    
  16

the cmd.exe is the correct place. I think the book tends to use the Mac/Apple OS for pictures, so don't let that worry you.

The file can be anywhere...but you have to tell the java compiler where it really is. By default, it looks in the 'current' directory - i.e. wherever your cmd window says it is. Generally, you would make something like a C:\java\projects directory, and put the .java file there.

I have a C:\slop directory I use. Then, I cd into it, and then just type "javac MyClass.java". If i was somewhere else, I could type "javac c:\slop\MyClass.java"


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Welcome to the Ranch

This is what I suggest about running the command prompt. I think, apart from the file name, it is the same as Fred suggested earlier.
Jose Kampilan
Greenhorn

Joined: Aug 04, 2012
Posts: 11
@fred: thanks man. what you said worked. also, i was encountering the "file not found" error because i was only putting the location of the folder. didnt know i was supposed to also include the file.

@campbell: this looks like a place friendly to newbies like me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie question on javac
 
Similar Threads
My first java program
Javac: File Not Found
error message in terminal
Very simple program from Head First is showing no output on print
Getting up and running with Javac