Why is the JVM not platform independent, given tha

2020-06-03 00:30发布

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

标签: java jvm
13条回答
神经病院院长
2楼-- · 2020-06-03 00:57

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.

查看更多
Explosion°爆炸
3楼-- · 2020-06-03 01:01

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.

查看更多
在下西门庆
4楼-- · 2020-06-03 01:06

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.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2020-06-03 01:07

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.

查看更多
爷、活的狠高调
6楼-- · 2020-06-03 01:07

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?

查看更多
ら.Afraid
7楼-- · 2020-06-03 01:07

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..

查看更多
登录 后发表回答