Running javafx application on java 1.8 - java

I have noticed that in jdk folder javafx-src.zip is separate from src.zip.
Is it included in the jre? Will it run in all java 8 VMs?

I have noticed that in jdk folder javafx-src.zip is separate from src.zip. Is it included in the jre?
No. The JRE only needs to include binary runtime code, it does not need to include source code. Only the JDK includes source code. So, the JRE includes neither src.zip, nor javafx-src.zip.
Will it run in all java 8 VMs?
VMs yes, JREs no. For example if you have an Oracle server JRE or an OpenJDK JRE distribution which does not include JavaFX client runtime code, then your JavaFX application will not run on those environments. All full (non-server only) distributions of Oracle Java SE 8 (except Solaris) include a compatible runtime for JavaFX 8, so you can execute a JavaFX 8 compatible application directly on the Oracle Java SE 8 JRE without any additional installations.
To ensure that your target machine has a compatible JRE installed for executing your application, you may wish to package your application as a self-contained application.

Yes as of JDK 7u6 JavaFX is included with the standard JDK and JRE bundles.
Source: http://www.oracle.com/technetwork/java/javafx/downloads/index.html

Related

How to open a .jar written with jdk 12

I'm writing a java application using JDK 12.
From Java 11, Oracle doesn't provide any JRE.
So, JDK 11 and JDK 12 don't have Java Runtime Envirnoment.
How can i execute jar written using jdk 11 or jdk 12?
I tried using jre 8 and it works.
How is possible open jar file written using jdk 12 with jre 8?
I read on Internet that from Java 11, jar files have a little jre inside.
But i need java 8 anyway for open them?
Both Java 11 and Java 12 JDKs have all you need to run a packaged jar file. Assuming that your installation is correct and you have the correct environmental variables in place, simply doing:
java -jar <jar_file>
should work properly for you. Granted JDKs nowadays do not have a specific jre folder as it was in the past, but that does not mean that they do not provide anything needed for you to run a java application. Just have a look at the bin folder for more.
Now regarding your second question. Is it possible to run a java application that has been compiled against a newer version using an older jre. Well the answer is it depends. Normally running bytecode produced from a newer jdk against an older jre will result in class compatibility errors. This can be circumvented by compiling your application in compatibility mode (most likely your case).
So to sum up. Go ahead and install the correct Java version (ideally the one you develop with and planning to deploy on). Set up your environment correctly and you'll have no problem running anything.

is it mandatory to having same version of jdk and jre?

I am having java JDK version 11 and JRE version 8, it will occur any problem in feature or not? is it mandatory to have same jdk version and jre version?
If your code is using features of Java 11, you will need the JRE 11 to run it. But as long as you develop your code against JRE 8, it doesn't matter which JDK you use to develop and compile with.
You can set your project in your IDE to a compatibility level of JRE 8 (like here). This prevents any usage of features newer than Java 8.
Example: Develop with JDK 11 but only use features from Java 8 -> code will run in JRE 8. See the older versions as subsets of the newer ones.
If you compile code targeting Java 8, and don't use any newer APIs, you can run it on either.
If you build for Java 11, but try to run on Java 8 it won't work.
The simplest thing to do is to use the JVM the software was built on (or a newer version)
No. Because you never use both of them at the same time.
JRE is Subset of JDK.
JDK includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java development.
If you Open your JDK folder (C:\Program Files\Java\jdk1.8.0_152) , you can find JRE there.
Coming to your Question; No it is not necessary to have both JDK and JRE of same version as we don't use both at the same time.

JavaFX only run with JDK

My JavaFX Desktop program only run with JDK 1.8 installed, doesnt run with JRE 1.8.
Any JavaFX Application should run with JRE?
If NO, How can I find why JDK is needed?
This is because JavaFX runtime is not packaged into some distributions of JRE. As far as I know JavaFX will be in all distributions only when JDK 9 is released. Till then, it is safer to install JDK instead of JRE, or you can include jfxrt.jar when you export your project into JAR file.
Per Oracle's documentation, the JavaFX SDK and Runtime (jfxrt.jar) are included in the Java JDK, beginning with Java SE 7 Update 2. As long as the application was compiled with this version or later, it should run JavaFX.
Also per their site, the JavaFX APIs are fully integrated with the Java SE Runtime Environment (JRE) and the Java Development Kit (JDK).
The specific location where you should find jfxrt.jar in both the JDK and JRE is:
For Java 7, under jre\lib
For Java 8, under jre\lib\ext
Additional info can be found at Oracle's various JavaFX resources such as here and here - though the latter was created for JavaFX 2, so may not be entirely compatible with the latest version of JavaFX.

Create Jar Compatible With Java 7 With IntelliJ Using JDK8

I am using JDK8 on my normal desktop and I have a separate linux box that I am trying to run the Java program on.
The problem I'm running into is that the linux box is running jdk7, so the computer has JRE7 basically that it is running off of. My question is, is it possible to create a jar file in JDK8 that will be compatible with java 7?
I'm using IntelliJ to compile. I tried to compile in 1.7, but it gave an error when I did end up trying to do it. I compile it here:
In 1.8 it works fine to compile, but when I try to compile in 1.7 it doesn't work.
I know the short answer is to update the linux to JRE 8. But I am curious, is there a way to make it backwards compatible? Or is the other answer to simply install JDK7 on the desktop in order for it to run on the linux box using JRE7?
Java programs built with JDK 8 will only run on machines running JRE 8 (or higher).
I found this when trying to compile classes on my local Linux machine (using JDK 8) and deploying to a remote server running JRE 7. The classes just wouldn't work (like you're finding).
If you want to use JRE 8 on linux, I recommend using the oracle-java8-installer package from webupd8team. Installation instructions found here (assuming Debian based distro).
If you want to compile to JDK 7, it's not good enough to only have JDK 8 installed and pick to compile 1.7. You need JDK 7 installed to and restage your project to use JDK 7.
The thing you have to remember is that the difference between JRE/JDK versions is not just the extra features developers can use (e.g Lambda functions) but it's also that the JRE itself is improved (efficiency, garbage collection, etc.).
As a extreme example: If you wrote code that only used JDK 1 features but compiled it using JDK 8, it wouldn't run on a machine running JRE 1 because the Java classes had been compiled with JRE 8 in mind.
Do note though, that if you're Java Code uses only features from JDK 7 or 6 etc., you might think it good practice to compile using the minimum JDK required to allow for compatibility with more machines. Well...you'd have that compatibility but at a cost of using inefficient, out of date, possibly vulnerable compiled classes (At little extreme, but you get my point).
Are you using any new Java 8 features? Because if you are, this means you cannot build the project against the JRE7.
If you are not using any Java 8 features, you can build to Java 7 most easily by downloading the JDK7 and switching the project to use that instead of the JDK8.
You should also set project language level to 1.7 (and module language level(s) as well, if they're different). It's done in Project Structure settings dialog. After that the project should compile.
Note that you shouldn't use any of the APIs that appeared in 1.8, but such usages will most likely be highlighted in the editor.

which java version need to be uninstall

I already researched on how to install Eclipse Luna. One of the things to consider before installing Eclipse is to choose the JDK (planning to use JDK 8). It said that it is recommend that if I have an older version of Java, I need to uninstall it. But here's the problem: I don't know which I should uninstall. Here is the list of installed versions in my control panel (Windows 7 64bit):
Java 7
Java(TM) 6 Update 45
Java(TM) SE development kit 6 (i think this one but what's with (TM)?)
It is strongly recommended to specify what JVM (preferably a JDK) Eclipse should run in, via the eclipse.ini file. That way you can have any number of JDKs and/or JREs without problem. In fact, Eclipse also allows you to have multiple Java versions on your machine and each project in Eclipse can dictate exactly which one it uses. You can easily mix-and-match projects that use different Java versions, and they're all independent of the JVM that Eclipse itself is running in.
run java -version at the command line to see which one is in your PATH. This is the one that will run the Eclipse workspace.
Unless you have clear requirements to use older Java versions, I would recommend to uninstall all of them. And just have the latest JRE or better JDK installed.
In my case, I have a JRE to run the Eclipse workspace that is maintained by the Admin people and a private JDK (to provide additional tools, such as javadoc) to support the software development. You can have several Java versions installed (without having them in the PATH environment listed). You can point to them in the workspace settings or in specific Eclipse projects, e.g., to use a Java 6 for a certain project.
I think Eclipse Luna needs Java 7.
A Java 7 JRE/JDK is required for most of the Luna package downloads based on Eclipse 4.4.
In my opinion you can uninstall Java(TM) 6 Update 45 & Java(TM) SE development kit 6

Categories