Is the JVM a part of an OS or package? - java

I know Java Virtual Machine is used to run a java program independent of the OS.But can anyone tell me if JVM is the part of OS or a package.

Depends on your definition of OS, your definition of package and your actual OS.
Some OS vendors ship a JRE or JDK as part of their OS install in eigter core or extended sets. They all ship it as packages. This includes AIX, Solaris and some of the commercial Linux distributions.
However, without knowning your background it is safe to say it would be a stretch to consider Java to be a part of the OS itself. The one exception would be Android (however it is debatable if the Android VMs can safely be called Java :)
(Not talking about embedded and card os here).

Related

is java 9 and above still platform independent or not after this module system has been introduced?

I am not able to understand that after module system is introduced in our java language. Is java9 and above still platform independent or not ? I am asking this question because I have read that now every application will have its own jre inside it. So, how will this single jre run on all OS, like windows, Linux, or Mac OS.
You are conflating two different changes recently made to the Java platform:
Retiring of Java Web Start & Applet technologies
Modularization
Retiring desktop-technologies
Recently Oracle announced the phasing out of the Java Web Start technologies, in addition to the already-deprecated Applet technology. See item JDK-8184998 in Java 9 Release Notes:
Java Deployment Technologies are deprecated and will be removed in a future release
Java Applet and WebStart functionality, including the Applet API, The Java plug-in, the Java Applet Viewer, JNLP and Java Web Start including the javaws tool are all deprecated in JDK 9 and will be removed in a future release.
End-users will no longer be encouraged to install a JDK or JRE on their computer.
For more details, see the eight-page 2018-03 white paper from Oracle, Java Client Roadmap Update.
So then, how are developers of Swing or JavaFX apps to deliver their software to the end-user?
Oracle suggests packaging up your app along with a JVM & JRE for delivery as a single launch-ready applications on that appears on the client to be just another app alongside the native apps. Such “double-clickable” app-packaging has been commonly done on the Mac since the beginning of Java. But what was once an obscure art on other host environments (Linux, BSD, Windows, etc.) will now be the norm, as it is on macOS.
In yesteryear, bundling a Java runtime with your app required jumping over some licensing hurdles. The legalities have eased with arrival of the open-source OpenJDK project, and possibly with other implementations†.
You will need to prepare different releases of your app for each hosting environment. While your Java code runs independently of the host OS, the JVM is built of native code to interact with one specific kind of host. So you will need to build a Linux release with a Linux JVM, a macOS release with a macOS JVM, and so on. While that may seem like a downer, the upside is that you no longer need to worry about users having the wrong JVM version installed, or no JVM at all. Now the JVM’s presence and version are under your control. Your end-users and customers will no longer need to be aware that your app is Java-based.
Modularization
That need for app-packaging has nothing to do with the modularization of Java. As I said, it has been done for decades on the Mac.
What modularization brings to the party is that the JVM/JRE you bundle into your delivered app can be customized to contain only the Java Modules actually utilized by your particular app. This results in a smaller size, so your finished app is smaller, downloads are faster, less storage is used, and your app may load faster.
The open-source jlink “Java Linker” tool helps with the packaging work, so you can assemble and optimize a set of modules and their dependencies (only the ones actually called by your app) into a custom run-time image. This modular run-time image format is defined in JEP 220.
† On a related note, you may want to read the white paper Java Is Still Free to understand how and where to obtain a Java implementation for your app, and what support may or may not be offered in either free-of-cost or paid releases.
By the way, you may find helpful this Answer on a related Question, with a flowchart of choosing various sources of a Java implementation.
Is java9 and above still platform independent or not ?
Yes. It's as platform independent as it ever was. The module system has nothing to do with platform independence.
now every application will have its own jre inside it.
It doesn't have to, but it's more and more recommended as time goes on since fewer people have Java installed separately on their systems. This used to be a given, but that number has been declining for the last decade or so, and now (outside of Java developers) pretty much no-one has a standalone JRE installed.
how will this single jre run on all OS
It won't. You will bundle a separate JRE for each platform you want to distribute for. But JRE's for all platforms are still freely available, and the same Java code will still run on a JRE for any platform.
The module system doesn't influence the OS independency of java in general. Java applications that make use of the module system need to be run in a JRE. This can be either an OS specific pre-installed JRE as usual or a tailored runtime image (application embedded JRE) created with JLink.
The module systems main purpose is to provide you a managed way to split your application into different logical modules. E.g. into different .jar files that can be loaded at runtime - no matter on which operating system.
In summary, you have the following options:
Make sure that your client has the right JRE pre-installed. This could be dangerous, because (normally) you are not in control of his updating behavior.
Ship your application together with an official JRE.
Tailor your own, application and OS specific runtime image using JLink. Ship it bundled with your application.
But, suppose I do not know what OS my client would be running so how
the server will decide what image he should give to him. i.e., a Mac
Image, a Linux Image or a Windows exe.
You have to know the target OS and deliver the right runtime image.
While Java 9 makes it easier to ship a JRE which is more compact and specific to the needs of an individual application, you are not required to do so. If you were already planning to ship a JRE with your application it can be smaller with Java 9 than earlier versions.
It doesn't mean you have to ship a JRE, an application which wasn't shipped with a JRE is unlikely to start shipping with one now, and in fact Java 11 only ships as a JDK.
From this link on Java 9 features;
JLink allows you to create custom runtime images that only consist of your application modules and those JRE modules that your application requires. The result is likely a smaller runtime image, which uses fewer resources than a default JRE.

Jvm comes with JDk or it default comes with os

I have a confusion of JVM. does it comes with os or JDK ,because I have read in many books ,it comes with JDK but JVM is not plat form independent it means that it comes with the os .Can any one clear my doubt?
Think of the JVM / JRE / JDK as a car:
The JVM (Java Virtual Machine) is the engine of the car. It's the essential part that makes the car run. Likewise with Java, the JVM is the engine that can run Java bytecode. It's the interface between Java bytecode and the operating system and hardware of the computer.
The JRE (Java Runtime Environment) is the rest of the car. To be able to drive a car, you need more than just the engine (the JVM). You need a chassis, wheels, a steering wheel, pedals, etc. The JRE provides everything around the JVM, such as libraries and tools needed to run Java programs.
The JDK (Java Development Kit) provides extra tools on top of the JRE that you need when you want to write your own Java programs. It contains the Java compiler and other tools that you need to create Java class files from source code.
On Oracle's website, you can download either the JRE or the JDK.
If you are an end user and you just need to run Java programs that other people have created for you, then the JRE is all you need. It's a complete car - it includes the JVM (the engine of the car).
If you are a programmer and you want to write your own Java programs, then you need the JDK. Oracle's JDK package includes the JVM and JRE, as well as the Java compiler and other development tools.
The JVM is provided by Oracle (or by another party, if you are using a different Java implementation than Oracle's). It is not normally included with the operating system.

Java x86 compatible with Java ARM?

Can any given Java program written targeting an x86 platform also run on an ARM platform, or will there need to be OS-dependent code written to handle OS-specific functionality?
Yes. The Java runtime environment (JRE) includes a virtual machine which allows for true cross platform software. As long as you aren't using native libraries (or JNI), everything should be truly cross platform. Also, you need to check that the version level of the virtual machine is equivalent for some corner cases.

Why java JDK gives option for all OS?

http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u3-download-1501626.html
We know that java is a Platform Independent Language then why does this site provide JDKs for all OSes like Linux, Windows, Solaris?
Then why do we tell java is Platform Independent?
it is like this:
your application
---------------------
JAVA on OS1
---------------------
OS1
---------------------
hardware
---------------------
if you write your application on top of Java, then you can just move your java
application, as is, without changing it, or even compile it, to new OS, because
your program is written on one platform, which is Java, not the native OS.
So, you need to download specific Java for your OS. But from application point of view, it is the same API. Java makes your application platform independent since it hides the OS from your application. But Java itself, it has to be compiled and build for each specific OS. But the application do not care about that. The application sees the same API. That is the whole point.
Because there you download the Installer for the Java Virtual Machine. This is the environment where your Java Application is running in.
The reason why Java is OS independent, is because its running in this JVM.
The JVM's job is to hide the differences between platforms and to provide the same execution environment to application code regardless of platform.
The JVM is written in C++, and is compiled to a native binary, just like any other C++ application. (You wouldn't expect a .exe file to run on Linux, after all).
So the JVM is platform-specific, but the environment it provides is not.
To explain you in simple terms, you no need to compile your java source code when you move your code from one OS to another, but to run your compiled java code you need to have OS specific Java run time machine. Thats why you have different JDK for different OS.
To add to others answers, Java is qualified Platform independent because the code you write is supposed to works on every platform. That's not totally true in fact. The Java code is always compiled in bytecode in the same way, but the JVM interprets this common bytecode in different way in function of the OS, there is one JVM per OS. OS that don't have a JVM implementation to use bytecode can't support Java.

Best OS for java development? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
What is the best OS for Java development? People from Sun are pushing the Solaris, yes Solaris have some extra features included in itself such as (dTrace, possibility for Performance tuning the JVM, etc.. ). Some friends of mine, had port their application on solaris, and they said to me that the performances was brilliant. I'm not happy with switching my OS, and use Solaris instead.
What were your experiences?
Of the three I've used (Mac OS X, Linux, Windows), I consider Linux the best place to do Java development.
My primary personal machine is a Mac, and I've done quite a lot of Java development there and been happy with it. Unfortunately, however, Apple lags behind the official JDK releases and you're pretty much limited to the few versions they choose to provide.
My employer-provided machine is an old P4 crate from HP which I use mostly to keep my feet warm. The real work occurs "Oberon", on a 2.6 GHz quad-core running Ubuntu 8.04 in 32-bit mode [1]. The two advantages I notice day-to-day compared with Windows are:
A powerful command line, which helps me automate the boring little stuff.
Far superior file system performance. (I'm currently using EXT3 because I'm becoming conservative in my old age. I used ReiserFS previously, which was even faster for the sorts of operations one typically performs on large workspaces checked out of subversion.)
You can get those advantages from a mac too, but Linux offers another nice bonus:
Remote X11: Before my $EMPLOYER provided e-mail and calendar via web, I had to be on the Windows box to read my mail and see my meetings, so I used Cygwin's X11. This allowed my to run the stuff on Linux but display it on my windows desktop.
[1] I used to run Ubuntu in 64-bit mode, but I had no end of trouble. (Mixing 64-bit and 32-bit is something Mac OS X does much better.) 7.04 worked fine running 32-bit applications on the 64-bit kernel. 7.10 broke the linux32 script and the ability to install new 32-bit applications though old ones continued to (mostly) run. 8.04 killed 32-bit java by making it impossible to connect to the network from a 32-bit JVM (no more updates for Eclipse). Running Eclipse 64-bit didn't work reliably. The then current version of oXygen would only run (grudgingly) under the IBM 64-bit VM which would work for about 10 minutes until it stopped getting keyboard events. I finally gave up in frustration and used my Mac for a few months until I had enough slack time to do a 32-bit install of 8.04 on the linux box. Now everything works again and I'm quite happy.
Develop on whatever you like. As a java programmer you might want to avoid Mac OS X, primarily because new features seem to have been significantly delayed, and also because you can find you've no longer got a machine that supports the new versions of Java. Having said that I imagine developing on Mac OS X must be very nice (command line interface, dtrace, nice OS).
I develop on windows with IntelliJ 7. It's ok, but needs some hefty hardware. I then deploy onto solaris/linux. Unless you're writing GUI's or integrating with C++ code, you should be fine choosing whatever takes your fancy.
I'd say Mac OS X.
Java development built in. All the unix command line tools you want. Out of the box. Ant and maven are there. Not the latest versions, but that's easy enough to upgrade.
Yes, you might not have the very latest version of the JDK, but really, unless you have a need to develop for the latest and greatest JDK, it's not going to be an issue.
"development" ?
I believe you should stick to the OS you are the most comfortable with, or which is the most available to a large group (of developers), like for instance a set of PCs on Windows.
It is rare to need to do in-depth tuning on development platform.
You would reserve all those dtrace and other performance tuning to assembly platform (for example in Linux), for daily deployments where everything is recompiled and unit-tested.
And then you could set up a special JVM (like IBM JRockit instead of Sun JRE) to do some analysis on your integration platform, where all your system can be tested from front to back, with stress and non-regression test
And finally, make all UAT (User Acceptance Tests) on a pre-production platform (which can be an expensive F15K or SunFire880 or V490 or...), with the target JRE used there.
My point is: there is so many parameters to take into account between development and release into production that switching OS at such an early stage may prove unnecessary.
Develop on what you're happy with, and test on what you deploy on.
I get to develop Java on my Mac, and deploy on Solaris and Linux. The truth is that for the bulk of tasks, Java can be developed in an OS independent manner. This is especially true for server side development.
I like developing on a Unix in general over a Windows box, but that's me.
Answer is easiear than you might think: use your favorite OS. For Java, it's the best answer. Not the development itself, but your comfort will help your success, browsing docs etc in your favorite environment.
Personally, I would not bother. I would use the platform that best supports the development tools and target platform that you use.
Why do you need to tune the JVM? This is a very unusual thing to want to do. Would you be better writing in a lower level language like C++?
Dtrace is available for OS X, there is a linux port too.
Solaris has historically had a reputation for being slow (hence the Slowaris nickname). I'm not sure if this is still true.
I've used Linux, Windows and OS X. My big argument in favour of OS X is that it is user friendly operating system (ie. I can run iTunes, most modern browsers, and don't need to allocate 50% of my time maintaining it on a laptop like linux) with a unix foundation. As most my development is for unix systems, this makes life hugely more productive. Also, there is a more and more active development community behind the platform here. These reason also work in reverse for Windows - while cygwin closes some of my requirements for using unix tools - it's nothing like having a real unix system.
I have had success before doing Java development in Windows with Eclipse. Sounds like you are also asking about deployment/hosting. Whichever OS is best to run your application on should not really predicate what OS you use to develop the application.
Windows and Eclipse works well, as pmiller suggested. I can also recommend OS X with either Eclipse or IntelliJ IDEA (the latter also works on Windows, too).
I've only ever done the most basic Java development on Solaris (basic data structures' programming practice at University), so I can't offer any real comparison, I'm afraid. I did find it quite painful on Solaris, though, due to a lack of proper tools (I think I was restricted to nedit or something).
One thing you have to take into account is whether you are going to be developing an application that could be run on a mac. I love OS X, but good old steve made sure that we're always many JDK versions behind. We just barely got Java 6. Developing on a mac may at least insure you are working under the lowest possible JDK version.
Your development environment MUST BE THE SAME AS PRODUCTION.
There is no "best development environment" which is not identical to your production environment. Run what you run in production, in development.
That said, that doesn't mean you can't run your IDE, for example, on another OS, provided you still do development on the same system as production (on another machine, or a VM, for example).
Windows is just fine.
Solaris is a wonderful Java development environment too (I like it better than Windows, but for subjective reasons), but unless you're deploying on it, it might not be worth switching to.
Linux is a little clunky for Java development, but doable.
The only one I can't recommend is Mac because they're always so far behind on the version of Java available (Not provided by Sun, Apple does their own).
My best advice is to develop on the platform that you are targeting. That way, when you run it during you development testing and run your unit tests, you know that it will work on the target platform too, without any nasty surprises.
If you are targeting all platforms then you might actually want to develop on a Mac because you will get the most nasty surprises on the Mac. As far as Java goes, on Windows and Unix, "it just works", but not so much on Mac. Sun develops the Java runtime (JRE) for all operating systems except Mac. Apple develops their own JRE.
If you develop on the Mac, you are most likely developing against the least common denominator, so what runs on Mac should run on the others. That has been my experience.
Barring that, I always recommend that you choose the operating system based on whether it runs your software. Pick the OS that runs your IDE and other tools that you use for development and testing. If more than one OS runs the tools that you need, pick the one that runs them the best.

Categories