How to display UTF-8 characters in Eclipse / RAD Console

The default setting in your Eclipse or IBM Rational Application Developer console does not support UTF-8. You have to turn it on your self in the preferences. The following diagram shows how you can do it.

Open our IDE Preferences and go to General > Workspace Then underneath Text file encoding, change the value from Default (cp15252) to UTF-8. If you are looking for other character sets, there are some options in the drop down as well.

Once you turn this feature on, you can have your program spit out UTF-8 characters to your console and the console should be able to display those characters without a problem. Here is a screenshot from my machine when I did this change.

How To Set Conditional Debug Breakpoints in Eclipse or IBM RAD?

Developers and Production Support Analysts will, in their lifetime, spend a lot of time debugging, specially if the applicaiton is complex and they have no idea on what’s going on. I mentioned Production Support Analysts because they are the ones in most companies analyzing and fixing the defects in production environments. Developing the new features probably does not need you as much to debug as it needs for maintenance work, specially if you are trying to understand what’s going on and what is the flow.

There are many occasions you don’t want to debug every steps. For example, if there is a for loop that loops for a 1000 times and that you know it fails on the 100th step or are intersted to see what’s going on somewhere around that, would it make sense to go through the 99 steps of debugging before hitting the 100th one? It certainly does not make sense to me unless you have a lot of time to hit those debug short cuts (I love those F5,F6,F7,F8 shortcut keys in Eclipse and IBM RAD by the way).

So what can you do about it? Well the IDEs like Eclipse or IBM RAD offer you a way to set conditional breakpoints – the IDE will stop at the breakpoint you set only when certain conditons are met.

The following is some piece of code with a for-loop. Let’s say we are interested to look at the value of the variable ‘random’ when the value of i is 100.

package com.kushal.tools.published;
/**
 * @author Kushal Paudyal
 * www.sanjaal.com/java
 * www.icodejava.com
 * 
 * Written to be used in a tutorial to show how to do 
 * conditional break points in eclipse
 */

public class ConditionalBreakPointEclipse {

    public static void main(String args[]) {

        doSomeStuff();
    }

    /** Just outputting some random numbers. We would like to
     * add a conditional breakpoint when the value of i is 100.
     */
    public static void doSomeStuff() {

        for (int i = 0; i <= 1000; i++) {

            double random = i * Math.random();

            System.out.println(i + " - Random - " + random);
        }
    }

}

The first step is to set a breakpoint where it says

double random = i * Math.random();

Here is a screenshot for that.

Eclipse - Putting a breakpoint

The second step is to right click on the breakpoint and choose ‘Breakpoint Properties…’.

Eclipse - right click on the breakpoint

On the third step, enable the checkbox ‘Conditional’. The text area underneath the checkbox will be enabled and that is a place where you can put your conditions. In my case, I simply typed in i==100 because I wanted to stop when the value of i is 100.

Eclipse - Adding the conditional in the Line Breakpoint Properties

Now close the window and run the application in debug mode. You will see that after the value of i reaches 100 and when the statement where we put the breakpoint is reached, the IDE will stop for you to evaluate the variables at that point. Isn’t that neat? Once you hit F7, the program should continue without another stop at the breakpoint.

Eclipse - Debugging with conditional breakpoint

Compare this to not having a conditional breakpoint. You would have to step through 99 times before it reached your desired value of i and to finish debugging the program, you would have to hit F7 for another 900 times (or just stop debugging)!!

You are going to appreciate that IDEs provide this great feature.

List of valid @suppresswarning annotation parameters in Java for Eclipse and IBM RAD IDE

The following is a list of most of the valid @suppresswarning annotation parameters in Java for Eclipse and IBM RAD IDE. The right column shows what those java annotation parameters are used for.

Annotation Param

Usage

intfNonInherited interface non-inherited method compatibility
javadoc invalid javadoc
localHiding local variable hiding another variable
maskedCatchBlocks hidden catch block
nls to suppress warnings relative to non-nls string literals
noEffectAssign assignment with no effect
null to suppress warnings relative to null analysis
nullDereference missing null check
over-ann missing @Override annotation
paramAssign assignment to a parameter
pkgDefaultMethod attempt to override package-default method
raw usage a of raw type (instead of a parametrized type)
restriction to suppress warnings relative to usage of discouraged or forbidden references
semicolon unnecessary semicolon or empty statement
serial to suppress warnings relative to missing serialVersionUID field for a serializable class
specialParamHiding constructor or setter parameter hiding another field
static-access to suppress warnings relative to incorrect static access
staticReceiver if a non static receiver is used to get a static field or call a static method
super overriding a method without making a super invocation
suppress enable @SuppressWarnings
synthetic-access to suppress warnings relative to unoptimized access from inner classes
tasks enable support for tasks tags in source code
typeHiding type parameter hiding another type
unchecked to suppress warnings relative to unchecked operations
unnecessaryElse unnecessary else clause
unqualified-field-access to suppress warnings relative to field access unqualified
unused to suppress warnings relative to unused code
unusedArgument unused method argument
unusedImport unused import reference
unusedLabel unused label
unusedLocal unused local variable
unusedPrivate unused private member declaration
unusedThrown unused declared thrown exception
uselessTypeCheck unnecessary cast/instanceof operation
varargsCast varargs argument need explicit cast
warningToken unhandled warning token in @SuppressWarnings

 

Here is an usage example. As you can see, the piece of code below does not use any annotations and the code has a yellow underline in the method signature. If you hover around the icon on the left bar of the IDE where there will be warning sign, you will notice that the Eclipse IDE has issued warning saying that this method is never called in the class.

 

But if you put the annotation @SuppressWarning(“unused”), we specifically tell the IDE to ignore the usused methods by suppressing the warnigns. Here is the code after the annotation has been added. Code looks clean, no more annoying warning underline !