Two ways to Execute Java Program

  • Command Prompt
  • Integrated Development Environment (IDE)

Using Command Prompt :

1. Let us create a file with Simple Java Program code
//Create a Class
public class sample {

// Add Main Method - Java will Start the Execution from Main Method
public static void main(String[] args) {

// Add Print Statement
System.out.println("Welcome to Learn More");
}
}

2. Save the file with extension of ".java" ( File name should be same as class name )


3.  Go to the file location ( I have saved the file under Music)



4. Click on file Path and Enter the keyword of "cmd". Once Click on Enter, Command Prompt will be open along with your file path




5. Let's compile our program. Enter the command "javac sample.java" and click enter


6. Execute the program with the help of "java sample" command, then click enter


7. It will Displays the Output in command prompt



Using Integrated Development Environment (IDE) :

  • IDE is a software application which is used to develop, debug and manage applications.
  • It consists of at least program code editor, compiler and debugger.

  • There are many IDE's available for java application development in marketplace.                                
    • Eclipse 
    • IntelliJ IDEA 
    • NetBeans

If you want the IDE, Download from official site and Install the Software.

!!!  If you are looking more features, IntelliJ is a good choice !!!

1. Once Installed the IntelliJ, Open the IDE ( Name the new project and change its location if required )



 2. Select the language, build System and JDK Which is mentioned in above image. then, Click on "Create" Button

3. Create a Class under src/main/java 



4. Enter the Class Name like Sample and Select "Class" then Click Enter Button



5. Write the sample program in class file



6. Right Click it and then click on "Run"



7.  IDE will automatically compiles the Code, displays the output in console