1

We call java as platform independent because java has a virtual machine, JVM, which can execute the bytecode independently in any platform.

But the JVM must be installed( or must reside) on that system.

Now, Why don't people create virtual machine like JVM for other existing languages and call those languages as platform independent?

Kawsar Ahmed
  • 433
  • 2
  • 12
  • It's not something that happens overnight. – Jeroen Vannevel Aug 23 '14 at 20:20
  • There are plenty of platform-independent languages. I was using virtual machines in 1976, and they weren't new then. – user207421 Aug 23 '14 at 20:21
  • Why is my question downvoted? That's why I'm a fresher in stackoverflow with reputation 1, right? It hearts me. – Kawsar Ahmed Aug 23 '14 at 20:28
  • Why would people want to create another language that works like Java and C# if there are already two great languages that work with VMs. There is no reason for that. – Lars Aug 23 '14 at 20:36
  • I can't speak for anyone else but I downvoted it because it is founded on a factual error, as noted in my previous comment. There have been virtual machines since the 1960s, and I personally have worked on around a dozen, years before Java was ever thought of. – user207421 Aug 23 '14 at 23:56

3 Answers3

2

I can think of a couple of reasons on top of my head:

It's lengthy

It takes time. You're basically creating 2 programming languages - the high-level language and intermediate language (bytecode). That means thinking of 2 designs, writing compilers, lexers, linkers and all accompanying tools. No one guarantees that it will get popular, especially because it has to compare against mature ones like Java, C# and alike. Then, you have to code it for every operating system out there, every file system and every similar variable dependency (not literally, but the more the better). Even Oracle isn't doing a perfect job, just see I/O, I remember I was wondering for quite a while what have I done wrong before discovering that File#renameTo is extremely unreliable.

You need to achieve really good performance

Meaning, you have to compile and optimize your code while executing it, without the user noticing. Like compiling it for the first time (to bytecode) wasn't enough. It's not something you can do overnight. And again you have to beat JVM, .NET, ART and many more already there.

Nonetheless, there are many virtual machines out there and probably more in the making. It's also easier to compile to the bytecode of the already-made VM, so you have e.g. Jython which works with JVM, but its high-level part is actually (very similar to) Python.

I'll add more as I remember.

EDIT: To clear this up, since you seem to be mixing up terms: you don't need a VM to make platform independent apps (you can compile them for every OS, etc) and not every VM works on every OS (e. g. .NET works only on Windows).

Luke
  • 1,284
  • 1
  • 12
  • 34
2

Platform independence is not directly related with having a Virtual Machine. Platform independent development means that the software you develop can run on multiple platforms. This can also be achieved with C or C++ for example when using multi platform libraries as QT or boost (whatever your purpose is). It has to be mentioned that C and C++ don't run in a Virtual Machine. Other languages like Java and the .Net languages like C# are translated to bytecode and run in a Virtual Machine. To run the bytecode on different platforms you need a VM for those platforms. So the Virtual Machine has to be developed for every specific platform.

And also you cannot simply create a Virtual Machine for C, it's simply not thought to run in a VM. You have both languages: those that run 'directly' and those running in a VM. And you can develop platform-independent software in both types of languages. To put it short: platform independence is not directly related to Virtual Machine (but of course instead of compiling a code once for every platform a VM requires only one compilation and allows direct execution on all platforms that have this VM, so having a VM makes things a bit easier.)

nomadSK25
  • 2,350
  • 3
  • 25
  • 36
Sjoerd222888
  • 3,228
  • 3
  • 31
  • 64
2

Most common languages do run in a virtual machine or interpreter, and are therefore platform independent, including Python, Ruby, Javascript, and more. The few languages that compile directly to machine are the more mature compiled languages, such as the venerable C and C++. Edit: also, the newer Rust and Go languages.

Virtual machines pay a performance penalty compared to machine code that was optimized for the particular system it was designed to run on. For further details about this, see this question.

James M. Lay
  • 2,270
  • 25
  • 33
  • Nonsense. Virtual machines were a 'solidified science' in the 1960s, and there are products still running today that are based on VMs designed in the 1960s. – user207421 Aug 23 '14 at 23:58
  • I suppose you're right. Smalltalk and Prolog both ran on VMs. I'll remove that first point so as not to mislead readers. – James M. Lay Aug 24 '14 at 18:16