How to Compile and Run Java Programs in CMD or ECLIPSE

create and run java class program in eclipse

To Compile a Java Program, You need to install a Java Compiler or Java SE (Java Standard Edition) or JDK (Java Developer Kit). It is just an installable software.

To Create and Edit a Java Program, You need a Text Editor or an advanced IDE (Integrated Development Environment) Software. The Most popular Java IDE is ECLIPSE.

To Run a Java Program, You need a JRE (Java Runtime Environment) Software and CMD (Command Prompt) Tool. Java IDE Software includes GUI and Keyboard Options to execute CMD commands without directly using it.

Download Required Java Compile and Run Tools for Windows 10

  1. First complete downloading java and setting up JAVA Environment on your PC on Windows operating system.
  2. Now download a Text Editor like Notepad++ OR an ECLIPSE IDE for Java Software. These tools are free of cost. Visit Eclipse Packages site to get the latest IDE tools.

1. Compile and Run Java Programs using a Text Editor like Notepad++

Step 1: Create a new folder for keeping Java Files.

Step 2: Open Notepad++ and Type the below sample Java Program.

class Hello
{
  public static void main(String args[])
  {
    System.out.println("Hello Last Minute Java..");
  }
}
type or edit java program in notepad++ text editor

Step 3: Save the program as Hello.java. File name should be the same as that of a class name.

Step 4: Now open Command Prompt or CMD. Go to the folder using CD (Change Directory) command.

Step 5: Compile the java program using JAVAC command in lower case. Mentioning file name extension is mandatory.

C:\testingfolder>javac Hello.java

Step 6: Run the java program using JAVA command in lower case. We have dropped file name extension here for running.

C:\testingfolder>java Hello
Hello Last Minute Java..

2. Compile and Run Java Programs using ECLIPSE IDE Editor

Step 1: Create a new Java Project with any name.

Step 2: Right Click on the Project Name, click New and choose Class File. Give Class name as Hello.

Step 3: Type the below java program.

class Hello
{
  public static void main(String args[])
  {
    System.out.println("Hello Last Minute Java..");
  }
}

create and run java program in eclipse for the first time

Step 4: Click the green icon to execute the Java Program and see the output in the bottom Console Pane. Note that this process does both compiling and running the java program by Eclipse.

 

Congratulations on compiling and running your first java program. Share this tutorial with your friends and colleagues to encourage authors.