-2

The problem is that my computer is looking in the wrong place for java. I don't know how to get it to look in the correct place.

When i type: javac -version in my command prompt it tells me the version is jdk 13. It is looking in the correct path which is

C:\Program Files\jdk 13\bin

or something like that

however when I type: java -version it says that nothing can be found in

C:\Program Files (x86)\Java\jre1.8.0_241\lib\i386\jvm.cfg

this is not the right directory

SO how can i tell my computer to go to the right place when trying to run my program?

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • 1
    Please try the following: You've got a .java file, open the console in the directory where the .java file is located, type "javac yourfile.java", press enter, now if that worked type "java yourfile" (without .java) and thats it. (I would strongly suggest to use an IDE like Eclipse or IntelliJ) – JavaMan Feb 06 '20 at 19:28
  • You must set the system environment PATH to point to your jdk13/bin folder and JAVA_PATH to point to your jdk 13 folder. – Victor Polo De Gyves Montero Feb 06 '20 at 19:28
  • And take a look at https://www.poftut.com/how-to-set-java-jre-and-jdk-home-path-and-environment-variables-on-windows/ (as Victor Polo De Gyves Montero mentioned you have to set the PATH and JAVA_PATH) – JavaMan Feb 06 '20 at 19:30
  • 'javac myfile' works fine it complies just fine. When i RUN it with 'java myfile' it says Error: could not open `C:\Program Files (x86)\Java\jre1.8.0_241\lib\i386\jvm.cfg' – Alfredo Lepe Feb 06 '20 at 19:31
  • I think that i did set the Path already I'm not sure why but the path is set for javac but NOT for java and idk what to input into the path environment to make it know it has to work for javac and java – Alfredo Lepe Feb 06 '20 at 19:31
  • maybe take a look at https://stackoverflow.com/questions/19565237/java-comand-works-but-not-javac – JavaMan Feb 06 '20 at 19:34
  • The only environment variable that matters is `Path`. No JDK tool uses JAVA_HOME or JAVA_PATH. Some other tools that make use of Java will require JAVA_HOME, but `java` and `javac` do not. – VGR Feb 06 '20 at 20:45

1 Answers1

-1

javac is converting java files into bytecode. java is running bytecode. The fact that javac -version shows a proper version means that you can build Java projects and the fact that java -version is not showing a proper value indicates that you do not have a proper runtime environment.

Setting the JAVA_HOME environment variable to a correct path should help.

https://www.tutorialspoint.com/what-is-the-difference-between-javac-java-commands

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175