Eclipse is an IDE and, as such, has (at least) two versions of Java: the one that it uses to run ( JAVA_HOME ) and the JVM that it uses to run your application. These two should not be the same.
So, to fix your problem, you need to study the Eclipse settings, in particular the Installed JREs , which gives you a list of Java virtual machines that Eclipse will use to run Java code from projects. I assume that there will be several records, and by default there will be JRE instead of JDK.
Make sure you have the JDK in the list, and then go to your project. In the project, you can choose which Java virtual machine to use in the Java Build Path → Libraries .
[EDIT] Take a look at the last screenshot: you configured Eclipse to use C:\Program Files\Java\jdk1.8.0_31\jre , which means that you pointed it to a JRE inside the JDK. Instead, use C:\Program Files\Java\jdk1.8.0_31 (without \jre at the end).
[EDIT 2] If you delete the jre folder, Java will stop working. Any JDK also contains a JRE. The JRE contains rt.jar with String.class and the like. The Java compiler is located in tools.jar , which is in the JDK.
If recreating the JRE entry in Eclipse does not help, you will have to add it manually to the class path.
You can use the variable ("Add Variable ...") to make sure that Eclipse updates the path when switching to a new / different JRE. Try JAVA_HOME with the extension lib/tools.jar
source share