Welcome to this Blog. I am Software Engineer and work for Zühlke Engineering AG in Bern. This is my private blog, in which I will post mainly about technical stuff like Software Engineering or IT related topics. The views expressed herein do not necessarily represent those of my employer.

 

 
 

 

Today, I encountered a very helpful feature in Eclipse. When I am debugging code, I sometimes want to know, what’s the result of a method is. If the result it’s not assigned to a variable, it gets complicated. Take a look to this example: what is the result of add(17,19)?

public class DemoApplication {
 
    public static void main(String[] args) throws Exception {
        DemoApplication calc = new DemoApplication();
        System.out.println(calc.divide(calc.add(17, 19), 2));
    }
 
    public int add(int i, int j) {
        return i + j;
    }
 
    public int divide(int i, int j) {
        return i / j;
    }
}

In earlier times, I stepped one step further to get into the method divide. Then I got the result of add(17,19) in my parameter.

 

But Eclipse is offering a better solution. In the Debugging Perspective, there is a view called Expressions. Just add a new expression add(17,19) and the Debugger is printing out the result.

image

The result is directly printed out:

image

 

A simple, but helpful feature in Eclipse!

 

 

 
 

 

In Eclipse, there is a nice feature to clean up Java code. First, you can change the Clean Up profile (Window – Preferences) and define, how you want the code should look like.

image

There are interesting clean ups like “Remove unnecessary casts” or to add missing Annotations like “@Override”.

image

After creating your profile, simply right click to the project and choose Source – Clean up.

Nice feature. If you want to know more about this feature, you will find here more information’s.

 

 

 
 

 

After the ultimate shortcut, which I mentioned here, there’s another nice shortcut in Eclipse: CTRL + 1. This shortcut helps you almost in every situation. Let me mention two examples (there a lot more, just try it out):

 

Use CTRL + 1 to assign a parameter of a constructor as a field:

image

image

 

Or use CTRL + 1 to extract a String or another variable to a constant:

image

 

 

 
 

 

Are you a real men (or women)? Because if you are one, Eclipse offers you the possiblity to “don’t click” ;-) Try to use the simple shortcut CTRL + 3. What happens? Eclipse opens the Quick access window:

image

 

Now, type what you want, for example “new xml file”, and Eclipse searches for the command, which consists of these words:

image

 

Also very interesting is the access to the Preferences window. Try to search for “classpath variables” or “build path”, you get direct access to these settings. Also interesting is “Generate Getters”. If you don’t know a specific shortcut, just use CTRL + 3 from now on!

 

 

 
 

 

If you press CTRL + O in Eclipse, a list with all members and methods shows up. Red highlighted are private members/methods, green public ones. But unfortunately, inherited methods are invisible.

image

Now, just press CTRL + O again and you can see all inherited methods.

image

I know, the hint is mentioned in the bottom right corner, but I didn’t noticed this until today…

 

 

 

Older Posts »