How to Use Notepad++ to Compile and Run Java Programs
Notepad++ is not just your ordinary text editor; it’s a highly versatile and extensible platform that can cater to a wide range of programming languages thanks to its plugin system.
In this tutorial, we’ll focus on one specific use case: how to use Notepad++ to compile and run Java programs. While Notepad++ doesn’t natively execute Java code, it can be transformed into a powerful Java development environment with the right plugins and configurations.
Use Notepad++ to Compile and Run Java Programs
If you want to run Java programs within Notepad++, you can easily achieve this by following these steps:
-
Prerequisites
Before you begin, ensure that you have Java Development Kit (JDK) and Notepad++ installed on your system. If you haven’t already installed them, you can download and install them from the following links:
-
JDK: Download JDK
-
Java Runtime Environment: Download JRE
-
Notepad++: Download Notepad++
Once you have these prerequisites in place, proceed to the next step.
-
-
Install the NppExec Plugin in Notepad++
Open Notepad++ and navigate to the
Plugins
menu. Then, choosePlugins Admin
to open the plugin manager.Look for the
NppExec
plugin in the list and install it if it’s not already installed.Note: If the
NppExec
plugin is already installed, it won’t appear in the list. -
Set the Environment Variables
To configure environment variables for Java, follow the instructions below:
Open the start menu and search for
Environment Variable
.Click on
Edit the system environment variables
.In the user variable section, click
New
and add a variable namedJAVA_HOME
. Set the variable value to the directory where your JDK is installed.Next, find the
Path
variable in the system variables list and clickEdit
.Click
New
and add%JAVA_HOME%\bin
to the list of paths. ClickOK
three times to save and close the properties menu.At this point, you will need to restart your computer for the environment variables to take effect.
-
Run Java Program in Notepad++
Now, you’re ready to compile and run Java programs in Notepad++!
Open Notepad++, create a new file, write your Java program, and save it with a
.java
extension (e.g.,Java_notepadpp.java
).Go to the
Plugins
menu and selectExecute NppExec Script
from theNppExec
submenu.In the script box that appears, enter the following commands:
cd $(CURRENT_DIRECTORY) javac $(FILE_NAME) java $(NAME_PART)
Save these commands as
Java_Run
.With the commands saved, you can now run Java programs.
Again, go to
Plugins
and selectExecute NppExec Script
fromNppExec
.Choose
Java_Run
and clickOK
to run your Java file in the console. You will see the program’s output in the console.There you have it! You have successfully compiled and run a Java program within Notepad++. Feel free to explore more Java programming in Notepad++.
As an example, here’s a simple Java program:
public class Java_notepadpp { public static void main(String[] args) { System.out.println("This is a demo to run a Java program in Notepad++"); } }
Let’s run it to see the output:
Your Java program is now successfully compiled in Notepad++.
Now, whenever you want to compile and run your Java program in the future, go to the Plugins
menu again.
Select Execute NppExec Script
from the NppExec
submenu.
Lastly, choose the script you saved in the previous step (e.g., Java_Run
) and click OK
.
This will compile and run your Java program, and any compilation errors will be displayed in the console.
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