JDK contains src.zip but JRE doesn't - java

Just noticed that JDK contains src.zip with a set of java files. I checked JRE and didn't found it over there.
Does it mean the JVM does not need these files in order to run my code?

The JDK (Java Development kit) is, as the name implies, a Development Kit, so it includes tools and resources that are useful for developers. Many of these tools or resources are not actually required in order to run Java applications. Specifically, src.zip contains source code that is useful for developers, but indeed is not required to run Java applications.
The JRE (Java Runtime Environment), in contrast, includes only the JVM and tools and resources that are necessary in order to run Java applications.
So, in short, in order to run Java applications you only require the JRE. Anything in the JDK that is not present in the JRE is not required.

These files are here to provide the source of the JDK classes, this way, it's easier for developers how some classes act (but the javadoc should be sufficient).
So no, no need for clients to read the JDK source code. The only thing needed to run Java applications is the .jar containing all the .class for JDK Classes.

That's right, the JRE does not need Java source files to run your code.
The src.zip file includes the Java sources for the JDK library types and (apparently) some Sun JVM implementations of those types as well.
The JRE doesn't need your source files either, but the JDK includes a tool (javac) that compiles your sources to Java bytecode for execution on the JRE.

Related

does eclipse have it's own JDK? or it uses the JDK on my computer?

I'm new to java programming and I haven't used any java IDE,
I intalled Java JDK 8 on my computer and been doing some coding through Notepad++ and compiling it via cmd commands.
Since now that i'm comfortable coding manually, I wanna try to use IDE and decided to get the latest "Eclipse IDE for Java Developers". what I got is actually a .zip file no installation or something which is odd.
My question is does the eclipse uses the JDK I installed on my computer or it has it's own? if so how would I know which version of java does my eclipse run?
and if does use the JDK on my computer, if I want to update the JDK intalled on my computer do I have to uninstall the old one or I can just overwrite it with the new JDK build??
Thanks,
CC
Eclipse uses externally installed JDKs to run itself (it's written in Java, after all) and to provide the core libraries for the code you write (such as the java.* packages). By default, Eclipse will use its own compiler, ECJ, that has deep integrations with the IDE to provide features such as detailed error reporting and sometimes even partial compilation of invalid classes.
It's possible to override the compiler via some plugin (for example, you can explicitly specify a compiler in a POM via m2eclipse, though the default there still uses ECJ), but that's uncommon if you're still compiling Java code.
Eclipse has support for using multiple JDKs, for example for different versions (maybe you have backwards compatibility with 1.6) or different vendors. Depending on how your OS is set up, if your main JAVA_HOME is set through a symlink, you may not need to update Eclipse at all if you perform a minor upgrade. In the case of a major upgrade, though, you will probably need to go to "Installed JREs" and add or modify an entry.
1.the jdk you installed in your computor is global situation. it can effect anywhere if you have configured the environment variables.
2.configured the environment variables,run cmd like this,the java version will be show,enter image description here
3.generally, one JDK , one computor is enough.if you want to update jdk, just download new jdk and override the old jdk .

In the Java install directory, why are there multiple java.exe files?

Just curious about the directory layout for the JDK . So there are two separate java.exe files - one is in:
C:\Program Files (x86)\Java\jdk1.7.0_45\bin
and one is in:
C:\Program Files (x86)\Java\jdk1.7.0_45\jre\bin
Why does there need to be two files ? The motivation for this question arises from some challenge I'm having installing a program(SQL Developer).
There's a difference between installing the jdk vs. the jre.
The jdk package is the developer package and includes tools such as the compiler (javac).
The jre package is the core runtime package, and includes the JVM / runtime environment / whatever you need to run software written in JVM languages.
Here a link to the official Oracle documentation.
The binaries in jdk/bin and jdk/jre/bin are identical. According to the documentation, the PATH should point to jdk/bin.
Here is a link to JDK 7 and JRE 7 Installation Guide
If you want to run Java programs, but not develop them, download the JRE. If you want to develop Java applications, download the Java Development Kit, or JDK. The JDK includes the JRE, so you do not have to download both separately.

Run Java packages on unsupported Java Version

I have a PowerMac and it is giving me bad version number on some .jars. I would love to make it seem like I am running Java 6. How would I spoof the version? Let me also say I am running PowerPC and Leopard
The most likely problem is that you have Java 6 JAR files and you are trying to run them on an old Java installation.
How would I spoof the version?
The answer to your question is that you can't. The way to run Java 6 specific JAR files it to use a Java 6 (or later) JRE or JDK.
The problem is that the format of Java class files has changed, and your installation can't cope with the new format. And this is not a gratuitous change that you can pretend doesn't exist. Java 6 (actually Java 5) has support for generic types, enums, annotations and other things. Assuming that the JARs contain code that uses these new language features, an older JRE simply won't know what to do with them.
There are two solutions:
Upgrade your Java installations to the required level on all machines. This is the best solution ... if it is an option ... because it means your users will get the benefit of security and bug fixes and performance enhancements. (And progress of your project won't be held back by the constraint of supporting legacy platforms.)
Compile all of your code for compatibility with the oldest version of Java that you still have to use. Either compile on the corresponding old JDK, or on a more recent JDK using appropriate -source / -target / -Xbootclasspath options ... as described by the javac manual page.
The catch with the second solution is that if the source code for the JAR files in question uses recently added Java language features or APIs, then recompiling for the older platform will fail. To fix this you will need to rewrite your code to replace the nice modern stuff with archaic stuff. Not a good solution, IMO.
The other possibility is that you are seeing corrupted JAR files. This is unlikely, but it can happen if you are using applets or webstart, and the server is delivering error pages instead of JAR files.
The third possibility is that you simply haven't configured your Mac's Java installation's correctly. Making Java 7 the default should allow you to run everything without class version problems. (Thanks #paulsm4) Note that I can't help you with that ... 'cos I don't use Java on a Mac.

Is there any way I can get a program that relies on Java7 and JavaFX2 to run "portably"?

I'm writing a program with Java7 and JavaFX2, but I'll need to show it to people who only have access to machines with Java 6 installed (with no JavaFX).
Is there any way I can find a solution to this short of asking them to install Java7 and JavaFX2?
Perhaps you can create a self-contained application package by "bundling" your program with Java 7 and JavaFX 2. That way you don't have to worry about what's on or not on your user's machine.
You can read more about self-contained application packaging at http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm.
Theoretically yes, but you have to check if that is conform to the license conditions of Sun/Oracle the owner of JavaFX:
You could sue tools like http://one-jar.sourceforge.net/
They pack all your java into one jar.
Another possibility you could obfuscate your application and include JavaFX.
But this, too might violate the license conditions.
Both solutions might be more work, than the effort off installing JavaFX to the (one)clients computer.
Try JavaFX2 for JavaSE6
On page: http://www.oracle.com/technetwork/java/javafx/downloads/index.html
Download Download JavaFX 2.2.3 for Java SE 6 ...
If you are using Eclipse JDT, you can configure your projects "Java Compiler", by "Enable project specific settings", to "Compiler compliance level" value 1.6. This should produce bytecode in a version suitable for Java 1.6 VM. I suppose, but am not sure, that Eclipse shall also warn you if you use library elements not present in the 1.6 library version; though you can be careful about that with or without warnings. As with the previous solutions, JavaFX you can just package in your application's JAR if the license agreement allows it.

With GNU classpath, is it possible to build a crossplatform (Win32 and Linux) jar

I thought that gnu classpath was just an open source version of the Java library. Apparently it is tied heavily to the host system? Is this true.
For example, would it be possible to build a gnu classpath 'rt.jar' with only Java bytecode and what are the args to use that as the bootstrap library?
Most of GNU classpath is platform independent, but there is (and has to be) a VM specific layer that handles the behind-the-scenes interactions with the virtual machine and host operating system.
Classpath is not designed to be immediately usable by Java programmers. It requires an appropriate implementation of a number of Classpath VM* classes, etcetera. These classes are normally provided by the target VM's development team.
It should also be noted that some Open Source JVM projects that previously used Classpath are migrating to / have migrated to OpenJDK. One reason is that the Classpath implementation tended to be incompatible with the equivalent Sun JDKs. This is partly due to the 'clean-room' approach taken by the Class-path team (for legal reasons), and partly due to Sun's continuing unwillingness to license the JDK test suites to open source projects. (Apache Harmony has the latter problem too.)
The Java JRE for each platform is tied specifically to that platform and contains its own rt.jar file. The GNU classpath project was intended to create a free version of the Java class libraries, but that is now sort of a historical artifact since the Java implementation is now open source.

Categories

Resources