Вы находитесь на странице: 1из 8

Notepad++ as a Java IDE | Scripsi: My Writings http://www.quarkphysics.

ca/scripsi/java_notepad/#part1

Scripsi: My Writings
by Michael Harwood

Notepad++ as a Java IDE

Notepad++ is one of the best editors, simple yet powerful.


It can easily be used to compile and run Java programs.
You can put Notepad++ and Java on a USB drive and program in Java everywhere!
Thus it is a simpler, more streamlined alternative to Eclipse.
[If you cant get this to work, use Eclipse but it wont run off a USB drive.]
Unfortunately, unlike Java, it only runs on Windows.

In this article Ill explain how to setup Notepad++ and Java so that you can use Notepad++ to compile and
run Java programs.
These instructions are to set things up so that everything run on a USB flash drive.
If you want to install the programs onto your hard drive (i) you can download Notepad++ instead of
Notepad++ Portable, and (ii) you need to find and use the correct path to javac.exe (and java.exe) instead of
\java\jdk1.7.0_11\bin\javac. It will probably be something like C:\program files\java\ .
Also, as new versions of Java come out youll have to modify the path to the correct version number.

There are 4 parts to this:

1. installing Java JDK


2. installing Notepad++ portable
3. adding scripts to Notepad++
4. testing everything by compiling and running a Java program

Part 1: install Java 7 JDK

(JDK means Java Development Kit which is what you need in order to compile Java programs.)

1. Go to: http://www.oracle.com/technetwork/java/javase/downloads/index.htmlClick on the appropriate


button (as seen below) to do to the download page

.
2. On the next screen (see below) select
Windows x86 for 32 bit windows(e.g. jdk-7u11-windows-i586.exe) or
Windows x64 or for 64 bit windows( e.g. jdk-7u11-windows-x64.exe)

1 of 8 5/1/2017 6:25 PM
Notepad++ as a Java IDE | Scripsi: My Writings http://www.quarkphysics.ca/scripsi/java_notepad/#part1

3. Next, install the JDK file you downloaded (jdk-7u11-windows-i586.exe) by clicking on it and choosing the
default options..
4. Now copy the folder C:\Program Files\Java to your USB flash drive (e.g. to M:\Java)

2 of 8 5/1/2017 6:25 PM
Notepad++ as a Java IDE | Scripsi: My Writings http://www.quarkphysics.ca/scripsi/java_notepad/#part1

Part 2: download, install, configure Notepad++

1. Go to: http://portableapps.com/apps/development/notepadpp_portable

3 of 8 5/1/2017 6:25 PM
Notepad++ as a Java IDE | Scripsi: My Writings http://www.quarkphysics.ca/scripsi/java_notepad/#part1

.
2. Download Notepad++ and Install it to your USB drive.
3. Now run Notepad++, and go to the menu option Plugins/Plugin Manager/Show Plugin Manager and
install these plugins.
i. Compare is very useful for comparing versions of documents or source code
ii. NppExec is essential for compiling Java code
iii. TextFx Characters has the ability to automatically indent your code
iv. Hex-Editor is optional. You have to click on Settings and then Show Unstable Plugins to be able to
install it.

4. Notepad++ Portable is now correctly installed on your USB flash drive (presumably, thats where you installed
it). You should also probably make a folder for where youll be storing your programs (I called it JavaProgs).

Part 3: adding scripts to Notepad++

Unfortunately, Im getting tired of making all of these screen shots. Most of this section is written instructions.

1. Enter new commands that show up in the Macros menu by doing the following:

4 of 8 5/1/2017 6:25 PM
Notepad++ as a Java IDE | Scripsi: My Writings http://www.quarkphysics.ca/scripsi/java_notepad/#part1

A. Plugins/NppExec/Execute (or Press F6)


B. Youll see a box that says Temporary Script
Paste in this code:

C. Click Save
D. Then type in Java-Compile (this is the name of your script) and click Save
E. You then get back to the previous screen and have the choice of clicking OK or CANCEL. Click Cancel
which exits NppExec without running the script (OK would run it)
F. Java-compile is used to compile your programs. (If you have a different path, you will have to modify the
scripts.)
2. Go back to Plugins/NppExec/Execute (or Press F6) and repeat these steps to enter the following scripts
A. Note: first select Temporary Script to clear the box so that you can paste in the next script
B. Java-run is the name of this second script. It will run the Java program after it has been compiled.

C. Java-applet-HTML is the name of this script. It is used to make a very simple HTML file for running
Java applets. [Dont bother with C and D unless you plan to use applets.]

Note: I cant find any way of not displaying &gt; and &lt; If I use the > and < symbols, then the code is
treated as HTML instead of plain text. I also cant use &#60; WordPress is just screwed up.
D. Java-applet-run is the name of the fourth script. It is used to run an applet after it has been compiled
and the HTML file created.

3. Now we add the scripts to the Macros menu.


A. go to the submenu Plugins/NPPexec/Advanced Options
B. select script from Associated Script combo box. It will automatically fill in the Item Name
C. now click the Add/Modify button
D. Check the box at the top that says Place to the Macros Submenu
E. Click OK. This will exit the Advanced Options box and say that NotePad++ needs to be restarted (dont
restart it until all 4 scripts have been added).
We have to click OK because its the easiest way of clearing the boxes to add the next script otherwise its
likely to overwrite the existing menu option.
F. Repeat these steps to add the other 4 scripts.
G. Close Notepad++ and restart it.
4. When youre done, click on the Macros Menu and you should see the 4 Java scripts (not Javascript!) that we
added at the bottom. (see below)

5 of 8 5/1/2017 6:25 PM
Notepad++ as a Java IDE | Scripsi: My Writings http://www.quarkphysics.ca/scripsi/java_notepad/#part1

Part 4: testing to make sure that everything works.

1. copy and paste the following code into a Notepad++ window

2. Save this file as Draw4Ovals.java. Upper-case is important. Once it is saved, youll see that Notepad++ does
syntax highlighting.
3. Select the Macros menu, then click on the Java-compile macro near the bottom. The results should look like
this:

6 of 8 5/1/2017 6:25 PM
Notepad++ as a Java IDE | Scripsi: My Writings http://www.quarkphysics.ca/scripsi/java_notepad/#part1

.
4. Now select the macro Java-run. You should see this:

7 of 8 5/1/2017 6:25 PM
Notepad++ as a Java IDE | Scripsi: My Writings http://www.quarkphysics.ca/scripsi/java_notepad/#part1

5. If, in addition, you want to test an applet,


i. paste the following code
ii. save it as TestApplet.java
iii. run Java-compile
iv. run Java-applet-HTML
v. now either view the file in a browser, or else run Java-applet-viewer

6. Note: Applets are no longer used as much as other types of web-programming.


The Java-applet-HTML script just makes a very simple HTML page. If you want to put an applet in a
webpage, you should actually make a decent webpage.

Scripsi: My Writings
Proudly powered by WordPress.

8 of 8 5/1/2017 6:25 PM

Вам также может понравиться