Ten Time-Savers in NetBeans

The NetBeans IDE(Integrated Development Environment) has come a very, very long way. Our Java curriculum development group uses this tool everyday in the development of training materials and NetBeans is the default development environment for students. As a result, we have compiled a set of ten time saving features that we thought you ought to know about this powerful tool – features that make the development of Java software easier. So counting down the top ten (and these are no particular order), let’s start by reducing the amount of typing needed for common methods.

Number 10: Use typing shortcuts!

Two of my most used shortcuts are psvm and sout. Huh?

NetBeans has defined a number of code templates (abbreviations) to reduce the amount of typing required for common methods, field declarations and more. The two that I use the most are “psvm” to declare a public static void main (String args[]) { method, and “sout” to declare a System.out.println(“”); method. To use this functionality, simply put the cursor into you Java class and type the characters, psvm, followed by the Tab key:

That’s a lot less typing! My second most used shortcut is sout, to create a standard console printed message:

Notice that NetBeans also places the cursor in exactly the right place – you simply start typing right after the Tab key. A list of shortcuts and a number of other helpful features are listed on the NetBeans ReferenceCard, which is available through the Help menu or online at http://netbeans.org/project_downloads/usersguide/shortcuts-72.pdf. You can view the complete list by opening the Tools->Options menu within NetBeans and viewing the Editor->Code Templates and the Keymap sections. There you can view, customize, and even define your own shortcuts.

Number 9: Comment out a block of code

Sometimes you need to comment out a block of code, either to test to see if something is working (or broken) and sometimes because you changed your thinking on some program logic. I find that deleting code is not a good idea – you might find that what you thought you didn’t need was actually really important! So instead, select the code and comment it out in a one action with Ctrl-Shift-C. And, by the way, it works in reverse too – uncomment that code later with the same key sequence. If you prefer using the mouse, you can also use the buttons  at the top of the editor window to comment and uncomment.

Number 8: Use global replace

Sometimes you create a field or a method name that after careful thought, well, it just isn’t right…. Rather than hunting through a long class and laboriously replacing each occurrence one at a time, NetBeans has a way to replace every instance in your class all at once!

For example, in this code fragment, empArray really doesn’t say what this field will contain – and, it isn’t even an array. So what I really want is to rename every instance of empArray to employeeData, all at once. Simply click in the field, and all of the fields in the class will highlight. Then press Ctrl-R (or right-click and then Refactor -> Rename) to start replacement.

Voila! Note: unfortunately, this doesn’t work if your code has unsresolved elements – so do this after your code compiles correctly.

Number 7: Use auto format

Nobody likes ugly code! In fact, 4 out 5 Java developers will refuse to work on code that is not properly formatted. Ok, I made that up. But imagine that you are trying to debug the code on the left (with apologies to the Java tutorial). To make it easier to read, and determine the actual flow, simply press Alt-Shift-F (or right-click and choose Format) to reformat the code. the result is the image on the right. This feature will also take care of leading and trailing space – it does not remove blank lines between code lines, which is nice if you want to separate methods and fields from each other.

Number 6: Which file am I working on?

As course developers, we often have files with the same name that belong to different projects open in the editor at the same time. One file belongs to practice 1, and the other practice 2. More than once I’ve been editing a file only to discover it was in a different project than the one I had open. There is a great feature in NetBeans to determine which project a file belongs to. In the image below, I have two Employee.java files open. If I click in the file and press ” style=”background-color: #ffff00;” class=”bki-span”>Ctrl-Shift-1 (or right-click on the tab that contains the file name and choose “Select in Projects”), the project that contains that file will open in the Project Tab and highlight the file.

Number 5: Close all open files

At some point, you will have opened 10, 20 or more Java class files, XML files, and other assorted files all at the same time. Sometimes, when there are that many files open, trying to remember what you were working on and what you need to do becomes overwhelming. The answer? Reboot. No, not your machine, reboot your editor pane! Press Ctrl-Shift-F4 and all of the open file will close. If you had any open with unsaved edits, you will get a prompt to save the files. Then you can start your thinking process again with a clean slate.

Number 4: Fix imports automatically

When you are writing code, stopping your train of thought to track down a missing import statement, and resolve compilation errors such as “cannot find symbol” could be a tedious chore if you had to do it yourself. One of my favorite features in NetBeans is Ctrl-Shift-I (Fix Imports). This simple keystroke combination will track down missing import statements and fill them in for you, automatically. And if there are two classes with the same name in different packages and Fix imports can’t figure out which class you want from the other import statements, it will allow you to choose which one you mean to include.

But wait, there’s more! Fix imports will also remove extraneous imports and order them, neat and tidy!

Number 3: Make the javadoc work for you – use autocomplete!

Anyone who has memorized the entire javadoc, all the packages, classes and methods, well, that person has too much time on their hands! When we are coding, we understand what we are trying to do in the code, but not necessarily all of the method names and parameter syntax. Instead, make sure that you have the javadocs you need and use autocompletion to help choose which method you want, which field, which enum, even which tag in JSF and JSP files. Simply type a part of a class, a method name or the . (dot) to evaluate which method the object can call and press Ctrl-Space.

BTW, because NetBeans is always trying to help out, you may have seen this popup and go away without really knowing how to get it back, so know you know – Ctrl-Space. Notice in this simple example, I typed part of the ubiquitous System.out, and then after the dot pressed Ctrl-Space and selected the append method. On top is the javadoc and below is the method signature I could select simply by clicking on it.

Number 2: Auto-generate getters and setters, constructors and more!

The JavaBeans pattern is one of the most used coding patterns. Simply put, a JavaBeans has properties that are accessed or mutated through methods. Most often the properties represent fields in your class. The property methods follow a pattern, with getXXXX and setXXXX, where XXXX is the property (field) name. The simplest way to generate this code is to create your class, add the fields you want, click in the line after the fields and select Alt-Insert to open the Generate dialog and choose Getter and Setter. Then individually choose the fields, or select the class to generate a getter and setter for every field!

Poof! As if by magic I have a set of 5 getters and 5 setters inserted into my Employee class.

Using the same Generate feature above, you can also generate constructors, loggers, override Object equals, hashcode and toString, override methods of the parent class and more.By generating a constructor and then just getter methods, you have a nice immutable class.

Number 1: Compare files to see what’s changed

Probably the best kept secret of NetBeans is the Diff Tool. We use this tool a great deal when creating training, as the labs we write tend to be on a single project that changes from one lab forward to the next. As a result, we often have copies of classes with differences based on the lab. However, for anyone creating copies of files and making changes between copies, this tool is an absolute time saver! Simply select one file, then click Tools -> Diff and choose the second file. they don’t have to be the same name or even be open at the same time.

As shown in the image below, the diff tool has two modes, one to graphically show the differences and a textual differences tool as well. You can swap left and right, export the differences to another file and even set the granularity of the differences with Options. But if you’re like me, just the standard graphical view tells the whole story in glorious color!



How To Edit Your PATH Environment Variables On Mac OS X

If you are new to Mac OS X, you may need to know how to edit your PATH. The good news is that this is an easy task on Mac OS X.

The recommended way is by editing your .bash_profile file. This file is read and the commands in it executed by Bash every time you log in to the system. The best part is that this file is specific to your user so you won’t affect other users on the same system by changing it.

Step 1: Open up a Terminal window (this is in your Applications/Utilites folder by default)

Step 2: Enter the follow commands:

touch ~/.bash_profile; open ~/.bash_profile

This will open the .bash_profile file in Text Edit (the default text editor included on your system). The file allows you to customize the environment your user runs in.

Step 3: Add the following line to the end of the file adding whatever additional directory you want in your path:

export PATH="$HOME/.rbenv/bin:$PATH"

That example would add ~/.rbenv to the PATH. The $PATH part is important as it appends the existing PATH to preserve it in the new value.

Step 4: Save the .bash_profile file and Quit (Command + Q) Text Edit.

Step 5: Force the .bash_profile to execute. This loads the values immediately without having to reboot. In your Terminal window, run the following command.

source ~/.bash_profile

That’s it! Now you know how to edit the PATH on your Mac OS X computer system. You can confirm the new path by opening a new Terminal windows and running:

echo $PATH

You should now see the values you want in your PATH.

The instructions now use the .bash_profile method of editing your PATH. This is preferred as it keeps the changes specific to your user. I also updated the instructions to use Text Edit instead of vim so it is easier for a beginner.

How to dispose of a body like a pro

If you type 52.376552,5.198303 into Google Maps, you will find a man dragging a body into the lake. [obviously fake]

But you shouldn’t get caught like the guys in the foto, so here is an way to do it like a pro I found somewhere on the net.

First, be smart from the very beginning. Pulverize all teeth, burn off fingerprints, and disfigure the face. Forcing a DNA test to establish identity (if it ever comes to that) might introduce the legal/forensic hurdle that saves your ass down the line. An unidentifiable body can, in a pinch, be dressed in thrift store clothes and dropped in a bad part of town where the police are less likely to question it. I don’t reommend that disposal method, I’m just saying an easily identifiable body is an even bigger threat than the opposite.

Assuming you have it inside a house where you can work on it a bit, the first thing you want to do is drain it of fluids. This will make it easier to cut up, and slow decomposition a little bit. The best way to do this quick and dirty is to perforate the body with a pointed knife, and then perform CPR on it. Cut the fronts of the thighs deep, diagonally, to slit the femoral arteries. Then pump the chest. The valves in the heart will still work when dead, and the springback of the ribcage can put apply a fair amount of suction to the artria. Do this in a tub. Plug the drain, and mingle lots of bleach with the bodily fluids before unplugging the drain to empty the tub. This should help control the stench of death, which would otherwise reek from your gutter gratings. Do everything you can to control odors. Plug in an ionizer, burn candles, leave bowls of baking soda everywhere. Ventilate the room in the middle of the night, but otherwise keep it closed. Keep the body under a plastic sheet while it’s in the tub.

If you want to bury, I recommend seperating the body into several parts, and burying them seperately. For one thing, it’s easier to dig a deep enough hole for a head than for an entire body. this reduces your chances of being discovered while you are actually outside and digging the grave.
That is the one thing you can’t do inside the doors of your house, and represents a vulnerable moment you want to keep brief, under 2 hours. Do it between 3 and 5 am. It’s also less likely for someone to call the police if their dog digs up some chunk of meat, than if they dig up an enitre body. They may assume it’s an animal carcass disfigured by decomposition, and leave it alone or dispose of it. It’s also more likely that the dog will consume all of it before anyone knows the difference. A whole skeleton is another story. You can cut a body into 6 pieces faster than you think. It’s not much different than boning a chicken, but it takes more work, a big knife, and time. A hammer will be useful for pulverizing joints or driving the knife deep where it doesn’t want to go. Anyway it’s wise to crush as much of the skeleton as you can along the way. It will aid in making the body less identifiable for what it is as it decomposes.

Don’t return to the same site 6 times for 6 burials.You’ll attract suspicion from anyone nearby, and you’ll wind up placing the body parts close enough together to be found by any serious investigation. Put them in plastic bags with lots of bleach, and store in a freezer until you have enough time to bury them all.

Depending on what tools you have available, you may find that you’re get really good at deconstructing the body. You might prefer to slowly sprinkle it down a drain without leaving your house. This avoids the long-term risk of discovery associated with burial, and the overwhelming supply of bacteria in a sewer accellerates deconomposition, whil e providing a convenient cover smell.

Truly grinding down a body takes a lot more work, and you run the risk of fouling your plumbing and calling in a plumber. So don’t try it unless you know how to clear bones and meat out of a drainpipe. A good food processor can be useful. But don’t over-use it, or power drills or saws. They’re noisy and they attract attention. And forget the kitchen sink. It’s better if you actually remove one of the toilets in your house from its base, which will give you direct access to one of the largest sewer pipes that enters your house. Follow any disposals with lots of bleach and then run the water for 5 or 10 minutes on top of that. And plug that pipe when you’re not using it, to prevent any sewer gasses from backing up into your house. Usually, a U-trap inside the toilet does that for you.


plebiscite |ˈplɛbɪsʌɪt, -sɪt|


the direct vote of all the members of an electorate on an important public question such as a change in the constitution. the administration will hold a plebiscite for the approval of constitutional reforms.

Roman History a law enacted by the plebeians’ assembly.


plebiscitary |-ˈbɪsɪt(ə)ri| adjective

ORIGIN mid 16th cent. (referring to Roman history): from French plébiscite, from Latin plebiscitum, from plebs, pleb- ‘the common people’ + scitum ‘decree’ (from sciscere ‘vote for’). The sense ‘direct vote of the whole electorate’ dates from the mid 19th cent.

Scary Paintings

Electric Chair 1964 Andy Warhol
Electric Chair 1964 Andy Warhol
The Flaying of Marsyas: Titian, c1570-75
The Flaying of Marsyas: Titian, c1570-75
Hell: Hans Memling, c1485
Hell: Hans Memling, c1485
The Temptation of St Anthony: Hieronymus Bosch c1495-1515
The Temptation of St Anthony: Hieronymus Bosch c1495-1515
Medusa: Caravaggio, 1596-98
Medusa: Caravaggio, 1596-98
The Nightmare: Henry Fuseli, 1781
The Nightmare: Henry Fuseli, 1781
Saturn Devouring His Son Peter: Paul Rubens
Saturn Devouring His Son Peter: Paul Rubens
Severed Heads: Théodore Géricault, 1818
Severed Heads: Théodore Géricault, 1818
The Ghost of a Flea: William Blake, c1819-20
The Ghost of a Flea: William Blake, c1819-20