Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

purduematt

macrumors newbie
Original poster
Jul 17, 2002
29
0
i checked the man pages on javac, but didn't find what i was looking for really. is it possible to compile a java program so that you don't have to type 'java program_name' to run the program, but rather just type 'program_name'? i think this might be called compiling to machine code, not to the .class extention, but i'm not sure. thank you,

matt
 
Not using the standard Java compiler. Compiling java code produces Java Bytecode that needs the Java interpreter to run. There are 3rd party products that can turn java into native code, although I'm not aware of any for OSX.
 
Apple allows you to create Mac OS X .app bundles, which allows them to be double-clicked to start. You can also double-click .jar files to start them. There is currently no native code mechanism from Sun or Apple, although IBM's jikes compiler may allow such a thing as IBM does this on their larger machines.
 
thanks for the comments. the reason i was asking was on the gcc java compiler home page (http://gcc.gnu.org/java/index.html) it says compile:

Java source code directly to native machine code,

Java source code to Java bytecode (class files),

and Java bytecode to native machine code.


i'm pretty new to this, so i was a little confused i guess. what is the difference between a .class file and a .jar file? what's the difference in compiling them?

thank you,

matt
 
A jar file is basically a zip file containing any number of class files along with a special manifest file. This is nothing to do with turning java source or bytecode into native code.
 
.jar is a Java ARchive file. You don't compile source code into one. You compile into the .class files and then, you tell the archive utility to build one. I build mine by using a utility, so I don't have to remember all the bits each time because the command line can be quite long and missing one thing makes a mess.

You have to watch out for the gcc bits sometimes. They announce things that don't always work well. They may have native code resolution but it may not run any better. Java execution will continue to improve as JIT compiler technology improves. Why deal with the hassle of re-compiling it everywhere you want to use it?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.