Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between -source and -target compatibility?

When using the Java compiler (javac), we can specify two kinds of compatibility. One is using -source and the other is using -target. What is the difference between these two?

For example, -source 1.5 and -target 1.6?

Also, is there any case where we use a different source and target compatibility level?

like image 467
Adam Lee Avatar asked May 19 '12 08:05

Adam Lee


People also ask

What is compatibility in a relationship?

Compatibility in a relationship means that both partners understand and accept each other's life philosophy and goals, as well as genuinely enjoy being around each other without feeling preoccupied by what they feel needs to change within their partner.

What is difference between compatible and incompatible?

Compatibility controls the partitioning of different elements during melting. The compatibility of an element in a rock is a weighted average of its compatibility in each of the minerals present. By contrast, an incompatible element is one that is least stable within its crystal structure.

What is more important in a relationship chemistry or compatibility?

Compatibility is deeper and more logical than chemistry. “[Compatibility is about] the various elements of lifestyle, values, and goals that feel in line with one another and how that manifests in your interactions,” says AH.

Does compatibility matter in a relationship?

Ted Hudson, PhD, told Thrive Global that his research has shown "there's no difference in the objective compatibility between couples who are unhappy and those who are happy." He found compatibility wasn't an issue for couples who were happy in their relationships: Those couples made it clear that their will to keep ...


2 Answers

From the javac docs:

-source Specifies the version of source code accepted.

-target Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM.

In your example:

-source 1.5 and -target 1.6 

This would be used to make sure that the source code is compatible with JDK 1.5, but should generate class files for use on JDK 1.6 and later.

Quite why you would do this is another matter.

like image 161
skaffman Avatar answered Oct 09 '22 15:10

skaffman


The -source indicates what level of compliance your source code has: are you using Annotations? Then you would need at least 1.5; are you using @override on interface implementations, you would need 1.6 etc

The -target specifies what Java version you want to be able to run your classes on. You could use a Java SE 7 compiler and compile to run on Java SE 1.5.

like image 25
raphaëλ Avatar answered Oct 09 '22 16:10

raphaëλ