Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

Generating Code Snippets without Leaving the Keyboard

The Source Editor has several features for reducing the keystrokes needed for typing code. And you can access many of these features without using the mouse, having to use menus, or remembering scores of keyboard shortcuts.

Arguably the most important mechanisms for generating code are the following:

  • Ctrl-spacebar keyboard shortcut. This shortcut opens the code completion box, as shown in Figure 5-1. The code completion box contains a context-sensitive list of ways you can complete the statement you are currently typing and of other code snippets you might want to insert in your code.
    keegan_fig05_01.jpg

    Figure 5-1 Code completion box

  • Multi-keystroke abbreviations for longer snippets of code called code templates. These abbreviations are expanded into the full code snippet after you press the spacebar.
  • Alt-Enter keyboard shortcut. You can use this shortcut to display suggestions the IDE has regarding missing code and then have the IDE insert that code. The IDE notifies you that it has a suggestion by displaying a lightbulb ( keegan_05_01.jpg ) icon in the left margin of the line you are typing.

In addition to saving keystrokes and use of the mouse, these features might prevent typos and also help you find the right class and method names.

The following several sections illustrate how to get the most out of these features. These topics concentrate on features for Java files, but many of the features (such as code completion and word matching) are also available for other types of files, such as JSP and HTML files.

  • + Share This
  • 🔖 Save To Your Account