Saturday, January 26, 2013

"Run" button explored



If you started like most java developers I've ever
met (and a lot of developers of other languages) you probably do most of your work in an IDE (Integrated Design Environment) such as Eclipse, RAD, NetBeans, Visual Studio, etc. These tools are great in many situations because they hide a lot of the mundane details of programming. All you have to do is click the little run button and suddenly your program shows you its output.

But have you ever stopped to wonder what that run button does? Let's take a look at javac and java.exe.

Inside of wherever your jdk is installed (Default is C:\Program Files\Java) you have a bin directory. It has a lot of files, but the two we're interested in are javac.exe and java.exe. These are the programs your IDE is using whenever you click run.

javac.exe is the program that takes the name of your source code file as a parameter and compiles it down to java byte code (a .class file).

Javac in action!
If your program has any syntax errors, javac will give you some output about what they were. If your program compiled correctly, you won't see anything on the command line. However, in the file where you saved your .java program, you will see a new file with the same name as your program and a .class extension.



Java is the program that actually runs your java code and gives you the output of your program.

Java in action

Why should you care?

As a programmer, no matter how experienced you are, every time you call a function that you didn't write, every time you click on a button, you should ask yourself, "What does this actually do?" Not only is it good to keep learning, but it will make you a much more effective programmer. For a programmer, computers are not magical or mystical like they probably are to your grandmother. They are tools. And we need to understand our tools.

No comments:

Post a Comment