How to Compile and Run Java Programs Using Notepad++

Download ArticleDownload Article

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 How.com.vn teaches you how to set to your system variables and compile and run Java programs in Notepad++

Things You Should Know

  • You'll need 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.
Part 1
Part 1 of 3:

Getting What You Need

Download Article
  1. How.com.vn English: Step 1 Make sure you...
    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:
  2. How.com.vn English: Step 2 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
  3. How.com.vn English: Step 3 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).
  4. How.com.vn English: Step 4 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.
  5. Step 5 Click the checkbox next to "NppExec" and click Install.
    NppExec is the plugin that is needed to compile and run Java programs in Notepad++.
  6. How.com.vn English: Step 6 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.
  7. Advertisement
Part 2
Part 2 of 3:

Setting the Environment Variables

Download Article
  1. How.com.vn English: Step 1 Open File Explorer icon.
    It has an icon that resembles a folder with a blue clip. You can click the icon in the taskbar at the bottom or press Windows Key + E to open File Explorer.
  2. Step 2 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.
  3. How.com.vn English: Step 3 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.
  4. How.com.vn English: Step 4 Click Environment Variables.
    It's near the bottom of the System Properties menu.
  5. How.com.vn English: Step 5 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.
  6. Step 6 Type JAVA_HOME next to "Variable Name."
    It's the first bar at the top.
  7. How.com.vn English: Step 7 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.
  8. How.com.vn English: Step 8 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.
  9. How.com.vn English: Step 9 Click Ok.
    This saves the new system variable.
  10. Step 10 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.
  11. How.com.vn English: Step 11 Click New.
    It's the first option to the right. This creates a new blank environment variable at the bottom.
  12. How.com.vn English: Step 12 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]
  13. How.com.vn English: Step 13 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
  14. How.com.vn English: Step 14 Click Ok.
    It's at the bottom of the environment variables menu. This saves all of your changes and closes the menu.
  15. Advertisement
Part 3
Part 3 of 3:

Compiling a Java Program in Notepad++

Download Article
  1. How.com.vn English: Step 1 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).
  2. How.com.vn English: Step 2 Use Notepad++ to...
    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.
  3. How.com.vn English: Step 3 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.
  4. How.com.vn English: Step 4 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.
  5. How.com.vn English: Step 5 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]
    • cd $(CURRENT_DIRECTORY)
    • javac $(FILE_NAME)
    • java $(NAME_PART)
  6. How.com.vn English: Step 6 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.
  7. How.com.vn English: Step 7 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.
  8. How.com.vn English: Step 8 Click Save.
    This saves the script used to compile Java programs.
  9. How.com.vn English: Step 9 Click Ok.
    This displays the console at the bottom of Notepad++ and compiles the program.
  10. How.com.vn English: Step 10 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.
  11. Advertisement

Community Q&A

Search
Add New Question
  • Question
    Do I need to install the JDK?
    How.com.vn English: JumpingDragon
    JumpingDragon
    Community Answer
    Yes, you will need the JDK for any sort of programming, modding, or compiling software.
  • Question
    What are the basics of Java programming?
    How.com.vn English: Community Answer
    Community Answer
    It would be helpful to learn basic data structures like integers, doubles, and strings, and how to manipulate them with math and functions.
  • Question
    How can I run the code if I don't have the plugin installed or can't install it?
    How.com.vn English: RainbowMineBear 09
    RainbowMineBear 09
    Community Answer
    You can't.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Video

      Tips

      • There are other plugins for Notepad++ that can compile Java programs. However, NppExec is the one that is most commonly recommended.


      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      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.
      Advertisement

      About This Article

      How.com.vn English: Travis Boylls
      Written by:
      How.com.vn Technology Writer
      This article was co-authored by How.com.vn staff writer, Travis Boylls. Travis Boylls is a Technology Writer and Editor for How.com.vn. Travis has experience writing technology-related articles, providing software customer service, and in graphic design. He specializes in Windows, macOS, Android, iOS, and Linux platforms. He studied graphic design at Pikes Peak Community College. This article has been viewed 185,429 times.
      How helpful is this?
      Co-authors: 11
      Updated: March 30, 2024
      Views: 185,429
      Categories: Java
      Article SummaryX

      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.

      Did this summary help you?

      Thanks to all authors for creating a page that has been read 185,429 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement