Even though we have installed the latest version of Java in our machines, the Eclipse IDE will set the Compiler Compliance level less than the currently installed Java version. For example, I have installed Java version 1.8 in my machine but my Eclipse IDE compiler compliance level is set to 1.4.
Lets find out the compiler compliance level in Eclipse IDE by following the below steps -
1. Launch Eclipse IDE
2. Select 'Preferences' options from the 'Windows' menu as shown below -
3. Observe that 'Preferences' dialog is displayed as shown below -
4. Select 'Java' -> 'Compiler' option from the left side and observe that the 'Compiler Compliance level' set to 1.4 is displayed -
5. Click on 'OK' button to close the dialog.
In order to use the latest features of Java which were introduced after 1.4 version of Java in any Project, we have to change the Compiler Compliance Level to the latest version that is supported by Eclipse IDE. Lets implement this by following the below steps -
1. Create a new Java Project 'Project 48' in Eclipse IDE, as shown below -
2. Create a new Java Class file 'CompilerComplianceLevelDemo.java' with main( ) method as shown below -
3. Now lets implement a new feature say 'AutoBoxing' which was introduced after 1.4 version of Java and observe that a compiler error will be displayed as shown below -
This is because, JVM is compiling our Java Program code with the compiler version of 1.4, even though we have installed the latest version of the Java (i.e. 1.8 version in my machine). In order to overcome this kind of problem, we have to first change the compiler compliance level of the project to 1.8 after creating any Java Project in Eclipse IDE by following the below steps.
4. Right Click on the Project 'Project 48' and select 'Properties' option
5. In the Properties dialog, select 'Java Compiler' option on the left and change the Compiler Compliance level of the Project from 1. 4 to the latest supported version (i.e. 1.7 in my machine) -
6. Click on 'Apply' and 'OK' buttons in the above dialog and observe that the error in the AutoBoxing code got resolved as shown below -
Hence after creating any Java Project, change the compiler compliance level to the latest version provided by the Eclipse IDE, to avoid any errors which occur when you are using the features that are introduced in the latest versions of the Java.
Please comment below to feedback or ask questions.