I am compiling my web app in Netbeans against Java EE 5. I know that the
String.isEmpty() function is only supported in Java 6. Having said that, I can still compile my project using the
.isEmpty() in my code.
How come Netbeans is allowing my web app to compile if I am compiling against Java EE 5?Answer1:
The compiler level is not equal to the JDK level you use for compiling. The compiler level only checks for the syntax and of course creates a different output. But the compiler itself will use the jdk on your classpath so if you compiled with java 5 option but with the java 6 jars on your classpath the code will compile without an error. You should check your classpath.Answer2:
As many have pointed out, Java EE versions are not strictly tied with Java SE (JDK) versions. Mostly, they require a minimal Java SE version but are compatible with later versions.
Java EE 5 specification (<a href="http://download.oracle.com/otndocs/jcp/javaee-5.0-fr-eval-oth-JSpec/" rel="nofollow">downloadable PDF here</a>) says:
This specification requires that containers provide a Java Compatible™ runtime environment, as defined by the Java 2 Platform, Standard Edition, v5.0 specification (J2SE)
Since JSE versions are backwards compatible, you can take a container compatible with Java 5 and run it on top of Java SE 6 or Java SE 7.
You can check the compatibility level that Netbeans is using by checking the project "<em>Properties</em> > <em>Source</em> > <em>Source/Binary Format</em>"
If you still have doubts about "Java vs Java EE" you can look for several questions here on SO about the difference between Java SE and Java EE.