In addition to Anand Gupta's answer, make sure no other java except for the one you need is used.
Run which java
(where java
for Windows) and see which java executables are used.
Just delete the ones you don't want to use and if the one you need is not present, add it to PATH.