Notepad++ is a free text and source code editor for Windows. You can use Notepad++ to write programs in Java and other programming languages. Using a plugin called "NppExec", you can compile and run Java programs using Notepad++. You'll need to have the proper Windows environment variables set up on your computer in order to do so. You will also need to write a short script to compile and run Java programs using the plugin. This wikiHow teaches you how to set to your system variables and compile and run Java programs in Notepad++
Running Java Programs with Notepad
- Get the latest version of Java SDK, Java RTE, Notepad++, and NppExec (the plugin for Notepad++).
- Change your computer's environment variables to allow for creating and running Java.
- Write Java code in Notepad++, save it as a Java file, then launch the NppExec plugin.
Steps
-
Make sure you have the latest version of Java SDK and Jave RTE . Java Software Development Kit (SDK) allows you to write programs for Java on your computer. Java Runtime Environment allows you to run Java programs on your computer. Even if you have both installed on your computer, check to make sure you are running the latest version of both Java SDK and Java RTE. You can download and install both Java SDK and Java RTE from the following links:
-
Download and install Notepad++. Notepad++ is not the same as Notepad that comes pre-installed on most Windows computers. Notepad++ is a separate free program you need to download and install. Notepad++ has autofill options for Java and other programming languages. It also allows you to install plugins that can be used to compile Java and other languages. You cannot compile Java in the regular version of Notepad. Use the following steps to download and install Notepad++:
- Go to https://notepad-plus-plus.org/downloads/ in a web browser.
- Click the latest release of Notepad++ at the top of the list.
- Scroll down and click Installer below "Download 64-bit x64."
- Click the installer file in your web browser or Downloads folder.
- Follow the instructions to complete the installation.
Advertisement -
Open Notepad++. It has an icon that resembles a pencil drawing on a sheet of paper. Use the following steps to open Notepad++ :
- Click the Windows Start icon.
- Type "Notepad".
- Click the Notepad++ icon (not Notepad).
-
Open the Plugins Admin or Plugins Manager. The Plugins Admin or Plugins Manager allow you to install plugins for Notepad++. If you are using a newer version of Notepad++, this is listed as "plugins Admin." On older versions of Notepad++, it will be listed as "Plugins Manager." Use the following steps to open the Plugins Admin or Manager:
- Click Plugins in the menu bar at the top.
- Click Plugins Admin or Plugins Manager .
- Click Show Plugins Manager .
-
Click the checkbox next to "NppExec" and click Install . NppExec is the plugin that is needed to compile and run Java programs in Notepad++.
-
Click Yes . This confirms you want to install the plugin and installs the NppExec. It will take a few minutes for the plugin to finish installing. Notepad++ will restart when the installation is complete.
-
Right-click "This PC" and click Properties . "This PC" is in the menu bar to the left. Right-click this option to display a pop-up menu. Then click Properties at the bottom of the pop-up menu. This opens the "About" menu in Windows Settings.
-
Click Advanced system settings . It's in the menu to the right below "Related settings" menu on the right. This opens the System Properties menu.
-
Click Environment Variables . It's near the bottom of the System Properties menu.
-
Click New below the System Variables box. There are two boxes in the Environment Variables menu. The one labeled "System Variables" is the one on the bottom. This opens a dialogue box that allows you to create a new system variable.
-
Type JAVA_HOME next to "Variable Name." It's the first bar at the top.
-
Click Browse Directory . It's the first button on the bottom. This opens a file browser that allows you to browse to the location of your Java installation.
-
Click the folder containing your Java installation and click Ok . On most Windows computers, you can find the Java installation by opening the following folders
- Click This PC .
- Click C:(OS) .
- Click Program Files .
- Click Java .
- Click jdk-[latest version]
- Click Ok .
-
Click Ok . This saves the new system variable.
-
Click the "PATH" system variable and click Edit . It's the variable labeled "Path" is in the box on the bottom. Click this variable to select it. Then click Edit below the box on the bottom.
-
Click New . It's the first option to the right. This creates a new blank environment variable at the bottom.
-
Type %JAVA_HOME%\bin and click Ok . This is the text you need to use to fill in the blank new system variable at the bottom. This creates a new environment variable that allows NotePad++ to access the "bin" folder. [1] X Research source
-
Click Ok . It's in the lower-right corner at the bottom of the "edit environment variables" menu. This saves the new environment variable path
-
Click Ok . It's at the bottom of the environment variables menu. This saves all of your changes and closes the menu.
-
Open Notepad++. It has an icon that resembles a pencil drawing on a sheet of paper. Use the following steps to open Notepad++:
- Click the Windows Start icon.
- Type "Notepad".
- Click the Notepad++ icon (not Notepad).
-
Use Notepad++ to write a Java program . Use Notepad++ to enter your Java code. It works like a regular Notepad, but also has predictive text and autofill features for most programming languages. This makes it much easier to write code in Notepad++ rather than regular Notepad.
-
Save your program as a Java file. It is recommended that you create a specific folder on your computer to save your Java program files in. Use the following steps to save your text files as Java files:
- Click File in the menu bar at the top.
- Click Save as in the drop-down menu.
- Select the folder you want to save your file in.
- Type a name for your file next to "File name."
- Select Java source file (*.java) in the drop-down menu next to "Save as Type."
- Click Save .
-
Launch the NppExec plugin. You can do so in the plugins menu. Use the following steps to execute the NppExec plugin:
- Click Plugins in the menu bar at the top.
- Hover your mouse cursor over NppExec .
- Click Execute .
-
Type the following commands in the Command(s) box. This is the script needed to compile Java programs. There are three commands you need to type. The first command opens the directory the current Java file is saved to. The second command compiles the current Java file. The third command executes the main class in the Java file. Place each of these commands on a separate line. Type each of the following commands and press Enter: [2] X Research source
-
cd $(CURRENT_DIRECTORY)
-
javac $(FILE_NAME)
-
java $(NAME_PART)
-
-
Click Save . It's the second button at the bottom of the screen. This displays a pop-up that allows you to name the script.
-
Type Java_Compile_Run as the script name and click Save . This gives the script a name. You can reuse this script anytime you need to compile a Java program inside Notepad++. It's a good idea to name it something that indicates that this script compiles Java programs.
-
Click Save . This saves the script used to compile Java programs.
-
Click Ok . This displays the console at the bottom of Notepad++ and compiles the program.
-
Compile Java programs using the Java_Compile_Run script. Use the following steps to compile future programs using this script you just created:
- Click Plugins in the menu bar at the top.
- Hover over NppExec .
- Click Execute
- Select "Java_Compile_Run" in the drop-down menu at the bottom.
- Click Ok .
Community Q&A
-
QuestionDo I need to install the JDK?JumpingDragonCommunity AnswerYes, you will need the JDK for any sort of programming, modding, or compiling software.
-
QuestionWhat are the basics of Java programming?Community AnswerIt would be helpful to learn basic data structures like integers, doubles, and strings, and how to manipulate them with math and functions.
-
QuestionHow can I run the code if I don't have the plugin installed or can't install it?RainbowMineBear 09Community AnswerYou can't.
Video
Tips
- There are other plugins for Notepad++ that can compile Java programs. However, NppExec is the one that is most commonly recommended.Thanks
Warnings
- Notepad++ is a light program. So it is hard to run a huge Java project. However, a normal Java class file that is under 10 MB should work fine.Thanks
References
About This Article
1. Download and install Notepad++.
2. Install the "NppExec" plugin from Plugins Admin.
3. Execute NppExec and enter the commands: "cd $(CURRENT_DIRECTORY)", "javac $(FILE_NAME)", "java $(NAME_PART)".
4. Save the script in NppExec.
5. Write a simple Java program in Notepad++.
6. Save the text file as a ".java" file.
7. Use the script in NppExec to compile the program.