Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Notepad++ can edit Java files and launch Java commands, but it does not compile Java itself. The JDK provides javac, the compiler; Notepad++ can run that compiler for you. For a first program, save a .java file, compile it with javac, then run the resulting class with java.

What you need

  • A Windows computer with Notepad++ installed.
  • A Java Development Kit (JDK). The JDK includes javac and java. A runtime-only installation may include java but not the compiler.

Install a JDK from Oracle’s Java downloads page or choose a reputable OpenJDK distribution. Java release numbers change, but the basic commands below are stable across modern JDKs.

Open Command Prompt and check that both tools are available:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
java -version
javac -version

Each command should print a version. If java works but javac does not, install a JDK or add its bin directory to Windows PATH. After changing PATH, reopen Command Prompt and restart Notepad++ so they receive the updated setting.

1. Create and save a Java file

In Notepad++, enter this small program:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}

Save it as HelloWorld.java. Because the class is declared public, its name must match the filename exactly, including capitalization. Java is case-sensitive. In Windows Explorer, check that the file is not really named HelloWorld.java.txt. You can select Language → Java in Notepad++ for syntax highlighting, but that setting does not compile the program.

2. Compile and run from Command Prompt

In Command Prompt, change to the folder where you saved the file. Replace the example path with your own; keep the quotes if the path contains spaces:

cd /d "C:UsersYourNameDocumentsJava"
javac HelloWorld.java
java HelloWorld

javac HelloWorld.java compiles the source and normally creates HelloWorld.class in the same folder. java HelloWorld launches that class. Do not include .java or .class in this normal class-launch command. A successful run prints:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Hello, world!

This is the most useful sequence to learn even if you later trigger it from Notepad++: it makes clear which step failed and shows the compiler’s output.

3. Compile from Notepad++ with Run

For a one-off compile, save the file, choose Run → Run…, and enter:

javac "$(FULL_CURRENT_PATH)"

Click Run. The quotes protect paths containing spaces, and $(FULL_CURRENT_PATH) is a Notepad++ variable for the active file’s full path. The command compiles the file; it does not also run the resulting program.

You can save a Run command for reuse and assign it a keyboard shortcut. Notepad++ is still only launching the external compiler. If it cannot find javac, verify the JDK and PATH, then restart Notepad++.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Compile and run from Notepad++ with NppExec

If you want one Notepad++ command to save, compile, and run a simple program, use the optional NppExec plugin. It is not built into Notepad++. Install it through Notepad++’s plugin manager if it is available for your version, then create and run an NppExec script such as:

npp_save
cd "$(CURRENT_DIRECTORY)"
javac "$(FILE_NAME)"
java "$(NAME_PART)"
  • npp_save saves the current document before compilation.
  • $(CURRENT_DIRECTORY) is the folder containing the file; changing to it gives the compiler and launcher the expected working directory.
  • $(FILE_NAME) is the source filename, including its extension.
  • $(NAME_PART) is the filename without its extension, which is the class name for this example.

NppExec variables use parentheses, as in $(FILE_NAME), not shell-style curly braces. This script assumes an unpackaged single-file program whose public class has the same base name as the file. It also continues to the run command if compilation fails, so read the console output; for a sturdier workflow, add error handling or use a batch file that stops on a failed compile.

For a simple Windows batch-file alternative, save a file such as run-java.bat with this content:

@echo off
cd /d "%~dp1"
javac "%~nx1"
if errorlevel 1 exit /b %errorlevel%
java -cp "%~dp1" "%~n1"
pause

Pass the current Java file to the batch file from a Notepad++ Run command. This example is also limited to an unpackaged single-class program; packages, dependencies, and separate output folders require adjusted commands.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Packaged classes and output folders

The short NppExec script is not suitable unchanged for a class with a package declaration. For example, suppose the source begins with package com.example; and is stored at srccomexampleHelloWorld.java. From the project root, compile it into an output folder:

javac -d out srccomexampleHelloWorld.java

Then run it with the output folder on the class path and its fully qualified name:

java -cp out com.example.HelloWorld

The -d out option tells javac where to place generated class files, including the package directory structure. The class path tells java where to find them. The javac reference documents output-directory and class-path options.

More than one source file

For a small project, compile several source files together. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
javac -d out srccomexample*.java

For a long source list, put file paths in an argument file such as sources.txt:

src/com/example/Main.java
src/com/example/Helper.java

Then compile with:

javac -d out @sources.txt

Projects with dependencies, tests, generated files, or more elaborate layouts are easier to maintain with a build tool such as Maven or Gradle, or a Java IDE. Notepad++ can still edit the source, but managing the build by hand becomes increasingly error-prone.

Optional: run a single source file directly

Modern Java launchers support source-file mode:

java HelloWorld.java

This is convenient for a small single-file program and does not require a separate javac command. It is not the usual compile-then-run workflow that leaves a conventional class file beside the source. Use javac HelloWorld.java followed by java HelloWorld when you want that explicit workflow. See the Java launcher reference for source-file mode details.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

“javac is not recognized”

Windows cannot find the compiler. Check the JDK installation and run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
where javac
javac -version

If needed, add the JDK’s bin folder to PATH, then open a new Command Prompt and restart Notepad++. As a temporary alternative, call the executable by its full path, quoting it and the source path:

"C:PathTojdkbinjavac.exe" "$(FULL_CURRENT_PATH)"

“java is not recognized”

The Java launcher is not available through PATH. Verify the JDK installation and its bin directory, then reopen the shell and Notepad++ after making changes.

“class HelloWorld is public, should be declared in a file named HelloWorld.java”

The public class name and filename differ. Rename the file to match the class, or change the class declaration so the names match exactly.

“Could not find or load main class”

Check that you compiled successfully, are running from the directory containing the class (or have the correct class path), and typed the class name without .class. Confirm that the class has a valid entry point:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
public static void main(String[] args)

If the source declares a package, run it with its fully qualified name from the correct class path, as in java -cp out com.example.HelloWorld.

The expected .class file is missing or an old one still runs

Read the compiler output first: a failed compile does not produce a usable new class file. A stale class from an earlier successful compile can mislead you while troubleshooting. Delete old .class files or compile into a clean output folder such as out, then run the class from that folder.

It works in Command Prompt but not from Notepad++

Notepad++ may have started before the JDK was added to PATH; restart it. Also check that the command quotes paths with spaces, saves the current file first, and changes to the source folder before compiling or running.

When Notepad++ is enough—and when it is not

Notepad++ works well for learning Java syntax and compiling short examples. Its built-in Run command is best for one external command; NppExec or a batch file can automate a simple compile-and-run cycle. For debugging, code completion, refactoring, dependency management, tests, or repeatable project builds, consider an IDE such as IntelliJ IDEA, Eclipse, NetBeans, or Visual Studio Code with Java extensions, or use Maven or Gradle for builds.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For official command details, consult Oracle’s Java compile-and-run guide and the Notepad++ community FAQ on running external tools.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.