Question

In the documentation of maven it is written

https://maven.apache.org/plugins/maven-compiler-plugin/

"Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler."

The java version we use is java 7.

What will be the benefit if i will change the target settigs to 1.7?

Will the code run faster?

Will there be less memory usage?

Était-ce utile?

La solution

Java 7 means JDK/JRE 1.7. However, the real name is Java 7 (the 1.X is old naming convention left over from before 5 and/or refers to internal version number).

Target versions mean you compile the bytecode to adhere to the specs (supported features) of a specific java version. So, if you want to compile code that will run on a machine running java 1.6 JVM you need to compile your code targetted for Java 1.6 and you should limit yourself to the syntax/options available for java 1.6.

Otherwise you will get a java min/max version. Memory usage depends on the actual JVM running the code and if it is a server JVM or standard JVM.

In general you should target for what your target machine JVM supports and not higher. Your code must also not use features introduced in a later version than your targetting (e.g. diamond operator in 1.6 because it was introduced in 1.7).

Update: About naming conventions:

Have a look at http://en.wikipedia.org/wiki/Java_version_history .

It's very interesting that actually there was a change in the naming conventions after Java 5 from 1.5 to 5.

Codename Tiger. Originally numbered 1.5, which is still used as the internal version number. The number was changed to "better reflect the level of maturity, stability, scalability and security of the J2SE."

Versions - from wikipedia:

  • JDK Alpha and Beta (1995)
  • JDK 1.0 (January 23, 1996)
  • JDK 1.1 (February 19, 1997)
  • J2SE 1.2 (December 8, 1998)
  • J2SE 1.3 (May 8, 2000)
  • J2SE 1.4 (February 6, 2002)
  • J2SE 5.0 (September 30, 2004)
  • Java SE 6 (December 11, 2006)
  • Java SE 7 (July 28, 2011)
  • Java SE 8 (March 18, 2014)
  • Java SE 9
  • Java SE 10

Autres conseils

The compiler does almost no optimisations and which version you use has almost not difference to performance.

The main difference is the features available in different versions. Java 8 has more features than Java 7 which has more than Java 5.0 did. If you want to use the newer features, you need a newer version but if you only use an older version it will make difference to the performance at runtime.

It is the JVM you run the code on which determines the performance. In general, newer versions perform better however, Java 8 may or may not be faster than Java 7 as it is new. Once it has been out for a while it could be faster than Java 7.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top