Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't run java program from the CMD my paths may be we

I’m trying to run Welcome.java program from the cmd

public class Welcome {  
  public static void main(String[] args) { 
    System.out.println("Welcome to Java!");
  }
}

Before I mention what I have been trying, when I type where java into cmd I get two different paths

C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
D:\java\jdk\bin\java.exe

First I set my current directory to where welcome.java is.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

C:\Users\user_name\Desktop

Then I check if the file exists and it does.

dir

Then I try to compile the file by typing

javac Welcome.java

Then I check again to see if welcome.class has been created, I think the issue might be here since I dont see any welcome.class file. I don’t know if this is because something is wrong with my paths.

dir

Then I attempt to run the java interpreter

java Welcome

After this I don’t see any output, it just returns to the next system prompt.

>Solution :

To execute these 2 command, you must to configure your system variables.

  1. You must to add into your path variable D:\java\jdk\bin or %JAVA_HOME%\bin.

  2. You should configure JAVA_HOME creating one new system variable: JAVA_HOME=D:\java\jdk

To add this variables you can follow this link: https://docs.oracle.com/en/database/oracle/machine-learning/oml4r/1.5.1/oread/creating-and-modifying-environment-variables-on-windows.html#GUID-DD6F9982-60D5-48F6-8270-A27EC53807D0

You have to restart your PC to load the changes.

Then, execute:

javac Welcome.java

This command should create one Welcome.class in the same directory.
Fianlly, You can execute the command

java Welcome

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading