what does it means by "recompile source code?" in java - java

I have read following:
"Active mq requires JRE or JDk
(a JDK is required if you plan to recompile source code)"
My question is, what does it means by "recompile source code?"

It means that if you want to download the source code yourself and compile it yourself, you need the JDK. The JRE (Java Runtime Environment) can run Java code, but to compile Java code you need the JDK (Java Development Kit).

Compiling Java source code is the act of turning Java code as written by programmers into Java Byte Code by the JVM which can then be run by the JRE on any machine.
To "re-compile" means to restart this process. For us as programmers working in an IDE it means that we just save the newly changed code and press the compile icon.

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 .

Compiling for Java 6 using Java 7 without installing Java 6

The target system, on which my application is supposed to run, uses Java 6. On my development machine, I have Java 7. Can I do the development, without downloading Java 6?
I found on http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html one example for cross compilation:
javac -source 1.6 -target 1.6 -bootclasspath C:\jdk1.6.0\lib\rt.jar -extdirs "" OldCode.java
However, this too requires the existence of a rt.jar, which belongs to Java 6. Is there a simpler way?
New Java versions generally change both the Java Language (source and class file format) and the Java API.
The Java compiler can emit class files in the old format, even if the source is in a new format (these versions are specified by -target and -source, respectively). Therefore, you don't need the old compiler to target an old JVM.
However, the changes to the Java API are somewhat harder to account for. The easiest is to compile using the API of the Java version you target (-bootclasspath). Of course, you may feel confident that you are not using newer APIs, and skip this step, but the only way to make sure is actually compiling against, and testing on, the old runtime library.
In short, while cross compilation is helpful in that the same source can be used with different Java versions, you should compile and test against the actual Java version you intend to use, which does require the old JRE (or JDK).
BTW, all of these settings are also available in Java IDEs. For instance, in eclipse, one would set the compliance level in the project's compiler settings, and add the appropriate "JRE System Library" to the project's "Build Path":
The below command should suffice to meet your requirement.
'javac -source 1.6 -target 1.6 OldCode.java'
With this command you are telling that the compiler should generate class file that is compatible with java 6. Any java 7 specific will result in compilation error. Regarding rt.jar, you don't need to have java6 specific version. As mentioned the above command automatically ensures output is java6 compatible.
UPDATE/CORRECTION:
After going through the following link http://www.javaworld.com/article/2077388/core-java/what-version-is-your-java-code.html it is clear why it is recommended and is important to use -bootstrap flag along with -source and/or -target flags.

Why Eclipse doesn't have path to java compiler?

As I know, java source code is compiled into class files by the java compiler (javac.exe); then these class files are put into JVM to interpret using java.exe
But Eclipse is only using javaw.exe. So, I think javaw.exe is equivalent to javac + java
But some references say javaw.exe nearly equivalent java.exe. thus Eclipse only has the interpreter progress. Compiler process takes place where, how?
How should I understand this?
Eclipse does not compile files using javac. It has its own, independent implementation of a Java compiler, complete with its own set of error messages—and bugs.
Eclipse still needs access to all the standard library classes against which it compiles Java code.
The Java runtime which runs the Eclipse IDE process is not related to the JDK used to compile the code against. For all that matters, Eclipse could be a native application written in C++ and that wouldn't stop it from being able to compile Java.

Need to use two Java versions in one machine

My application will support only java 1.6 version and I need to execute all test cases using java 1.7 compiled class files code.
My question how to reach above requirement...
Is it possible to install both java 1.6 and java 1.7 versions in my machine?
If possible how can i set java 1.6 path for my application and how i can set path for java 1.7 version to execute test cases using java 1.7 compile files.
Application will not open with Java 1.7, but I need to use java 1.7 compiled files only.
Yes , it is possible. You need to change JAVA_HOME environmental variable. You can set it in the script that is used to start the application.
This article might help you
Yes it is possible.
You can install multiple java versions in single system.
To make it simple. You can use eclipse , or Netbeans IDE. In that you can use different java versions to compile.
Like any program, you need to specify the directory of the program you want to run, either directly by giving the full path name, or indirectly by setting an environment variable like PATH or JAVA_HOME OR JDK_HOME
You can install any number of updates/versions of Java until you run out of disk space. To configure each program to use a specific version you need to look at how they are started and set appropriate directory to use Java from for that program.

JDK contains src.zip but JRE doesn't

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.

Categories

Resources