How to run a Java program from Notepad
Install JDK and set JAVA_HOME and PATH. 2. Write Java code in Notepad and save as HelloWorld.java. 3. Use NPPExec plugin to run commands: cd "$(CURRENT_DIRECTORY)", javac "$(FILE_NAME)", java "$(NAME_PART)". 4. Save script and assign shortcut for one-click compile and run.

To run a Java program from Notepad , you don't need an IDE like Eclipse or IntelliJ. You can write, compile, and execute Java code directly using Notepad and the command-line tools included with the JDK. Here's how.
1. Install Java Development Kit (JDK)
Before running Java from Notepad , ensure the JDK is installed on your system.
- Download the JDK from the Oracle or OpenJDK website.
- Install it and make sure to set the JAVA_HOME environment variable.
- Add the bin folder of the JDK (e.g., C:\Program Files\Java\jdk-xx\bin) to your system's PATH environment variable.
Verify installation by opening Command Prompt and typing:
java -versionjavac -version
You should see version info for both.
2. Write Java Code in Notepad
Open Notepad and write a simple Java program. For example:
public class HelloWorld {public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Save the file as HelloWorld.java in a folder of your choice (e.g., C:\JavaPrograms). Make sure the file name matches the class name exactly, including case.
3. Compile and Run Using NPPExec Plugin
Notepad has a plugin called NPPExec that allows executing external commands, such as compiling and running Java.
- Go to Plugins → NPPExec → Execute (or press F6).
- In the script window, enter the following commands:
javac "$(FILE_NAME)"
java "$(NAME_PART)"
This tells the system to:
- Change directory to where your Java file is saved.
- Compile the Java file using javac.
- Run the compiled class using java.
Click Save and give the script a name like "Run Java". You can now run this script anytime with a shortcut.
4. Shortcut for One-Click Execution
To make it faster:
- After saving the NPPExec script, go to Plugins → NPPExec → Advanced Options.
- Under "Menu items", select your saved script and click "Add/Modify" to add it to the menu.
- Optionally assign a shortcut key via Settings → Shortcut Mapper → Plugin Commands.
Now you can compile and run your Java program with just one click or keystroke.
Basically, Notepad becomes a lightweight Java coding environment when combined with JDK and NPPExec. It’s fast, simple, and great for learning or small projects.
The above is the detailed content of How to run a Java program from Notepad. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20570
7
13669
4




