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 Java in General and the fly likes Compile with flags in Java 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 » Java in General
Bookmark "Compile with flags in Java" Watch "Compile with flags in Java" New topic

Compile with flags in Java

Robin Trietsch

Joined: Apr 09, 2011
Posts: 5

Hi all,

I'm learning Java with the book HeadFirstJava, but I don't completely understand how you can compile with flags.

%cd MyProject/source
%javac -d ../classes com/headfirstjava/

Where do you enter this? I believe it's not in the actual code. They give a lot of flags in the book, but they don't tell you how to use them.

Hope someone can help. Thanks.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11168

it depends on what operating system you are using. Many of us old-timers on windows call it a DOS prompt. Go to start->run. type "cmd" in the pop up, and you'll get a black box with something like


it is there that you enter the commands. If you are on a Mac, I can't help you. If you are on Unix/Linux, you should already know what they are talking about.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

If you're using Windows, you'll type in those commands in a command prompt window. If you don't know what a command prompt window is and how to use it, then you can find tutorials for it on the web.

Note: The "%" in those commands should not be typed in, that's not part of the commands.

On Mac OS X or Linux, you'd use a terminal window for the same commands. Some commands might have slightly different syntax on Mac OS X or Linux compared to Windows.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Nico Van Brandt
Ranch Hand

Joined: Mar 31, 2011
Posts: 66

These commands are executed in the background when you compile your code in your IDE like Netbeans/Eclipse/IntelliJ
You can also compile your code manually without the need of an IDE. That is what is described in the book.

Oracle Java SE6 Certified Programmer
Oracle Java EE5 Certified Web Component Developer
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11168

If you are just starting out, most folks around here would recommended not using and IDE like Netbeans/Eclipse/IntelliJ. There is enough to learn just with Java that adding in a behemoth like those make it that much harder - and often you end up fighting with the tool rather than the language.

Get a simple text editor (I use ConText, but search around and you will find plenty of recommendations for others) and compile your code by hand on the command line.
Robin Trietsch

Joined: Apr 09, 2011
Posts: 5

Thanks for your replies. I do understand now how to use these commands.
I agree. Here's the link:
subject: Compile with flags in Java
Similar Threads
printf(String, Object) and format(String, Object) methods
QuizCard source code
is always API correct?
Compiler warnings
What's the best book?