• Post Reply Bookmark Topic Watch Topic
  • New Topic

why not convert java directly to binary?  RSS feed

 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand the advantages of bytecode, but wouldn't it be cool to tell the compiler to convert your code to machine code or bytecode as you wish?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. I rarely deploy on the same OS that I develop upon. The platform independence of byte code is crucial for me.
 
Joe Bishara
Ranch Hand
Posts: 175
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is platform independent because when you compile Java source code to bytecode, the compiled code can run on any platform (since bytecode is platform independent).

If Oracle allows the Java compiler to compile Java source code to machine code, the compiled code cannot run on any platform (since machine code is platform dependent).
 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes but it would be useful for development boards like the arduino where you don't have much memory for a jvm, right?
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice thought, and yes it's possible and has been done.
Oracle's Hotspot JVM goes for a JIT (Just In Time) strategy, but there are other JVM's that take an AOT (Ahead of Time) compilation strategy. http://www.excelsiorjet.com/ is one example.

But I don't agree that you can do away with the JVM itself. Even if your java code is compiled into native machine code, it still needs all the stuff JVM provides other than JIT compiler - things like memory allocation, GC, thread synchronization primitives, class loading, reflection, management counters.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, with native compilation, all that could be compiled into the resulting binary. Oracle is actually planning something similar for Java 9, where you can create a deployable that's a subset of the JVM (including its own java.exe on Windows). It's not a binary though.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Well, with native compilation, all that could be compiled into the resulting binary.

But the memory used by the JVM to store all the state that enables it to provide those additional services can't be avoided, even if the JVM's code was linked along with the app into a single binary.
I think OP's assumption was that compiling to native code would avoid the JVM's memory footprint, making it suitable for low memory devices like Arduino.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a VM for devices like the Arduino.

And a Raspberry Pi is really cheap. Which is a real computer on a board.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!