简体   繁体   中英

How to compile and run lower version java to higher version?

I am currently working in jdk 1.5 version. I want to compile and execute code in jdk 1.6 version.

How can i do this?

It's a bit unclear what you're asking.

If you're asking whether you can compile code with JDK 1.5 and run it with JDK 1.6, yes, that's fine. 1.6 can run code compiled with 1.5 without trouble. You won't be able to make use of any of the Java 6 (1.6) compile-time or API enhancements, of course. To do that, you'd have to compile with the 1.6 (or higher) JDK.

If you're asking how to start using 1.6, just install it and start using it. (That's a very general and somewhat vague answer, but then, it's a very general and vague question.)

Install JDK 1.6 and re-set your JAVA_HOME variable. Normally, the code from the older platform versions will work on newer ones.

if you are using an IDE, there must be an option with the location of java compiler, change to the directory of your installation of your new jdk.

else, change the value of your environement variable JAVA_HOME to the directory of your installation of your new jdk.

you don't have any change to do in your code

jdk 1.6支持jdk 1.5中的所有功能。因此,您可以在jdk1.6上编译并运行程序。

Use the -target and -source flags to tell the compiler what source version you are using or what target version you plan to run it on

javac -target 1.6 -source 1.5 [classes to compile etc]

http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html#options

Java is backwards compatible, so you can compile and run your application on 1.6 without any problems but maybe with some warning messages on compile.

You can use also the arguments -target and -source. More info here

Have a look at the java documentation about compatibility issues. Find here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM