Running a java code from Notepad is always a good practice, especially for beginners. There are several reasons. I hope you all have used modern IDEs like NetBeans and Eclipse. Well, these are no doubt excellent IDEs with lots of features, but if you are a beginner then these are not a good option to do programming. Because all these IDEs have auto-complete feature, you just type few letters and the line is completed automatically, which is absolutely not good for beginners. Always remember our mind remembers those things which we practice a lot. You won’t be able to learn things or remember things if you always select things from the drop down menu in IDEs. If you are a beginner or just started to learn programming and using those modern IDEs, then it is like spoon feeding when you don’t even know how to hold a spoon.
Here’s another reason, modern IDEs use so much RAM. If you have a PC with 1-2 gigs of RAM it will take lots of time to load the IDE. So a light weight notepad is always a good option.
Read this full article and try running Java code from NotePad++ and any other IDE. You will see the difference.
So my suggestion is to use a text editor like NotePad++ rather than using any of those IDEs like NetBeans or Eclipse.
Now that you know why I am suggesting a notepad to do Java programming, it’s time to install the notepad and get started with it.
First of all, you need to install Notepad++ on your computer. You can download the setup file from the official site of Notepad++.
After downloading the setup file simply install it by double clicking.
Now that you have installed notepad++, we have to do few simple things to run java code. Follow the steps below:
1. To run a java code your PC needs to be configured environment variable. If you are not sure about that you can check our article on Java Environment Variable.
2. Now open Notepad++ and go to Plugins – Plugin Manager – Show Plugin Manager.
- 3. From Plugin Manager window we have to install three plugins.i) Compare – This plugin is used to show the difference between two files.
ii) NppExec – This plugin is necessary to execute java code.
iii) HEX-Editor.4. From the Available plugins tab, search for the above three plugins and install.4. After installing all three plugins, again click on Plugin – NppExec – Execute.5. Execute window will open. In the command line type the below code and click Save.
123456//save current fileNPP_SAVEcd $(CURRENT_DIRECTORY)javac $(FILE_NAME)
6. Type the name as you want. Like Java_Compile. Click Save then click Cancel.
7. Again do the same steps as above. Go to Plugins – NppExec – Execute.
Type the below code in the command line and click Save..12345678//save current file//NPP_SAVEcd $(CURRENT_DIRECTORY)javac $(FILE_NAME)java $(NAME_PART)
8. Name it as you want, like Run-Java or Java-Run then click Save and then click on Cancel.
9. We are almost done. Now we have to add those two Options under Macro tab. To do so, Go to Plugins – NppExec – Advanced Options. NppExec Advanced Options window will open.
10. At the bottom of the window select Java-Compile (or whatever you have named the script) from the Associated Script drop-down menu and select Add / Modify.
Tick Place to the Macros submenu under Menu items* and click Ok. The window will be closed.
11. Do the same steps as above to add the Java-run (or whatever you have named the script).
Go to Plugins – NppExec – Advanced Options. Now select your script from the Associated script drop-down menu. Click Add / Modify. Tick Place to the Macros submenu and then click Ok.
That’s all. Restart your NotePad++ and Run your java code.
Now we are going to test a java code to see whether it’s working or not.
Open NotePad++ – type any code and Save it anywhere as .java.
To run the code click Macro – Java-Compile then Macro – Java-run.
After running the program you will see the output at the bottom of the screen.