Can we have multiple Java SDKs in one machine? - java

Can I have multiple java SDK versions installed on my machine?
Java 1.4
Java 2
Java 6
Java 7
please advise as I have to develop solutions for Maximo in Java 1.4 and Java 2
Plus I want to learn development on Java 6 and 7
Thanks.

Can I have multiple java SDK versions installed on my machine?
Yes
But make sure you use right path in your projects. It will be better to use some IDE like Eclipse. It will handle jdk path problems for you.
Java 1.4 is very old, try to shift to new one as soon as possible.

Yes,you can.
You need change environment variable Normally JAVA_HOME variable.
So you can use another variable.
eg.
JAVA_HOME='/home/jdk1.8.0_45'
JAVA_7='/home/jdk1.7.0_60'
JAVA_6='/home/jdk1.6.0_34'
Add path variable
PATH=$PATH:$JAVA_HOME/bin
PATH=$PATH:$JAVA_7/bin
PATH=$PATH:$JAVA_8/bin

Yes, you can. Just use full path names when invoking javac, java, etc. or set your PATH environment variable to point to the appropriate jdk/bin location.
The IDEs usually allow defining multiple JDKs/JREs, and you can choose which one to use for every project.

Yeah, you can install as many Java SDKs as you want. When you develop you just use the JDK you want to use.

Yes you can. JDK is merely a directory somewhere on your disk. So you can easily download and unpack all the versions you want, and run java and javac from the directory you're currently interested in.
IDEs will do all the messy stuff for you: just let them know where the unpacked JDKs are, and choose a JDK in project's or module's settings.
PS. Java 1.4 is Java 2. Java 2 is actually an umbrella name for 1.2, 1.3, and 1.4

I attach some pics as how I configured VS code to work with two different versions of Java in one machine
1-Environment Variables
2-Configuration inside VS Code
3-Configuration inside VS Code
4-Configuration inside VS Code

Related

Where are the java. packages such as java.lang and java.util located? [duplicate]

This may sound like a stupid question. Where are the core class files from Sun, like Button.class, located in the JDK installation folder C:\Program Files\Java\jdk1.5.0_12?
Or do the class files reside in C:\Program Files\Java\jre1.5.0_12 folder?
They are spread between several jars. It looks like Button is in jre/lib/rt.jar though.
The class files actually reside as jar files inside the Java distribution being used. Most files are in rt.jar (runtime).
Most developer machines actually have two forms of Java installed. The JDK (which you would often be using when developing and includes the compiler), and the JRE which is used by downloaded Java based applications, and often your web browser. Those are typically two independent distributions that don't know about each other. So the answer to your question is unfortunately, "depending what it is that you are running". To make things worse, the JDK may include it's own copy of the JRE...
This is one of the sources of the so-called classpath hell, because it is not always clear what you are using when you are running a java program.
If you run java from the command line, you can sometimes detect the exact version being used.
If you use Eclipse, you can pick version of the JDK you are working with.
On Both.
They are two different JVM's installations. One used to compile ( JDK stands for Java Development Kit )
and the other is the java environment which most customers machine have ( JRE stands for Java Runtime Environment )
Look on any of those two for a file named:
rt.jar
That where the core of the platform resides.
You can check out yourself for any class through reflection.
For example where can I find my String class located in the classpath?
Easy
URL url = String.class.getResource("String.class");
System.out.println(url);
There are actually contained in the JRE. Although, the JDK have her copy of the JRE so we may be tempted to say both JDK and JRE but in reality java inbuild classes are contained in the JRE.

Work with Java 1.7 and 1.8 at the same time

I'm working on Windows 7.
I have projects on my machine that runs with Java 1.7.
I have now checked out an existing project made by someone else that runs with Java 1.8.
I'd like to know the best way to switch from one Java version to another according on which project I work?
In your case, you can use the setenv.bat file, to set your JRE_HOME version.
On Windows, create the file %CATALINA_BASE%\bin\setenv.bat, with content:
set "JRE_HOME=%ProgramFiles%\Java\jre1.6.0_20"
exit /b 0
So create the file on both tomcat and set jre location
It depends on which frameworks are you using in these projects. If you talk about J2SE java 8 is backward compatible. All the code which is written in Java 7 is completely fine with Java 8. you don't need to worry about.

Use different jre for projects and for eclipse launch

May be its a newbie question...
I want to use latest eclipse available. It requires Java 8. However, our company uses java 6 for all projects.
So:
Should I download eclipse that is compatible with Java 6 only ?
or I can configure Java 6 for all the projects regardless what eclipse uses?
Would there be any issues, if its possible to use two versions (one for eclipse and another one for project)?
I know its a newbie questions. But the search did not yield a proper response.
no, you can use the latest Java for Eclipse. The JDK used for project can be configured per project or per workspace. You can install as much JDKs as you desire. i.e. You can start Eclipse using a 32Bit JDK while using a 64Bit JDK for Java EE-Servers or Projects, it has basically nothing to do with the JRE used for Eclipse. You just need to set it up.

Windows 7 64-bit, Configuring 2 versions of Java

Windows 7 64bit. I have a web based application that needs to use the newest version of java (1.7.0.45) and I have another software install the needs java versions (1.5.0.15 & 1.4.2). I'm just unsure how to set the PATH/VARIABLE for this to work properly.. any help would be greatly appreciated.
I have seen several posts & answers regarding very similar situations to this, but I am just unsure how to make this work.
As mentioned by #Moshe here.
It is absolutely possible to install side-by-side several JRE/JDK
versions. Moreover, you don't have to do anything special for that to
happen, as Sun is creating a different folder for each (under Program
Files).
There is no control panel to check which JRE works for each
application. Basically, the JRE that will work would be the first in
your PATH environment variable. You can change that, or the JAVA_HOME
variable, or create specific cmd/bat files to launch the applications
you desire, each with a different JRE in path. Just like below,
set JAVA_HOME=C:\...\j2dskXXX to change the JAVA_HOME environment.

Can I have applications using Java 1.4.2_12 and Java 1.5 on the same windows server

I have a couple of applications running on Java 1.4.2_12 and now need to add an new application that uses Java 1.5. Can I have both java versions on a windows server?
Yes. You just need to make sure that each has the correct version of Java/the JRE on its CLASSPATH, PATH and JAVA_HOME environment variables.
Yes: actually JDK or JRE can be just "copied" wherever you want, not "installed" (avoiding putting anything in c:\Windows\System32)
I would also recommend not using global environment variables.
That way, your applications depend entirely on local settings (local to the application), and not on external Java installation side-effects
Are you sure you have to have the Java 1.4.2_12 apps run using that specific Java VM? Most apps should run fine on the newer VMs, so you might be able to simply have them all use 1.5.
If you do need to use the specific VM versions then you can do what other posters have suggested.
YES. See above. Of course, running two VMs (of any version) takes twice the RAM.
I could suggest you to use Java WebStart, which allow you specific the target J2SE version in the JNLP file. Or; always execute the right version "java.exe" under "Program Files" by absolute path.
You don't have to set CLASSPATH for JRE (and should not in modern JRE). JRE have it own bootclasspath automatically. CLASSPATH is used by your application.
Usually you won't have to set the JAVA_HOME unless your appliaction is looking for resources from JDK\lib\ (e.g. tools.jar which contains compiler)
But I am not sure what's your problem.
Are you running client application(swing)? Two Java processes to provide services? or two application sharing same Java application server?

Categories