I wrote code using Eclipse IDE . My system has Java 1.6 installed but the required code needed to run on JRE 1.5 machines also so I set the compliance level to JDK 1.5 in the Eclipse IDE. My knowledge was that even if my machine has JDK 1.6 installed,if I set the compliance level to JDK 1.5 in the Eclipse,my code will comply with the Java 1.5 APIs and run fine on JRE 1.6 as well as JRE 1.6. But after development,my tool went to customer sites and I have come to know that it is not running on machines with JRE 1.5. Can anybody tell me what went wrong?Please correct me if my knowledge was wrong.Have I followed wrong procedure?Please explain in detail as I am new to java.
In project properties, under "Java Compiler", did you also set the "Generated .class files compatibility" to 1.5? And then under Java Build Path, on the Libraries tab, make sure that a 1.5 JDK is listed.
To register a 1.5 JDK with Eclipse and make that the default JDK, go to Windows > Preferences, and then Java > Installed JREs.
I have not registered JDK 1.5 in Installed JREs. For that I will have to Download JDK 1.5 first (right now I only have JDK 1.6 installed on my system)? Can I have 2 JDKs(1.5 and 1.6) installed on the same system?
You can have as many JVM versions as you like, although on some OS's, it's easier than on others. For example, on Linux, the convention is to keep them all in a /usr/java directory. On Solaris, they put the primary one in the system binary directories and a secondary one under /usr.
I think, however, that all platforms support downloading a JVM as a ZIP file that can be unzipped and used without the need for specialized installation like setting up Windows Registry items.
To select an alternative Java version for most commands, such as Tomcat or WebLogic, you set an environment variable (JAVA_HOME) for the shell that the application is running in.
Eclipse is different, since it's a development platform. For Eclipse, you use the Eclipse Window/Preferences,Java/Installed JRE's dialog to register JVMs.
Finally, note that if you set a project's code compatibility level in Eclipse, but actually do your deployment build with something like Ant or Maven, Eclipse's settings don't count. You actually have to set the java compile commands for Ant or Maven to output to the selected compatibility level. Otherwise, they'll compile to the highest version supported by the JDK you're compiling under.
An IDE is no substitute for an Intelligent Developer.