compiling java

Discussion in 'Mac Apps and Mac App Store' started by purduematt, Oct 13, 2003.

  1. purduematt macrumors newbie

    Joined:
    Jul 17, 2002
    #1
    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
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #3
    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.
     
  4. purduematt thread starter macrumors newbie

    Joined:
    Jul 17, 2002
    #4
    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
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    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.
     
  6. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #6
    .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?
     

Share This Page