Java on Apple Machines

I am stuck trying to figure out what to do with a .java program on my mac. If I open up the file in a text editor, I can see the source code. Does this mean that the file needs to be compiled or do macs have a java compiler built-in?

thanks!

I can’t speak to Mac, but every other platform I’ve coded Java on (Windows, AS400, Sun) you had to run a .java file through the javac compiler.

Java is pretty platform agnostic, so I would assume that yes, you need to compile it.

OS X kind of has a Java compiler built in.
Xcode can compile Java programs, it come free with OS X but isn’t always in the standard install.
You should be able to install it from your original OS X cd’s if you have them.

I’ve no idea how much experience you have when it come to Java, but be aware that although it’s supposed to be platorm independent, compilng a Java program designed for another system isn’t always straightforward.

If you open a terminal window, navigate to the folder with the .java file, and type javac yourfile.java, it should compile. Then type java yourfile.class and it should work. Assuming ./ is in your path. If not, replace yourfile with ./yourfile

Note that javac won’t be installed by default; you’ll have to install the Developer Tools package from your OS X CD’s if you haven’t already done it.

Once you’ve got that, you’ll have standard commandline compilers available for just about everything, plus XCode which is super awesome.

javac worked without having purposely installed xcode…thanks!