Is java really platform independent ?

There are different versions of JVM for different operating systems/platforms. Which means that the people who developed it have made different interpreters for major operating systems. If at all a new OS comes today will java work on it too? So When we say platform independent are we restricting to platforms for which JVM is available or is Java actually platform independent?

Upvotes: 3

Views: 4390

Answers (7)

ganeshjmore
ganeshjmore

Reputation: 51

I don't think that Java is completely platform independent.

Because:

  1. Threading schedule time slices of work depend upon processor, OS and the platform.

  2. AWT Graphics change as per the output devices changes so it shows platform dependency.

Upvotes: -1

Manish Gadhock
Manish Gadhock

Reputation: 163

In short: Without JVM, you can not interpret the java code on any platform. JVM is a platform-dependent. So if a new OS comes today,the java code wont run.

Upvotes: 1

rai.skumar
rai.skumar

Reputation: 10667

There are different aspects which needs to be considered :

JVM specification is not very strict on platform independence, like it doesn't say how you should implement garbage collection. So companies are free to have some component of JVM as platform dependent for optimizing performance. So JVM which executes the compiled code is not platform independent. You need JVM specific to that platform i.e. windows JVM, linux JVM, Mac OS JVM etc and there are different implementations of JVM for the same platform.

But Java API, Java Language and Java Compiler are platform independent.

Upvotes: 2

user207421
user207421

Reputation: 310913

You're conflating several distinct things here.

It is the Java Programming Language that is platform independent, and, by extension, any program written in it.

The JVM itself is not platform independent: it is the platform-dependent means via which platform-independence of the language is realized.

Upvotes: 7

timday
timday

Reputation: 24892

Obviously without a JVM you have no chance of executing bytecode. This question got me wondering how difficult it actually is to port the JVM to a new platform though. Wpedia has (re the HotSpot VM):

Ports are also available by third parties for Mac OS X and various other Unix operating systems. Several different hardware architectures are supported, including x86, PowerPC, and SPARC (Solaris only).

Porting HotSpot is difficult because the code, while primarily written in C++, contains a lot of assembly language. To remedy this, the IcedTea project has developed a generic port of the HotSpot interpreter called zero-assembler Hotspot (or zero), with almost no assembly code. This port is intended for easy adaptation of the interpreter component of HotSpot to any Linux processor architecture. The code of zero-assembler Hotspot is used for all the non-x86 ports of HotSpot (PPC, IA64, S390 and ARM) since version 1.6.

Gary Benson, an IcedTea developer, developed a platform-independent Just-in-time compiler called Shark for HotSpot, using LLVM, to complement zero.

Upvotes: 2

Joachim Isaksson
Joachim Isaksson

Reputation: 180917

With Java, platform independence only refers to the fact that if you write your code correctly, the resulting compiled code should run unchanged and identically on any platform that supports the JVM.

Upvotes: 2

Publius
Publius

Reputation: 1224

Clearly Java cannot run on a platform that doesn't have a JVM. So in the most literal sense of the word, Java isn't platform independent. But at the same time, your definition of platform independence isn't useful. No possible language could ever be truly platform independent, because some aspect of the platform would need to be able to parse the language. And given all possible platforms, some necessarily won't be able to parse it.

So, given the fact that many, many platforms run a JVM, and that Java code can be run on any JVM with the same meaning, Java is platform-dependent.

Upvotes: 6

Related Questions