NetBeans IDE: Features, tips & future
NetBeans has had a long and storied history. In this article, Geertjan Wielenga goes over some of that history to explain NetBeans’ unique features, as well as some tips and tricks to make your app development even easier.
NetBeans IDE, the original Java development environment, started as a student project in 1996 in Prague, in the Czech Republic. After James Gosling, the founder of Java, was introduced to NetBeans, Sun Microsystems acquired and open sourced it in 2000. Ten years later, with Oracle’s acquisition of Sun Microsystems, NetBeans became part of Oracle.
In 2016, the process of transitioning NetBeans to Apache began with currently over 4.5 million lines of code having been contributed to Apache with several million more lines in process. In the end, NetBeans will not only be an open source project: it will also be open governance, managed via the processes and guidelines established by the Apache Software Foundation.
Although NetBeans has been open source since its time in Sun Microsystems, its moved to a neutral place like the Apache Software Foundation with its strong governance model is aimed at helping it get more contributions from various organizations. For example, large companies have been using the infrastructure of NetBeans as an application framework to build internal or commercial applications. These kinds of organizations are much more likely to contribute to it within the neutral ground provided by the Apache Software Foundation. At the same time, though Oracle will relinquish its control over NetBeans, individual contributors from Oracle are continuing to contribute to NetBeans after its transition to Apache along with contributors from all other kinds of organizations.
Some unique aspects of NetBeans can already be seen from its origins as a student project; its status as the original development environment for Java, and its transition from Sun Microsystems to Oracle to the Apache Software Foundation.
But what makes NetBeans unique? Firstly, it’s support for Apache Maven. In fact, a key term that comes up repeatedly in the context of NetBeans is “Maven”. NetBeans users appreciate that they do not need to install any plugins to use Maven or import any projects but simply open them. Just go to File | Open Project and NetBeans will recognize any folder containing a POM file as a Maven project and then use the POM file as the NetBeans project definition. Following this, a key feature of NetBeans is the short time difference between installing it and beginning to create meaningful applications in it.
Despite its significant plugin ecosystem, not much is needed to be installed or configured. Everything is available “out of the box” as soon as you start it up. Another unique out of the box feature is that NetBeans automatically lets you work easily and intuitively with a wide range of popular versioning systems without plugins, including Git, Mercurial, and Subversion. Plus, users can create, test, debug, deploy, and profile applications that will run on the Raspberry Pi, mobile phones, PDAs, set-top boxes, and other mobile and embedded systems.
Also, the core of NetBeans is the language-aware NetBeans editor. This provides the standard robust features of editors aimed at fast and effective coding, detecting errors while you type and assisting you with documentation popups and smart code completion – all with the speed and simplicity of your favorite lightweight text editor. Of course, the Java editor in NetBeans is much more than a text editor; it indents lines, matches words and brackets, and highlights source code syntactically and semantically.
NetBeans tools for the Java EE platform are developed in close cooperation with the Java EE, GlassFish, and WebLogic teams to provide the tightest integration and easiest possible use of the Java EE specification. Consequently, using NetBeans IDE is the best way to quickly learn and become productive in Java EE programming if you are new to the Java EE specification and framework or if you’re experienced in need to be productive and focused on your domain logic.
The integration with Apache Cordova enables deployment of native packages to iOS and Android. HTML5 applications can be deployed to the Chrome browser on iOS and Android. Applications can even be debugged and profiled live on the device. The NetBeans Profile is a frequently hidden feature that it built in and freely available. It provides expert assistance for optimizing your application’s speed and memory usage while making it easier to build reliable and scalable Java SE, JavaFX and Java EE applications.
Finally, users appreciate the configurability of NetBeans. The Options window is extensive, unifying all the ways in which NetBeans can be configured in a single place. Also, you can easily drag and reposition tabs in the application frame to suit your individual workflow, while also undocking tabs and dragging them outside the application frame, even onto a different monitor and changing keyboard shortcuts to match your specific preferences.
Tips & tricks
Move/copy up/down. Press Ctrl-Shift-Up and the current selection is copied to the lines right above the current selection. Press Alt instead of Ctrl and it is moved instead of copied. Press Down instead of Up and the lines of code will be copied below the current selection.
Capture inner/outer syntactic element. Each time you press Alt-Shift-Period, the selection expands to a successively wider syntactic element. For example, below one statement was selected, the key combination Alt-Shift-Period was pressed, and then the complete content of the surrounding block statement was shown to be selected. The selection expands from the current statement to surrounding block statements to the surrounding method and from there to the surrounding class and further. To successively narrow the selection, press Alt-Shift-Comma instead of Alt-Shift-Period.
Generate code skeletons. Whenever you want to generate commonly needed pieces of code, such as constructors, getters, and setters, simply click Alt-Insert and a small popup appears with a list of items from which you can select.
Inplace rename. If you want to change a variable, method, or another item of which more than one is used in your code, press Ctrl-R and you will see that all instances of the item turn blue at the same time as shown below. Now, when you change the selected item, all the other instances change at the same time until you press Escape, at which point the inplace rename mode comes to an end.
Add/Remove comment lines. Select one or more lines, press Ctrl-/, and then the selected lines are commented out as shown below. Press the same keys again and the commented lines will no longer be commented. This was also possible in previous releases, but previously there were two different keyboard shortcuts, one for commenting and one for uncommenting. Now, they have been combined into one shortcut so you can quickly toggle between comment and uncomment, making this activity much faster and more efficient.
Inspect members/hierarchy. Both the members of the current class, as well as its hierarchy, can be displayed and then filtered. Press Alt-F12 and the ancestors of the current file are shown. On the other hand, if you press Ctrl-F12, the current file’s members are displayed.
Switch between documents. When you have multiple documents open at the same time, press Ctrl and Tab and then a small popup appears. You can scroll through the popup, which displays all the open documents and then choose the document that you want to open.
Jump to last edit. Often, you find yourself in a situation where you have edited in one document while you currently find yourself in a completely different document. How do you get back to the place where you were last editing your code? That is likely to be the place where you want to get back to in order to do some more editing. Now, whenever you click Ctrl-Q, the last edited document is found and the cursor lands on the line where the last edit took place. Alternatively, you can click the button shown below in the top left corner of the Source Editor.
When you press Ctrl-Shift-M, the current line is “bookmarked”. What this means is that you can later quickly cycle back/forward to it (with Ctrl-Shift-Period and Ctrl-Shift-Comma). The bookmarked line gets a small icon in the left sidebar as shown below until you press Ctrl-Shift-M on the line again, to remove the bookmark.
Highlight exit points. Place the cursor on the return type and you will immediately see all exit points highlighted.