java jre confusion - java

Could anyone please tell how jre directory help in the running java programs? I'm calling java interpretor by using java command, and that is in JDK directory, then how could jre directory help in running java programs and jdk for compiling?

When you install the JDK (development kit, compiler and so on), you get the JRE (runtime environment) as part of that (under my install, there's actually a jre subdirectory in the jdk folder) - this is because you will probably want to run code that you develop if only to test it a little bit before inflicting it on the rest of the planet :-).
But it's by no means necessary to install the JDK to run Java programs. All you need is the JRE and that is, by far, the normal situation for most people out there.

The JRE is just the interpreter (java.exe or whatever) - it's a smaller install that is typically used by people who just need to run Java applications and aren't Java developers. The JRE handles the conversion and execution of java bytecode for the target platform.
The JDK is meant for developers. Along with the runtime it provides the compiler and all the Java libraries that are used to build Java programs. The compiler is responsible for converting Java source code to bytecode.
So - when you are delivering your Java application to customers, all they need to install is the JRE.

The Java Runtime Environment (JRE) interprets byte code to platform specific machine code. JRE is minimal set of programmes which executes the java class files.
The JDK (Java Developmental Toolkit) comes along with java libraries and JRE embedded in it. Apart from these it comes along with the utility tools for byte code compilation "javac".

Related

Has every program that is installed a default complier with itself?

I am not native English user and I am sorry for bad English but very interested in programming.
My question is: Has every program that is installed on a specific OS a separate compiler or all programs that are installed on that OS use from a default OS compiler?
Thanks.
Your question is marked with 'java'. Regarding Java
you must have JRE to run a java program. JRE stands for java runtime environment, which includes JVM (java virtual machine) and another runtime units. Java feature is to have single JRE to run every java program (let alone versions etc). JRE will execute java program.
if you want to create a java program on your computer, you should have have Java SDK (software development kit). It includes compiter and huge bunch af another necessary and useful tools. SDK can turn your java source code to an executable java program.
If the question is general, like, what happens when you install a desktop app, it depends of a app type and it's installer type.
There are some, that are distributed with sources and are to be compiled at the installation phase right at your machine. Most often they have anything they need to run the installation successfully, including all necessary compilters. In vast majority of cases you are not supposed to have something preinstalled on you OS prior to the program installation.
But mainly a program is distributed as a bundle of binary artifacts. They are already compiled and packed and are delived in this state. So no, here you are not expected to have a compiler on you machine.

Eclipse compiling with JRE or JDK

I have one question in my mind and I should note that I know the differences between JDK and JRE. I am not a new programmer in Java.
What I would like to ask is in Eclipse I can specify the compilation environment (correct me if I a wrong) in window> Preferences but we can also change it for a specific project.
OK. I added jre and jdk folder in the options. I can use both.
But JRE has no javac (no java compiler) in it. So how it is possible that some projects requires that I need to change to jre1.7 to COMPILE?
I was getting some minor.major version error and setting JRE solved my problem?
How can this be possible?
In fact now I realized something.
Ok the question changes a little.
I saw that these are VM not compiler. I understood.
Does JDK have also JRE in it? so if I specify JDK1.8 I am setting jre1.8 as VM and if I specify JRE1.7 I am setting jre1.7 as VM?
Is it right?
It makes confusions. Why JDK has JRE in it?
JDK has whole JRE (regular Java VM) inside, in order to allow you to run what you will develop with it.
Theoretically someone could make some small-JDK with just tools and without JRE, but it would make a whole lot more confusion as to which tools version run with which JVM version (most JDK tools needs JVM to be run). Look at you, how many people have only this problem? So it is bundled together, tools and JRE as a whole named JDK, thanks to that you have some guarantee that those JRE and tools will work together.
JRE - Java Runtime Environment - allows you to run java programs
JDK - Java Development Kit - allows you to run and develop java programs
JDK = JRE + tools for developer
Also note, that You can choose for the java compilation process two things:
compatibility with source version - this is basically the syntax you are allowed to use.
compatibility with VM version - this is the minimum VM level on which you can run the compiled binaries.
example from your post: If you have compiled something as Java 8, you can't run it on Java 7, this is the minor/major version problem you have. But the opposite (to run something for Java 7 on Java 8) is valid.
in your example JDK8 and JRE7 both are just fully functional VM's, but JDK8 has additionally (in comparison to JRE) development tools inside it.

Any way to sandbox an application dependent on an older (non-working) version of JRE?

I have a very old application (published in 2001) I am trying to get working in Windows 7/8/10. There is a setup.exe part of it that is using Java in some capacity, and not working correctly. I suspect it is using java because I decompiled the JAR file packaged with the application and there are references to several setup steps within the .java files (along with a file named setup.java). There is also a jre folder published with the application as well, running the following (dated) version:
F:\jre\bin>java -version
java version "1.3.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)
At first I suspected the application was using the systems environmental variables to use the currently installed version of JAVA, but I ruled that out by completely purging JAVA from the system and retesting - same results.
I next tried to simply update the folder to the latest version. As expected however, there were calls being made that were no longer supported (error message was referencing _JVM_IsVMGeneratedMethodl).
At this point I am running out of options. I could always run this application in a VM (and it works fine), but I would prefer to somehow package it in a nice streamlined way for easy distribution and install. Is there anything I can do? I was thinking something along the lines of application virtualization but still reading up on it.
It's hard to tell without "being there", but I'm guessing that the old (1.3) JVM just isn't compatible with the more modern versions of Windows.
Your best bet is probably running it against whatever version of Windows the app was originally developed on, in a VM.
If you have / can get the complete source code, you could try recompiling it with the version of Java supported on your current system. But it's probably a long-shot.
If it is containing a JRE folder, then you could skip the installer and add some batch file to launch that .jar with the specific JRE via a command of this form:
java -jar pathToYourJAR
btw, you could also consider options to convert to executable, some older are mentioned here:
How can I convert my Java program to an .exe file?
some of them may allow you to select which JRE to bundle/use

JDK instead of or in addition to JRE?

I have a question about the two versions of Java: JRE (Java Runtime Environment) and JDK (Java Development Kit).
Is the JDK installed and used in addition to the JRE or is it used instead of the JRE so that one could install the JDK as a JRE with simply more functions for developers?
You must understand that JDK includes JRE. JRE is Java Virtual Machine where your Java programs run on whereas JDK is full featured Software Development Kit for Java
From the docs:
JRE (Java Runtime environment):
It is an implementation of the Java Virtual Machine* which actually executes Java programs.
Java Runtime Environment is a plug-in needed for running java programs.
The JRE is smaller than the JDK so it needs less Disk space.
The JRE can be downloaded/supported freely from https://www.java.com
It includes the JVM , Core libraries and other additional components to run applications and applets written in Java.
JDK (Java Development Kit)
It is a bundle of software that you can use to develop Java based applications.
Java Development Kit is needed for developing java applications.
The JDK needs more Disk space as it contains the JRE along with various development tools.
The JDK can be downloaded/supported freely from https://www.oracle.com/technetwork/java/javase/downloads/
It includes the JRE, set of API classes, Java compiler, Webstart and additional files needed to write Java applets and applications.
They're not two versions of Java. JRE is the Java Virtual Machine which executes bytecode. On the other hand, JDK is the Java Development Kit, which allows you to write Java code, compile it into bytecode and ships a JRE to execute it.
If your client just needs to execute Java, it needs to install the JRE only. If you want to run Java applications and create them install JDK.
One can install JDK..which has JRE also.

What is the difference between JVM, JDK, JRE & OpenJDK?

What is the difference between JVM, JDK, JRE & OpenJDK?
I was programming in Java and I encountered these phrases, what are the differences among them?
JVM
The Java Virtual Machine (JVM) is the virtual machine that runs the Java bytecodes. The JVM doesn't understand Java source code; that's why you need compile your *.java files to obtain *.class files that contain the bytecodes understood by the JVM. It's also the entity that allows Java to be a "portable language" (write once, run anywhere). Indeed, there are specific implementations of the JVM for different systems (Windows, Linux, macOS, see the Wikipedia list), the aim is that with the same bytecodes they all give the same results.
JDK and JRE
To explain the difference between JDK and JRE, the best is to read the Oracle documentation and consult the diagram:
Java Runtime Environment (JRE)
The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. It is also the foundation for the technologies in the Java 2 Platform, Enterprise Edition (J2EE) for enterprise software development and deployment. The JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications.
Java Development Kit (JDK)
The JDK is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications.
Note that Oracle is not the only one to provide JDKs.
OpenJDK
OpenJDK is an open-source implementation of the JDK and the base for the Oracle JDK. There is almost no difference between the Oracle JDK and the OpenJDK.
The differences are stated in this blog:
Q: What is the difference between the source code found in the OpenJDK repository, and the code you use to build the Oracle JDK?
A: It is very close - our build process for Oracle JDK releases builds on OpenJDK 7 by adding just a couple of pieces, like the deployment code, which includes Oracle's implementation of the Java Plugin and Java WebStart, as well as some closed source third party components like a graphics rasterizer, some open source third party components, like Rhino, and a few bits and pieces here and there, like additional documentation or third party fonts. Moving forward, our intent is to open source all pieces of the Oracle JDK except those that we consider commercial features such as JRockit Mission Control (not yet available in Oracle JDK), and replace encumbered third party components with open source alternatives to achieve closer parity between the code bases.
Update for JDK 11
An article from Donald Smith try to disambiguate the difference between Oracle JDK and Oracle's OpenJDK : https://blogs.oracle.com/java-platform-group/oracle-jdk-releases-for-java-11-and-later
As mentioned in comments by #Alan Evangelista, Java Web Start has been deprecated by Oracle in Java SE 9 and removed in Java SE 11.
JVM is the Java Virtual Machine – it actually runs Java ByteCode.
JRE is the Java Runtime Environment – it contains a JVM, among other things, and is what you need to run a Java program.
JDK is the Java Development Kit – it is the JRE, but with javac (which is what you need to compile Java source code) and other programming tools added.
OpenJDK is a specific JDK implementation.
JDK (Java Development Kit)
Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc…
Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method.
You need JDK, if at all you want to write your own programs, and to compile them. For running java programs, JRE is sufficient.
JRE is targeted for execution of Java files
i.e. JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.
JDK is mainly targeted for java development. I.e. You can create a Java file (with the help of Java packages), compile a Java file and run a java file.
JRE (Java Runtime Environment)
Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system
The Java Virtual Machine provides a platform-independent way of executing code;
That mean compile once in any machine and run it any where(any machine).
JVM (Java Virtual Machine)
As we all aware when we compile a Java file, output is not an ‘exe’ but it’s a ‘.class’ file. ‘.class’ file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… JVM is platform dependent.
The JVM is called “virtual” because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs.
There are different JVM implementations are there. These may differ in things like performance, reliability, speed, etc. These implementations will differ in those areas where Java specification doesn’t mention how to implement the features, like how the garbage collection process works is JVM dependent, Java spec doesn’t define any specific way to do this.
A Java virtual machine (JVM) is a virtual machine that can execute Java ByteCode. It is the code execution component of the Java software platform.
The Java Development Kit (JDK) is an Oracle Corporation product aimed at Java developers. Since the introduction of Java, it has been by far the most widely used Java Software Development Kit (SDK).
Java Runtime Environment, is also referred to as the Java Runtime, Runtime Environment
OpenJDK (Open Java Development Kit) is a free and open source implementation of the Java programming language. It is the result of an effort Sun Microsystems began in 2006. The implementation is licensed under the GNU General Public License (GPL) with a linking exception.
JVM is the virtual machine Java code executes on
JRE is the environment (standard libraries and JVM) required to run Java applications
JDK is the JRE with developer tools and documentations
OpenJDK is an open-source version of the JDK, unlike the common JDK owned by Oracle
JDK (Java Development Kit) :
contains tools needed to develop the Java programs.
You need JDK, if at all you want to write your own programs, and to compile them.
JDK is mainly targeted for java development.
JRE (Java Runtime Environment)
Java Runtime Environment contains JVM, class libraries, and other supporting files.
JRE is targeted for execution of Java files.
JVM (Java Virtual Machine)
The JVM interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… Java Virtual Machine provides a platform-independent way of executing code.
JDK - Compiles java to ByteCode. Consists of debuggers, Compilers etc.
javac file.java // Is executed using JDK
JVM - Executes the byte code. JVM is the one which makes java platform independent. But JVM varies for platforms.
JRE - JVM along with java runtime libraries to execute java programs.
JVM : A specification which describes the the way/resources to run a java program. Actually executes the byte code and make java platform independent. In doing so, it is different for different platform. JVM for windows cannot work as JVM for UNIX.
JRE : Implementation of JVM. (JVM + run time libraries)
JDK : JRE + java compiler and other essential tools to build a java program from scratch
Another aspect worth mentioning:
JDK (java development kit)
You will need it for development purposes like the name suggests.
For example: a software company will have JDK install in their computer because they will need to develop new software which involves compiling and running their Java programs as well.
So we can say that JDK = JRE + JVM.
JRE (java run-time environment)
It's needed to run Java programs. You can't compile Java programs with it .
For example: a regular computer user who wants to run some online games then will need JRE in his system to run Java programs.
JVM (java virtual machine)
As you might know it run the bytecodes. It make Java platform independent because it executes the .class file which you get after you compile the Java program regardless of whether you compile it on Windows, Mac or Linux.
Open JDK
Well, like I said above. Now JDK is made by different company, one of them which happens to be an open source and free for public use is OpenJDK, while some others are Oracle Corporation's JRockit JDK or IBM JDK.
However they all might appear the same to general user.
Conclusion
If you are a Java programmer you will need JDK in your system and this package will include JRE and JVM as well but if you are normal user who like to play online games then you will only need JRE and this package will not have JDK in it.
In other words JDK is grandfather JRE is father and JVM is their son.
Developers develop using JDK, and first we write .java source code
Developers debug the code and compile the code into .class bytecode executable files in JRE
The executable files are executed by JVM, translating the bytecode into native machine code which machines can execute
Here is they relations:
Reference:
Java JDK, JRE and JVM
Java is the language and includes a strict and strongly typed syntax.
Java 2 Platform, Standard Edition, also known as J2SE, referred to the platform and included the classes in the java.lang and java.io packages, among others. It was the building block that Java applications were built upon.
A Java Virtual Machine, or JVM, is a software virtual machine that runs compiled Java code. Because compiled Java code is merely bytecode, the JVM is responsible for compiling that bytecode to machine code before running it. (This is often called the Just In Time Compiler or JIT Compiler.) The JVM also takes care of memory management so that application code doesn’t have to.
The Java Development Kit, or JDK, was and remains the piece of software Java developers use to create Java applications. It contains a Java language compiler, a documentation generator, tools for working with native code, and (typically) the Java source code for the platform to enable debugging platform classes.
The Java Runtime Environment, or JRE, was and remains the piece of software end users download to run compiled Java applications. It includes a JVM but does not contain any of the development tools bundled in the JDK. The JDK, however, does contain a JRE.
JVM : this actually means the byte code interpreter .It is platform dependent. For eg: in Windows platform the 'java.exe' or 'javaw.exe' precess is the jvm process.
JDK : is a toolkit containing necessary libraries and utilities to develop and execute java program/application
JRE: is the execution environment for a java application.ie, it only support runtime dependencies including jvm for compiled program. If we want to compile a java program we need jdk.
JVM : virtual machine of java. tells machine what to do with the Java Code. You cannot download JVM as is. It comes packaged in some other component.
JRE: Some other component referred as above is the JRE.
It is JVM+ other jars to create runtime environmeny
JDK: contains JRE(which in turn contains JVM). Once you get JDK you need not install JRE and JVM separately. It contains compiler which compiles your .java files to .class files
JVM
JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.
JVMs are available for many hardware and software platforms.
JRE
JRE is an acronym for Java Runtime Environment.It is used to provide runtime environment.It is the implementation of JVM.It physically exists.It contains set of libraries + other files that JVM uses at runtime.
JDK
JDK is an acronym for Java Development Kit.It physically exists.It contains JRE + development tools.
Link :- http://www.javatpoint.com/difference-between-jdk-jre-and-jvm
In summary:
JRE = JVM + Java Packages (like util, math, lang, awt, swing etc) +
runtime libraries
JDK = JRE + Development/debugging tools
If you want to develop in java, you need the JDK, but if you just want run java, you need the JRE.
Simple image to illustrate JDK, JRE, JDK.
JDK In general this will be installed only in development setups like in developers, QA systems in real-time at corporate companies. Original code which is running in servers will not have JDK.
JRE is a part of JDK and independently too installable in servers. In real-time servers which serving user requests will have only JRE installed and code developed by developers (in *.class format)
JVM Developer developed code > tested and executed in development machines. Execution phase require a medium for Java.
.class files are not native code (code which understands by cpu). To achieve WORA (Write Once Run Anywhere) concept can't be achieved if .java file is directly converted to native code.
Native code differs from OS to OS. So, Java created a intermediate file called .class and magical program called "JVM". Its JVM's duty to convert .class into native code.
JVM Java Virtual Machine , actually executes the java bytecode.
It is the execution block on the JAVA platform. It converts the bytecode to the machine code.
JRE Java Runtime Environment , provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files.
JDK Java Development Kit, it has all the tools to develop your application software. It is as JRE+JVM
Open JDK is a free and open source implementation of the Java Platform.
In layman terms:- JDK = JRE + Development/debugging tools, where JDK is our complete package to work with Java, from creating compiling till running it.On the other hand JRE is just of running of code(Byte Code).
Note:- Whether we are installing JDK or JRE, JVM would come bundled with both the packages and JVM is the part where JIT compiler converts the byte code into the machine specific code.
Just read the article on JDK,JRE ,JVM and JIT
JDK: The complete package which you need to write and run java code
OpenJDK: An independent implementation of JDK for making it much better
JVM: Converts Java code into bytecode and provides the specifications which tells how should a Java code be compiled, loaded, verified, checked for errors and executed.
JRE: Implementation of the JVM with which some Java libraries are used to Run the program
JRE executes the application but JVM reads the instructions line by line so it's interpreter.
JDK=JRE+Development Tools
JRE=JVM+Library Classes
JVM is abbreviated as Java Virtual Machine, JVM is the main component of java architecture. JVM is written in C programming language. Java compiler produce the byte code for JVM. JVM reading the byte code verifying the byte code and linking the code with the ibrary.
JRE is abbreviated as Java Runtime Environment. it is provide environment at runtime. It is physically exist. It contain JVM + set of libraries(jar) +other files.
JDK is abbreviated as Java Development Kit . it is develop java applications. And also Debugging and monitoring java applications . JDK contain JRE +development tools(javac,java)
OpenJDK OpenJDK is an open source version of sun JDK. Oracle JDK is Sun's official JDK.
JDK - Tools like javac used to compile *.java files to *.class bytecode files (basically develop Java programs)
JRE - Tools to run *.jar files (basically run Java programs)
JVM - Tools to compile *.class files to executable machine code (run all Java bytecode)
OpenJDK is just a distribution of the Java JDK.

Categories

Resources