1

Nowadays, I've started hearing a lot about Java. I know that its because its meant to be cross platform. But is it really?

How much can we trust the client to have JVM installed? I've quite a few books on Java in my home and really wish to read them. But every time the same question strikes me. Will the apps which I develop with Java run on most of the machines? Isn't that bad?

One way out is to use some compilers to compile Java code to native machine code. But this makes me feel, "Why use Java then?"

So, Is it worth to learn Java for cross platform? Any ideas regarding the percentage of people having JVM installed?

Tanay Karnik
  • 424
  • 6
  • 19
  • 4
    see here http://stackoverflow.com/questions/2748910/how-is-java-platform-independent-when-it-needs-a-jvm-to-run – ashiquzzaman33 Sep 19 '15 at 08:49
  • You will understand the value of Java only if you have a project that needs to be run on different platforms and to make this happen you need to write the project with C and G and Objective C three times, come back afterward and say what do you think about Java – Iman Nia Sep 19 '15 at 09:34
  • The idea of the JVM is that Java developers write code only once and the authors of Java do the work of writing JVM implementations for each platform. – Louis Wasserman Sep 19 '15 at 16:42

4 Answers4

1

I would like to correct you, People dont require jre installed they require jvm.

Since Java only relies on JVM, it is platform independent (if the platform has JVM installed).

But the main thing is, That the programmer do not have to know specific knowledge of the Platform and program his application keeping one specific platform in mind. He just has to write code generate byteCode and rest part is handled by JVM, to run it on any other platform.

If you compare java with other language you will get the exact difference like in In c/c++ the source code(c program file) after the compilation using a compiler is directly converted to native machine code(which is understandable to particular machine on which u compiling the code). And hence the compiled code of c/c++ can not run on different OS.

Shailesh Yadav
  • 1,061
  • 1
  • 15
  • 30
1

Nowadays, I've started hearing a lot about Java. I know that its because its meant to be cross platform. But is it really?

Yes, Java is cross-platform - or, more accurately, portable. It runs on the most used architectures and platforms, often without modification, which makes it one of the most portable languages out there. (But keep in mind that you can write unportable code in almost any language and Java is no exception.)

How much can we trust the client to have JRE installed?

We can't, but that's almost never problem.

Most languages need runtimes in order to operate. The C language (and some of its derivatives, like C++) get away with the fact that the C runtime is often already installed in the OS.

For most other languages, we trust the end user to be at least willing (not even necessarily able) to install the required runtime in order to run our (and others') software. Most software these days (and this often includes C++ software) installs its required dependencies automatically in the installation script. If this isn't desirable for any reason, an alternative is to bundle (statically link) the runtime with the program when deploying it.

One way out is to use some compilers to compile Java code to native machine code. But this makes me feel, "Why use Java then?"

Not all languages that compile to native code are the same. They have different features, different tools, different libraries available, and so on.

In any case, make sure you're not confusing native compilation with static linking of any dependencies (runtime or libraries).

Even, tell me how much percent people have a JRE installed.

About 97% of enterprise computers and 89% of desktops in the USA are estimated to run Java.

Theodoros Chatzigiannakis
  • 28,773
  • 8
  • 68
  • 104
0

The client needs a JVM, not a JRE. They will run on almost all machines. I don't have a percentage but considering that pretty much every major OS has a JVM available to them, I would say around 95% (underestimation in my opinion). Java definitely does not have a limited audience so that shouldn't stop you from using Java.

Updated in light of Andreas' comment. I was under the impression that a lot of machines came pre-installed with Java. However, the JVM can be easily downloaded so you still don't have to worry too much about whether you're going to miss out on a large audience.

Sam
  • 1
  • 2
  • 2
    Windows doesn't come with a JVM, so I'd say your estimate of 95% is grossly overestimated. I don't think any of the desktop/laptop OS's come with one. Mac? No. Linux? No. – Andreas Sep 19 '15 at 08:49
  • I agree with what Andreas says. Since, JVM doesn't come pre-installed with any of the major OSes the percentage of people having JVM installed is pretty less. Atleast those people who are not experienced PC users don't have JVM installed. – Tanay Karnik Sep 20 '15 at 16:40
0

I think you mixed two different concepts:

Cross-platform: A program is considered to be cross-platform if it can run on different platforms without a need to recompile it.

Q: Is Java cross-platform?

A: Of course it is.

Native app: A program that runs on the targeted platform without a need to install, download any other software. Usually the program is compiled into a machine binary. However, it may in some definitions include programs/scripts that are not machine binaries, but the target it platform is guaranteed to run them with its built-in library/software.

Q: Can Java run on any platform without JVM?

A: No. JVM is not shipped with any platform that I'm aware of, so it needs to be downloaded and installed before any Java program can run.

One way out is to use some compilers to compile Java code to native machine code. But this makes me feel, "Why use Java then?"

It all depends on what you want to achieve. If you want to create native apps, drivers, etc, then Java is definitely the wrong tool. But if you want to create an app that can run on all platform without having to recompile it and create a version for each platform, then Java can be a good option.

So, Is it worth to learn Java for cross platform? Any ideas regarding the percentage of people having JVM installed?

Again, it really depends on what you want to achieve. Java is a good option for creating cross-platform apps and it is worth learning. However, there are other options that you may want to look into, compare, and decide which one to learn. C# is a great language, and just recently, Microsoft announced its plans to make it truly cross-platform, so it is another good option.

Most PCs have JVM installed. Theodoros Chatzigiannakis provided some statistics in his answer. But you shouldn't be too worried about the numbers. Those few who don't have JVM installed, will be willing to download and install it if they like your app.

Note: In the past, you could run apps written in C# on platforms other than Windows, but you needed a .Net Framework equivalent (e.g. Mono). With Microsoft recent announcement, we should be able to use Microsoft .Net Framework itself on other platforms. We will see how this will turn out.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55