Login/Register

How to: Compile and run a .java file in Windows with CMD

created by BasicSysAdmin

Tags: Windows, Windows 7, Java

Jun 04, 2016

Introduction

In this guide, I will be showing you how you can compile and run java files from windows 7 command prompt
Prerequisites

In order to follow this tutorial, you will need the following

  • Windows 7


  • Compiling and Running a .java file on Windows 7

    The first thing you will need to do is to open CMD through the start menu. You can do this by following the images below.

    Once you have this open, you can use the cd command to change to the directory where you have your java file stored. You can then use the dir command to make sure it is there. You can see an example of this using the image below.


    The final thing is to compile and run our program. The command for this is as follows
    javac Classname.java

    to run the program, we type in
    java Classname

    You can see a full example in the image below