Finally this problem is solved. Thank you to @RobSpoor for his suggestion.
I ran Get-Command java
in PowerShell and it pointed out java source to below below directory.
C:\Program Files\Common Files\Oracle\Java\javapath . When I checked my PATH variable this directory path was included in the path. After removing it my java and javac are now pointing to JDK1.8.