Use Notepad++ to Compile and Run Java Programs

Sheeraz Gul Mar 09, 2022
Use Notepad++ to Compile and Run Java Programs

Notepad++ can run the programs of different languages if the corresponding plugin is installed. This tutorial will demonstrate how to compile and run Java programs in Notepad++.

Use Notepad++ to Compile and Run Java Programs

The following are steps to use Notepad++ to compile and run your Java programs.

  • Prerequisites

    If you haven’t already installed Java and Notepad++, the first step is to install JDK and Notepad++.

    Download and install JDK, Java Runtime Enviroment, and Notepad++.

    Once the pre-requisites are installed, we can go to the next step.

  • Install NppExec Plugin in Notepad++

    Go to the Plugins menu option Plugins Admin and install the NppExec plugin.

    Plugin Menu

    Install NppExec

    Don’t be confused with the second picture. If the NppExec is already installed, it will not be shown in the list. Notepad++ will be closed to install the plugin; once the plugin is installed, go to the next step.

  • Set Environment Variables

    Go to the start menu and search Environment Variable and open as mentioned in the pictures below:

    Search Environment Variable

    Open Environment Variable

    In the user variable section, click new and add the JAVA_HOME variable; the directory should be your JDK directory:

    JAVA_HOME

    Now press edit for the path in the system variables list:

    System Path

    Click New and add %JAVA_HOME%\bin then click ok three times till the properties menu is closed:

    System Path Variable

    At this moment, you will need to restart your pc so the environment variables can work properly.

  • Run Java Program on Notepad++

    In Notepad++, create a new file, write a Java program, and save it with a .java extension, which is, in our case, Java_notepadpp.java.

    Save .java

    Once the program is saved, go to plugins and open Execute NppExec Script from NppExec.

    Save Commands

    Write the following command in the box opened:

    cd $(CURRENT_DIRECTORY)
    javac $(FILE_NAME)
    java $(NAME_PART)
    

    Save the commands as Java_Run.

    Save Commands As Java_Run

    Once the commands are saved, we can now run Java programs. Go to plugins and open Execute NppExec Script from NppExec.

    Execute NppExec Script

    Select Java_Run and click ok to run the Java file in the console; see the output below.

    Run the Java File in the Console

    The Java program is successfully compiled in Notepad++. Now, you can run Java programs in Notepad++.

    Here is another example:

    public class Java_notepadpp {
    	public static void main(String args[])
    	{
    	System.out.println("This is a demo to run the JAVA program in Notepad++");
    	}
    }
    

    Let’s run and get the output:

    Final Output

    The Java program is successfully compiled in Notepad++.

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook