Notepad++
[Tutorial and Download]
Notepad++ is a basic text editor. We could use the built in Windows Notepad (which has many similar generic features), but Notepad++ has some nice features specifically for Java programmers. You can download it for free from the Notepad++ website.
Notepad++ is nicely set up for basic Java editing, as it gives you line numbers (as does the JVM, when it warns you of code errors), and syntax colouring - that is, it colours different bits of code different colours, so you can see what they mean in the code progression. Later in the units we'll talk about Integrated Development Environments, which are more sophisticated editors, but for the moment we'll get used to using something simple so we always have something to fall back on.
Where is it?
On Windows 7, it should appear on the Start Screen. Alternatively search 'apps' for 'Notepad++'.
On other Windows, click on the Windows button at the bottom of the screen. Then click on 'All programs' and, when the menu pops up, click on 'Notepad++'. When the next menu pops up, Notepad++ should be on it.
Alternatively...
Click on the Windows button at the bottom of the screen (or right-click left end of task-bar in Windows 7 desktop). Click on 'Run...'. Type 'Notepad++' into the long box, and hit 'OK'.
The five important features of Notepad++:
'Cut and paste'
Most Windows programs use the same keys to do common functions, and most use the 'Control' key (labeled 'Ctrl') pushed at the same time as a letter key. The most common are...
- 'Ctrl' + 'A' To select everything.
- 'Ctrl' + 'C' Copy text highlighted by dragging the mouse.
- 'Ctrl' + 'X' Cut out the text highlighted by dragging the mouse and save it.
- 'Ctrl' + 'V' Paste the text cut or copied into the space where the mouse was last clicked.
- 'Ctrl' + 'Z' Undo the last action.
To highlight text, drag the mouse across it while keeping the left button depressed. When you get to the end of the text you want, release the mouse button. The text should stay highlighted until you next click the mouse button. If you cut and copy text it goes into the 'clipboard'. You can usually only have one thing at a time in there, but it can be text, pictures or other objects.
Try copying the paragraph above out of your browser and pasting it into Notepad++.
Find and Replace functions
As with most Windows programs, these are...
- 'Ctrl' + 'F' Find a word.
- 'Ctrl' + 'H' Find a word and replace it with another.
These are useful for finding a particular place in a long program, and replacing a lot of instances of a word all at once.
[Note that the find/replace in Notepad++ is much more sophisticated than most; for example, if you know how to write regular expressions you can do this in these dialogs]
Save as text with a .java extension
If you're writing Java programs, you'll want to save the source files as plain text, rather than something with a lot of colours and font formatting like a Word file (the Java compiler only works with plain text files). Once Notepad++ knows you're dealing with Java it will colour syntax and keywords, but it won't save these colours in the file - it recognises them automatically.
However, you'll need to call the file 'yourname.java' rather than 'yourname.txt' which is more usual for plain text files. The compiler only recognises .java files.
If you've got some text in Notepad++ now you can do this by following these instructions...
- From the menu at the top of Notepad++, choose 'File'.
- Click on 'Save As...' and a box of options will appear.
- In the folders displayed, find a suitable one in your personal space to put a temporary file into.
- In the long box next to 'File name' type 'MyFirstBigNotepadFile.java'.
- Click in the long box next to 'Save as type:' - a drop down list will appear.
- From the list, select either 'All files', 'Normal text file', or 'Java source file'.
- Click 'OK'.
Line numbers
One really useful aspect of Notepad++ is that it shows line numbers. The Java compiler and JVM will display the line numbers of any issues, so it is really useful to be able to see these.
If the line numbers aren't showing down the left-hand side of the editor, you can turn these on by going to the Settings menu, selecting Preferences..., finding the Editing tab, and turning on Display line number.
Formating
Note that for programmers a really helpful feature is that you can select a whole set of lines (click and drag mouse), and then push the Tab key to push all the lines over in one go.
To pull lines the other way, push Tab while holding the Shift key.
When you're ok with this lot, head back using your browser's back button.