Using Notepad++ to Compile and Run Java Programs
I had been using Notepad- The one that comes with Windows for a long time for writing Java programs and
then running it through command line, though i had Notepad++ installed on my system. But then it just flashed to me that “Why can’t i try Notepad++ for compiling and interpreting the Java programs“. I searched in the FAQs under “Running External Tools” and found useful information which has helped me to compile and run the Java programs right from the “Notepad++” application itself. Here’s how it can be done:
Running External Tools in Notepad++:
External tools can be executed by passing the current edited document as argument. For doing this the “environment variable” is used
The usage of Environment Variable:
$(ENVIRONMENT_VARIABLE)
Ex: Lets say we are editing “NotHelloWorld.java”
The 5 environment Variable that can be used are:
FULL_CURRENT_PATH: C:\Documents and Settings\Administrator\My Documents\JavaP\NotHelloWorld.java
CURRENT_DIRECTORY: C:\Documents and Settings\Administrator\My Documents\JavaP\
FILE_NAME: NotHelloWorld.java
NAME_PART:NotHelloWorld
EXT_PART:java
Note: The environment variables must be enclosed with in double quotes.
“$(ENVIRONMENT_VARIABLE)”
For Java Compiler its: javac “$(FILE_NAME)”
For Running the Program i.e interpreting the byte code its: java “$(NAME_PART)”
The screenshots can guide u much better:
Above: Program Snapshot
Above: Using the “Run” Menu
Above: Typing in the “javac” command for Compiling
Above: Typing in the “java” command for interpreting the Byte Code
Above: The Output Obtained
One can click on “Save” to Save the commands, and the next time the same can be accessed through the “Run” menu.
Suggested Tidbit on Using Notepad++ by LightGeoDuck (One of the readers)
1. (after code is saved) press f6
2. type:
cd “$(CURRENT_DIRECTORY)”
javac $(FILE_NAME)
java $(NAME_PART)
pressing enter after each command
3. save for future use
4. press ok
If you are able to compile thru the PC cmd prompt this will do the same but with in the Notepad++ environment.






Hey mohammed, nice post I must say. The purpose of notepad when developed was just to provide a facility to scribble down and save it… a text tool. And that is what is provides very efficiently even today. It consumes very low memory and uses least system resources. When you want to run java rpograms now thats not a responsibility of a text tool… so you can switch over to more powerful tool and thats where IDE come into picture..
Anyways, it was a great post..also EditPlus is very easy use..i normally use it..compilation and running are just one mouse button click away.
Keep the good work going.
Regards,
[b]PassingSCJP[/b]
Passing SCJP
August 10, 2008
where do you get notepad ++??it is not there as default in windows xp.
ashwin
August 14, 2008
@Ashwin
yeah it doesn;t come bundled with Windows. Google for “Notepad++”. The first link will take u to their site
Mohd Sanaulla
August 15, 2008
Some changes have to be made if in case the code involves packages and command line arguments.
Mohamed Sanaulla
September 8, 2008
i have problem with notepad++….
it cannot compile my project, what should i do?
which version of java is used for notepad++?
i use JavaJDK 6u2, i install it at C:\Program files\Java
help me plz
John
September 24, 2008
@John
What is the error u r getting?
When using Notepad++ the Output window which u get after compiling does not stay so one cannot come to know the compilation errors.
Any Java version is supported. Notepad++ is just an alternative to the Command line compilation. If u r facing problems using Notepad++ u can use command line compilation instead.
Mohamed Sanaulla
September 27, 2008
I am new to Java myself, but here is a hopefully helpful tidbit. Since I am learning Java I want to try to avoid using an IDE, I use Notepad++ but I came to realize that it is sometimes a pain using the cmd prompt all of the time so I figured out this tip using NOTEPad++ for java.
1. (after code is saved) press f6
2. type: cd “$(CURRENT_DIRECTORY)”
javac $(FILE_NAME)
java $(NAME_PART)
pressing enter after each command
3. save for future use
4. press ok
IF you are able to compile thru the PC cmd prompt this will do the same but with in the NPpp environment.
LightGeoDuck
October 13, 2008
@LightGeoDuck
Thanks for the Tidbit. I have explained the same in the post. You are absolutely right it makes the work lot easier.
Mohamed Sanaulla
October 15, 2008
MS,
Thanks for posting my comment, but maybe I didn’t explain it correctly. My comment is different from your post I believe. Where you used the Run command F5 where it would open the computers command prompt. I was refering to F6 where it puts the output inside the Npp editor. I attempted the F5 method and it didn’t work.for me that is
LightGeoDuck
October 16, 2008
LightGeoDuck,
Initially thought it was the same thing. But after u’r recent comment i tried it out and found it to be lot different from what i have posted. Sorry for not interpreting u’r suggestion correctly.
Thanks a lot for the suggestion. Will update my post to add u’r suggestion.
Do suggest some areas where i can blog about.
Mohamed Sanaulla
October 16, 2008
can i add a shortcut key to nPPexecute so tht
everytime i press it…my file gets compiled
automatically and i also get to c results of
compilation in command prompt window
Kshitij
October 22, 2008
Hi
I am using Notepad and would like to compile C, C++ program
How may I do so ?
What C compiler is preferred ?
Thanks dude
Muhammad Ali A
November 3, 2008
@Muhammad Ali A
Try using Cygwin. U can know more details about Cygwin -http://www.cygwin.com/
Once u have configured the bin directory path i.e added the bin directory of Cygwin to the existing path variable u can use it for compiling your C/C++ programs using gccg++ compiler on windows.
Mohamed Sanaulla
November 9, 2008
Just to clear up any confusion, if any readers find that pressing F6 does nothing, then you may not have the nppExec plugin installed. You need to install this before you can use the suggestion posted in the article.
you can download the plugin from the plugin page on the Notepad++ site using this link: http://notepad-plus.sourceforge.net/uk/download.php
I had to use the beta version to allow it to work with notepad++ version 5.1.1 hopefully using the beta version will be stable
Russell
December 11, 2008
better option for me in one line using %JAVA_HOME%
cmd /c “cd “$(CURRENT_DIRECTORY)” & %JAVA_HOME%\jdk1.6\bin\javac.exe $(FILE_NAME) ”
Thanks mate for the nice post.
psidarad
January 31, 2009
To Compile Java Code on the current document you have open while in Notepad++:
javac “$(FULL_CURRENT_PATH)”
To run the current java program you have open:
java -classpath “$(CURRENT_DIRECTORY)” “$(NAME_PART)”
Add some shortcut keys and it works like a charm.
CoolPolarBear
February 5, 2009
CoolPolarBear,psidarad, Russell
Thanks for the suggestions. Haven’t been finding time to write more. Meanwhile if u have any suggestions on how i could improve the blog. Suggestions for the articles- U are please welcome.
Mohamed Sanaulla
February 5, 2009
IS THERE ANY WAY I CAN WRITE A BUILD SCRIPT FOR NOTEPAD++ TO COMPILE ALL JAVA CLASSES AT ONCE
FURQAN
February 27, 2009
for me it works if i type
cd “$(LEFT_VIEW_FILE)”
javac $(FILE_NAME)
java $(NAME_PART)
with “$(CURRENT_DIRECTORY)” it assumes notepad++ directory
qwazix
April 28, 2009
Thank for the great post and resource
- this is just what I was looking for (adapted use to perforce checkouts in notepad++)
Rodney Reid
June 8, 2009