How to run java in cmd

How to run java in cmd

To run a Java program in the Command Prompt (cmd), you will need to have the Java Development Kit (JDK) installed on your computer. The JDK includes the Java runtime environment and tools for compiling and executing Java code.

Once you have the JDK installed, you can follow these steps to run a Java program in the Command Prompt:

  1. Open the Command Prompt by typing "cmd" in the search bar on your Windows taskbar and pressing Enter.
  2. Navigate to the directory where your Java program is saved. For example, if your program is saved in the C:\Programs directory, you can navigate there by typing cd C:\Programs and pressing Enter.
  3. Compile the Java program by typing javac [filename].java and pressing Enter. This will create a .class file with the same name as your Java source file.
  4. Run the compiled program by typing java [filename] and pressing Enter. This will execute the Java program and any output will be displayed in the Command Prompt.

Note: Replace [filename] with the name of your Java program.

Created Time:2017-11-01 20:42:48  Author:lautturi