TABLE OF CONTENTS (HIDE)

Source-Code Editors and Integrated Development Environments (IDE)

Introduction

To learn a new programming language, you could begin with a graphical Source-Code Editor, with provides syntax highlighting. But you must switch over to an Integrated Development Environment (IDE), which provides a graphic debugger, when you are working on complex programs and projects to improve your productivity.

A Source-Code Editor (or Programming Text Editor) is programming language sensitive and context-aware. It highlights the syntax elements of your programs; and provides many features that aid in your program development (such as auto-complete, compile/build/run, help menu, etc.). On the other hand, a plain text editor, such as Windows' NotePad and macOS's TextEdit, is not language-sensitive and, therefore, is NOT suitable for writing programs.

You also need to use a Text-based editor, such as nano and vim, when your system does not have a graphical user interface, such as the Ubuntu Server.

There are tons of "free" program editors available. Google "best source code editor" to find out the latest. Here are some program editors that I am currently using. Unfortunately, there isn't one magic wane (or silver bullet) that suits all my programming needs.

It is important to use a mono-space font (such as "Courier New", "Consolas") for programming, so that the columns are properly aligned.

Graphical Source-Code Editors

Windows' Notepad and macOS' TextEdit are NOT source-code editors. DO NOT use them for programming!!!

Sublime Text (Windows, macOS, Linux) (@ https://www.sublimetext.com/)

Sublime Text is "a sophisticated text editor for code, markup and prose".

Tips & Tricks
  1. Zoom In/Out: Press Ctrl++ and Ctrl+- to zoom in or out (increase/decrease font size) (Similar to web browser, but Ctrl-0 for reset doesn't work).
  2. Column (Block) Select: Hold Shift+Right-Mouse Drag Select (Windows)
Sublime Text for Java Programming

To compile and run Java Program from Sublime Text:

  1. First, choose the "Build System": Goto "Tools" ⇒ "Build System" ⇒ Choose "JavaC" or "Automatic". You only need to do this once.
  2. To compile and run a Java program: Goto "Tools" ⇒ "Build"; or press Ctrl-B.

My Notes: For Windows, the above build system is configured in "%APPDATA%\Sublime Text 3\Packages\Java\JavaC.sublime-build", as follows:

{
  "shell_cmd": "start cmd /k \"javac $file_name && java $file_base_name\"",
  "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
  "selector": "source.java",
  "shell": true
}
  • The above build file issues start cmd /k "<command>" to start a new CMD shell (with /k option to Keep the window opens after executing the <command>; contrast to /c option to close the window; <command> must be double-quoted).
  • This <command> first invokes Java compiler "javac $file_name", followed by Java runtime "java $file_base_name" if javac has no errors.
  • [TODO] Need to figure out the build-file path for Unix/macOS, and also the command to start a new bash shell.

Atom (Windows, macOS, Linux) (@ https://atom.io/)

Atom is "a hackable text editor for the 21st Century".

[TODO]

TextPad (Windows) (@ https://www.textpad.com/)

TextPad is a light-weight source-code editor, especially good for writing toy Java programs. It is simple to use, fast to launch, and it can be configured to run JDK commands directly. TextPad is a shareware (not a freeware). It has no time limit but a message will keep reminding you to purchase the shareware.

You can download the installer from https://www.textpad.com/. To install, simply run the downloaded installer.

Using TextPad for Writing Toy Java Programs

TextPad is great in writing toy Java programs, as it can be configured to run JDK command directly, bypassing the CMD.

From the TextPad editor, you can invoke the JDK compiler and runtime directly via "Tools" ⇒ "External Tools" ⇒ "Compile Java" or "Run Java Application". Take note of the keyboard shortcuts - Ctrl+1 for "Compile" and Ctrl+2 for "Run".

TextpadJava.png

If you cannot find these commands in the "Tools" menu, goto "Configure" ⇒ Preferences... ⇒ Tools ⇒ Add ⇒ JDK Commands. You can also configure the attributes of "compile" and "run" there, such as prompting for command-line arguments.

Tips & Tricks
  1. Error Message Hyperlink: Double-click on the first-line of an error message will hyperlink to the corresponding source statement.
  2. Find & Replace: Most important commands for programmers (after the copy/paste), available under the "Search" menu.
  3. Block Select Mode: The Block Select mode allows you to operate on a block of texts, such as deleting a few columns and filling in blank columns. To enable/disable Block Select mode, select "Configure" menu ⇒ check/uncheck "Block Select Mode".
  4. Line Numbers: To display the line numbers, choose "View" menu ⇒ check the "Line Number" option.
  5. Command-Line Arguments: To provide command-line arguments to your Java program in TextPad, choose "Configure" menu ⇒ "Tools" ⇒ "Run Java Application" ⇒ check "Prompt for parameters" box. When running your program, place your command-line arguments after $BaseName (which denotes the Java program name).
Configuring TextPad

TextPad is highly configurable to suit your personal programming style (such as your preferred font, color, layout, tab spaces, etc). Select "Configure" menu ⇒ Preferences.

  1. Font: "Configure" ⇒ "Preferences" ⇒ Expand "Document classes" node ⇒ Select your desired class, e.g., "Java", and expand the node ⇒ "Font" ⇒ Select monospace font for programming, e.g., Courier New, Courier, Consolas, Lucida Console.
  2. Add File Association (e.g., *.xml to use HTML Syntax Highlighting): "Configure" ⇒ "Preferences" ⇒ Expand "Document classes" node ⇒ Click on your desired class, e.g., "HTML" ⇒ In "Files in class xxx", add your file extension, e.g., *.xml, *.jsp.
TextPad/JDK Common Errors
ERROR MESSAGE: error: illegal character: \29 or '\u001d'
SOLUTION: 
  You has non-printable character, namely, ASCII "29" (decimal) or "1d" (hex) in your source code.
  You probably copy and paste the source code from somewhere.
  From the error message, identify the line number that triggers this error.
  Remove this character if you can figure out its location (not easy as it is non-printable and invisible).
  Otherwise, remove the whole line and re-enter the line.

NotePad++ (Windows) (@ https://notepad-plus-plus.org/downloads/)

NotePad++ is an open-source and free program editor that supports syntax highlighting for many languages. It is meant as a "Notepad Replacement".

Plug-ins

Notepad++ is highly expandable via third-party plug-ins. Google "notepad++ plug-in" to search for plug-in. To install a plug-in, download, unzip, and move the "dll" file into notepad++'s "plugins" directory.

These are the useful plug-ins:

  1. Hex Editor Plug-in: The hex editor plug-in allows you to view/edit binary files in hex codes. Google "notepad++ plugin hex editor", or from http://sourceforge.net/projects/npp-plugins/files ⇒ from the file list, select "Hex Editor" ⇒ download ⇒ unzip ⇒ move the dll file into notepad++'s "plugins" directory. The Hex Editor will be available from the "Plugins" menu ⇒ "Hex Editor", or the "H" icon on the menu bar.
Tips & Tricks
  1. Reformatting Source Code: TextFX ⇒ TextFXEdit ⇒ Re-indent C++ Code (which also work for java codes).
  2. Column (Block) Select: Hold Alt + Left-Mouse Drag Select (similar to WinWord).
  3. Converting Source Code to HTML: TextFX ⇒ TextFXConvert ⇒ Encode HTML (&<>").
  4. Converting End-of-line (EOL) between Windows, Mac and Unix: Edit ⇒ EOL Conversion ⇒ Choose Windows, Unix or Mac format.
  5. Tile 2 Windows: Right-click on a window ⇒ Move to other view.
NotePad++ for Java Programming

To compile and run Java programs with a single hot-key, I wrote two batch files called "NppJavaCompile.bat" and "NppJavaRun.bat" and save them in the NotePad++ installed directory (or a directory in the PATH).

NppJavaCompile.bat
@REM To run with: NppJavaCompile $(CURRENT_DIRECTORY) $(FILE_NAME)
@cd /d %1
@echo Check if you have save your source file?
javac %2
@pause
NppJavaRun.bat
@REM To run with: NppJavaRun $(CURRENT_DIRECTORY) $(NAME_PART)
@cd /d %1
java %2
@pause

To install the batch files, select the "Run" menu ⇒ "Run...", enter "NppJavaCompile $(CURRENT_DIRECTORY) $(FILE_NAME)" ⇒ Choose "Ctrl-1" as the hot-key for compiling Java program.

Similarly, select the "Run" menu ⇒ "Run...", enter "NppJavaRun $(CURRENT_DIRECTORY) $(NAME_PART)" ⇒ Choose "Ctrl-2" as the hot-key for running Java program.

(To use Ctrl-1, Ctrl-2, you need to re-configure and remove the existing mappings for these keys via "Settings" ⇒ "Shortcut Mapper...".)

These are the notepad++ internal variables:

  • $(FULL_CURRENT_PATH): the fully qualified path and name to the current document.
  • $(CURRENT_DIRECTORY): The directory the current document resides in.
  • $(FILE_NAME): The filename of the document, without the directory.
  • $(NAME_PART): The filename without the extension.
  • $(EXT_PART): The extension of the current document.

To modify the commands, you need to edit "shortcuts.xml" (search under your user's AppDate directory).

Using NppExec Plugin

The above Compile-Java batch file, unfortunately, does not automatically save the current file before running the compilation. To automatically save the file, I have to use the "NppExec" Plugin, as follows:

  1. Goto "Plugins" menu ⇒ Select "NppExec". (If you cannot find "NppExec" under plugins, you need to first install the "NppExec" plugin.)
  2. Choose "Execute..." and enter the following commands:
    NPP_SAVE
    cd $(CURRENT_DIRECTORY)
    javac $(FILE_NAME)
    Save it as script name "JavaCompile".
  3. Press "OK" to run the script. You shall see the output on the NppExec's console.
  4. To install a hot-key for this NppExec script:
    1. From "Plugins" menu ⇒ Select "NppExec" ⇒ "Advanced Options...".
    2. In "Menu Item" ⇒ "Associated script" ⇒ Select the script "JavaCompile" ⇒ "Add/Modify". You shall see the item appears in the "Menu Items". If you open the NppExec menu, you will see "Java-Compile" as a menu item.
    3. To install a hot-key (such as Ctrl-1 - make sure it is not used) ⇒ Goto "Settings" ⇒ "Shortcut Mapper" ⇒ "Plugin Commands" ⇒ Select "JavaCompile" ⇒ Modify ⇒ Assign your chosen hot-key.

The above "NppJavaRun" batch file is fine, as there is no need to save the current file.

NotePad++ for C++ Programming

Similarly, these scripts are used for compiling toy C++ programs using g++.

NppGccCompile.bat
@REM NppGppCompile $(CURRENT_DIRECTORY) $(NAME_PART) $(EXT_PART)
@REM Need to save the source file before running this script?!!
@ECHO OFF
cd /D %1
IF /I %3 EQU cpp GOTO CPP
IF /I %3 EQU c GOTO C

:CPP
g++ -Wall -g %2.cpp -o %2
ECHO g++ -Wall -g %2.cpp -o %2
GOTO END

:C
gcc -Wall -g %2.c -o %2
ECHO gcc -Wall -g %2.c -o %2
GOTO END

:END
pause
NppGccRun.bat
@REM NppGccRun $(CURRENT_DIRECTORY) $(NAME_PART)
@cd %1
%2
@pause

Code Writer (Windows) (@ Microsoft Store)

Pre-installed in Windows 10, Code Writer is a free text and code editor app with over 20 supported file types, and active syntax highlighting that updates as you edit documents. Use it as a replacement for Notepad and other quick edit apps.

gEdit (Linux, macOS)

gEdit is the default graphic editor for Linux.

[TODO] more

Others

PSPad (@ http://www.pspad.com/)

PSPad is an excellent program editor, especially for web programming such as writing JavaScript. It is a freeware. To install, simply run the downloaded installer. The "Help" menu provides many good links to various online programming guides and references.

Light Table (@ http://lighttable.com/)

Light table is "the next generation code editor".

jEdit

[TODO]

Text-based Source-Code Editors

Some systems, such as Ubuntu Server, do not support graphical user interface. Hence, it is important to be able to use a text-based editor, such as nano and vim, to do minor editing (such as changing the configurations).

nano (macOS, Unix, cygwin)

nano is small, simple and easy-to-use text editor. nano is available for macOS and Unix Systems, and is really handy to create/edit small configuration files.

To start nano, open a Terminal and issue:

$ nano                // Create a new file
$ nano <filename>     // Edit an existing file

To exist nano, press Ctrl+X, followed by "y" (yes) to save the file.

You can run nano with sudo (as administrator) for editing restricted system files, as follows:

$ sudo nano <filename>  // Run nano with superuser to edit an existing system file

vi and vim (Unix, macOS, cygwin)

[TODO]

Hex Editors

At times, you may need to display the hex values of a file. A Hex Editor is a handy tool that a good programmer should have in his/her toolbox. There are many freeware/shareware Hex Editor available. Try google "Hex Editor".

For windows, I recommend "Notepad++ with the Hex Editor plugin". Read "NotePad++". "TextPad" can be used to view the Hex code by opening the file in "Binary" mode.

For macOS/Linux: [TODO]

Integrated Development Environments (IDE)

In addition to syntax highlighting (in a source-code editor), an IDE provides:

  1. graphic debugger, supporting breakpoint, step-over, step-in and step-out.
  2. build system, such as ...
  3. profiling for performance tuning.
  4. many more.

Eclipse

Read "Eclipse for Java" or "Eclipse for C/C++".

NetBeans

Read "NetBeans for Java".

Visual Studio Code (VS Code) (@ https://code.visualstudio.com/)

See "VS Code" article.

Pycharm for Python

[TODO]

CodeBlock for C/C++

Read "CodeBlock for C/C++".

Microsoft Visual Studio for C++

Read "Visual Studio for C++" (obsoleted!).

 

REFERENCES & RESOURCES