tags:

views:

315

answers:

5

Hi Just curious to know when java is made platform independent then are there any specific reasons JVM is made platform dependent..

+9  A: 

The JVM executes Java code, but is written in platform specific languages such as C/C++/ASM etc. The JVM is not written in Java and hence cannot be platform independent.

Chris Kannon
Actually, several JVMs *are* written in Java: Maxine and Jikes are just two examples.
Jörg W Mittag
Because a small platform dependant C loader is required to launch the bootstrap, no matter what anyone says, the JVM is not 100% java :)
Chris Kannon
You're right. Although the way those VMs tend to use C is more like a Data Description Language and not a programming language. They mostly rely on the C compiler to get the data structures laid out like the OS expects them and not so much for C's semantics. You could probably write a Java program which generates the correct memory layouts, but why would you? The platform's C compiler already contains all the nasty layout logic.
Jörg W Mittag
Maxine, specifically contains C in only three places: a small bootstrapper, which does nothing but `mmap` the VM image, write the `mmap`ped address into a specific location into the image and then jumps into a predefined location inside the image. The second place is the debugger: Maxine uses the platform's native debugging facilities, and the reason why they are written in C is because they are ripped from GDB, because the platform documentation is simply too horrible to write a debugger from scratch. And three is the very low-level threading code: Maxine uses native threads.
Jörg W Mittag
Actually, I forgot one: the JNI code also contains some C, since, again, it is mainly concerned with interoperating with C data structures, so using C as a data definition language makes sense. However, note the things that are *not* in the list: garbage collector, memory allocator, native compiler, native assembler. All of those are written in Java.
Jörg W Mittag
+6  A: 

The JVM must be platform dependent to allow your Java to run on the specific platform. A JVM for Windows will translate your Java into different system calls than a JVM for OS X.

FrustratedWithFormsDesigner
+3  A: 

Because there needs to be some way to convert the platform-independent application's Java calls to calls that are compatible with the underlying OS.

Neville Flynn
+5  A: 

Unless you have a CPU that can directly execute Java bytecode (there are such things) you need to be able to interact with the OS (for things like reading files, connecting to the network, displaying to the screen, etc...).

You can write a JVM in other languages (such as Java or JavaScript) but ultimately there needs to be something that can interact with the underlying OS.

TofuBeer
A: 

I found that this was a great answer to the question:

Is the JVM Platform Dependent?

aashish