Can I compile Java code into a UNIX executable as if it were Pascal?

Is there a way to compile Java code into a UNIX executable? I want to be able to run it without a JVM for better efficiency. I don't care if it's not cross-platform, I don't feel obligated to support Windows...

iMac6,1 (Late 2006 iMac Intel), 3 GB RAM, 2.33 GHz Processor, 2 TB internal HD, Mac OS X (10.5.8), Minor GUI mods, a lot of stuff connected with FireWire or USB

Posted on Oct 2, 2011 11:22 AM

Reply
10 replies

Oct 2, 2011 11:46 AM in response to Mac OS 9000

Creating "Native" Java Applications on Mac OS X

If you develop on Mac OS X you can use the

Jar Bundler
application to turn jar files into Mac OS X applications.
Jar Bundler
is distributed with the other developer tools and is located in
Developer/Applications/
.


http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac3/


I think that's about as close as you can come... no expert though. 🙂

Oct 2, 2011 5:28 PM in response to Mac OS 9000

Cross-compilers do not exist (well, not *really*) for Java to C for several reasons. The biggest reason the the way that each language handles memory. I have used both, so I can tell you from experience.


C has two types of in-memory data:


  • Pre-defined variables
  • Dynamically allocated memory from the "heap".


"Heap" is a large amount of memory that is created when a program in loaded into "active space". In essense, every C program runs in a "virtual machine" created when you run it. C programs often "dynamically allocate" more memory as it needs it. But the original programmer had to be very careful about cleaning up after memory it allocated -- free it when no longer in use. Also, C programs can overwrite its own "non dynamic" variables because C does not have any mechanisms to "stop at defined size".


In short, C is a world of landmines, especially concerning memory.


Java was supposed to fix that.


The JVM is a world that manages its own memory. It has several advantages over C:


  • Memory for every variable comes off the "heap"
  • Memory for variables that have no more "references to them" are eliminated (called "garbage collection")
  • The sizes of all variables are known all along, so no variables can be ovewritten.


Java was also created to always use the same "low-level code". Whether it runs on Windows, Mac, Linux the "program" can be the same and the JVM handles the translation into the "machine-level" code reauired to run.


C code *MUST* be in the machine-specific code that each specific class of CPU knows. PowerPC is the prime example: PPC apps are compiled for a chipset that no longr is made, so a "virtual machine" (Rosetta) is required to execute it.


There is no good way to bridge that gap between "manually managed memory and machine-specific pre-compiled instructions" and "JVM with commonly-used intermediate language codes".


Sorry.


If you did start to learn to re-write in C, you have a fairly steep leraning curve.

Oct 2, 2011 6:12 PM in response to steve359

Oh, I didn't recommend C, nor have I recommended it since 1985 with my 1st encounters on Atari with it, I mean kudos to those that can use it, but I cannot & will not, Assembly is far easier for me, and sometimes placing things on the Stack is in order, but not most times like C did/does(?).


All I was tyring to say is Java Is Java, it'll only run in a JVM unless you convert it painfully, or there was such a cross compiler, of which the last one I used was Z80<->X86, & just more trouble than it was worth. 🙂

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can I compile Java code into a UNIX executable as if it were Pascal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.