Compile with java 6 from java 8 JDK installed

I need to compile my source code with Java 6 for university. I currently have Java 8 JDK installed on my PC (Linux). How to compile in Java 6?

ps I understand that I will not be able to use any Java 7 or 8 features.

pps I understand that the java 6 source code will compile using the Java 8 JDK, however I found that I accidentally use the Java 6 post functions in my programs when compiling at home. When I try to compile the source code on lab computers in uni, I encounter a bunch of errors. for example, the inability to apply an object to a primitive.

+4
source share
3 answers

SDK - .

, javac. javac -, Java. - -bootclasspath -extdirs.

-target version

, . , JVM. : 1.1, 1.2, 1.3, 1.4, 1.5 ( 5), 1.6 ( 6), 1.7 ( 7) 1.8 ( 8).

-target -source:

  • -source , -target 1.8
  • -source 1.2, -target 1.4
  • -source 1.3, -target 1.4
  • -source 1,5, -target 1.8
  • -source 1.6, -target 1.8
  • -source 1.7, -target 1.8
  • -source -target -source.

-bootclasspath bootclasspath

. , (:) , JAR ZIP-.

(, -bootclasspath), rt.jar JRE ( JDK) .

+5

% javac -target 1.6 <whatever you want to compile>
+3

, Java 6, Java 8. java .

java , :

export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)

-1

Source: https://habr.com/ru/post/1607391/


All Articles