71

I am using Java 7 SDK and IntelliJ IDEA IDE.

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

I am still not able to use Java 7 features. After a bit of googling I could use all the features after setting project language level to 7(Diamond, ARM, multicatch etc). What exactly is this? If this has some relationship to syntax based on JDK in use what is level 8(Lambda, annotations etc)? Java 8 isn't released yet. Java 8 is expected in March 2014 according to Wiki. Someone please explain this language level concept.

James Roper
  • 12,695
  • 46
  • 45
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289

3 Answers3

103

The Language level setting sets which features the code assistance in the editor should support. For example, if you're using JDK 1.7 but want your code to be compatible with JDK 1.6, you can set the language level lower than your actual JDK supports (6.0 in the case of JDK 1.6) and only get refactorings/syntax suggested that are supported on 1.6 and lower. Depending on your compiler, it may also give the compiler options to remove support for newer syntax elements.

The 8.0 (which, as you're guessing corresponds to Java 8) is available for people that want to experiment with one of the Java 8 snapshots that are available. Since Java 8 isn't released, language level 8.0 may very well change before release.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • So are these settings which sets which features the code assistance in the editor should support embedded in the IDE or is it fetched over network with updates? – Aniket Thakur Jul 18 '13 at 05:57
  • @AniketThakur It seems to be updated along with the IDE itself, at least I've never noticed changes that did not go along with an IDE update. – Joachim Isaksson Jul 18 '13 at 06:19
  • 22
    Set language level via `File > Project Structure > Project > Project language level` – JohnK Oct 22 '14 at 19:26
  • But in idea 14 we have 9 level. What does means 9 level ? – Mikhail Dec 04 '14 at 14:39
  • 1
    @Mikhail I would assume [JDK 9 snapshot versions](http://www.oracle.com/technetwork/java/javamail/ea-jsp-142245.html). – Joachim Isaksson Dec 04 '14 at 16:20
  • 2
    I already had Project language lever right, but editor kept complaining it was this: `File > Project Structure > Module (sources tab)> language level` – juanmf May 25 '17 at 21:13
  • 1
    IDEA has really bad UX compared to Eclipse. Same setting one need to at multiple places. Thanks @juanmf your tip helped. – vikramvi Jul 24 '17 at 10:56
5

As per the documentation within section Exploring the General Project Settings at the IntelliJ Wiki, the project language level impacts the intellisense provided by the IDE.

It also dictates the behavior of the compiler being used by IntelliJ when it compiles your Java code as you develop.

This setting tells all the facilities of the compiler that would be available for the project. For e.g. setting the language level to JDK 5 will allow the IntelliJ to recognize keywords such as enum that are present within the source code.

Prahalad Deshpande
  • 4,709
  • 1
  • 20
  • 22
5

If you look at the options for the javac Java compiler command, you'll see that the -source and -target options allow you to compile against alternate versions of Java. I'm not sure to which option IntelliJ's language level setting corresponds (it is likely -source), but it essentially tells IntelliJ to use the provided Java SDK (in the Project SDK field) in the specified Java language version instead of the latest provided by said SDK.

So while you have Java 7 installed, you could set the language level to 6.0, and IntelliJ will compile your code against the Java 6 specification instead of the Java 7 spec. This includes all of the real-time suggestions and code checking done as you type.

The Java 8 option is there likely due to the fact that beta builds of Java 8 are available for testing.

I've never experimented with what would happen if you set a language level to something higher than the JDK version.

ajp15243
  • 7,704
  • 1
  • 32
  • 38
  • In my case, if you set a language level to something higher than the JDK version, you will get an error. Error: LinkageError occurred while loading main class com.practice.Main java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=com/practice/Main, offset=6 – max Mar 17 '21 at 08:40