16

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

3
  • 9
    What are you actually asking ?
    – nos
    Jan 22, 2010 at 21:29
  • 6
    I personally feel that this should not have been closed (voted to reopen). The question may be thinly formulated but there is a real question in there (even though the answer may seem obvious at first sight to some). Jan 22, 2010 at 21:41
  • @ChristopheD - could you please clarify the question?
    – KatieK
    Nov 29, 2012 at 4:32

15 Answers 15

22

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.

5
  • 2
    Actually, several JVMs are written in Java: Maxine and Jikes are just two examples. Jan 23, 2010 at 5:18
  • 2
    Because a small platform dependant C loader is required to launch the bootstrap, no matter what anyone says, the JVM is not 100% java :) Jan 25, 2010 at 14:21
  • 1
    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. Jan 26, 2010 at 10:39
  • 1
    Maxine, specifically contains C in only three places: a small bootstrapper, which does nothing but mmap the VM image, write the mmapped 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. Jan 26, 2010 at 10:44
  • 2
    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. Jan 26, 2010 at 10:46
22

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

JVM translates bytecode into machine language

Every Java program is compiled into an intermediate language called Java bytecode. The JVM is used to both translate the bytecode into the machine language for a particular computer, and actually execute the corresponding machine-language instructions as well. The JVM and bytecode combined give Java its status as a "portable" language.

Machine language is OS dependent

Given the previous information, it should be easier to deduce an answer to the question. Since the JVM must translate the bytecode into machine language, and since the machine language depends on the operating system being used, it is clear that the JVM is platform (operating system) dependent. This fact can be verified by trying to download the JVM – you will be given a list of JVM’s corresponding to different operating systems, and you will obviously pick whichever JVM is targeted for the operating system that you are running.

Quoted from Is the JVM Platform Dependent?

0
19

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.

10

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.

5

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.

4

No, JVMs are not platform independent. In fact they are platform specific run time environment provided by the vendor. Each platform (Windows, UNIX, Mac etc) has its own JVM to run Java applications. Although the byte code supports connection to multiple databases..

Think of Music being played in a MP3 player, CD player and old faithful cassette players(Boom Box). The output is always the same, ie music. But the input (media ie .mp3 files for MP3 Players, CDs for CD Players and cassettes for Cassette Players) vary depending on the system [here the systems will be the various Operating Systems like Windows, UNIX, Mac etc..]. Hope i was able to solve your problem..

1

JVM depends on operating system. For the code to be independent, something should be dependent and that is JVM. While downloading JDK it asks for which OS you want to download it for. Which clearly implies that JVM is platform dependent.

1

The JVM is not platform independent

The key here is that the JVM depends on the operating system – so if you are running Mac OS X you will have a different JVM than if you are running Windows or some other operating system. This fact can be verified by trying to download the JVM for your particular machine – when trying to download it, you will be given a list of JVM’s corresponding to different operating systems, and you will obviously pick whichever JVM is targeted for the operating system that you are running.

0

simply like - * - makes a +.

We all know Java is platform independent

but OS where we write the code is platform dependant

and Output should be platform independent so, we make jvm (which is in-between and installed with jre) platform dependent so that the output is independent.

1
  • Sort of. The language is platform independent, but it somehow must run on said platform. The machinery to do that will depend on the platform where it runs.
    – vonbrand
    Feb 21, 2013 at 13:48
0

I think that it could be platform independent if many different languages (each one written in specific different platform )where combined to make it change its own code dynamically.But all these take some great effort to happen and maybe destroy its portability.

0

JVM translate the byte code which is universal to machine code which is machine dependent hence JVM is platform dependent. Due to this byte code java is platform independent.

0

No, JVM is platform dependent. The code written in Java is not platform dependent. If you write Java code on a Windows operating system you can run that code on Linux or other operating Systems. But the JVM for Windows and Linux is different. JVM are found in JRE and when you download JRE from Oracle it says JRE for Window, Linux and other operating systems

0

JVM is platform dependent because it takes java byte code and generates byte code for the current operating system. So Java software is platform dependent but Java language is platform independent because different operating system have different JVMs.

0
0

JVM

Hope this image can make it clear. When you install java on your machine, you are asked to select your OS. That means java to be installed on a Windows machine is not the same as the one on a mac. Java installation comes with JDK, JRE, and JVM that are OS-specific.

JDK has a compiler that converts your Java code to bytecode and bytecode is platform-independent. JVM can read this bytecode and using an interpreter convert them to OS-specific instructions which vary based on your OS.

All JDK, JRE, and JVM are platform-dependent. But JAVA is platform-independent because bytecode is platform-independent.

Content summarized from here

0

It is platform-independent. Because java has bytecode it is platform-independent. So, when it writes once run everywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.