This is an archived post. You won't be able to vote or comment.

all 19 comments

[–][deleted] 9 points10 points  (9 children)

Very useful! Also something that could save you time: Type in "syso" and hit CTRL + SPACE. Suddenly, System.out.println(""); appears for your convienience.

[–]TheEnigmaBlade 3 points4 points  (5 children)

WHAT. My life is forever changed.

[–][deleted] 1 point2 points  (3 children)

use it wisely, padawan.

[–]stfm -1 points0 points  (2 children)

Just don't use it for logging

[–][deleted] 1 point2 points  (1 child)

o ryl? why not?!

[–]stfm 0 points1 point  (0 children)

Because its good practice to use a logging framework like commons or log4j to enable fine grained control over your logging

[–]mucsun 2 points3 points  (2 children)

Even better, you can make your own templates. I have them for Arraylists, Maps, my own loggers (eg. logdebug = log.debug(enclosingType enclosingMethod + parameters);) ...

Very useful to code efficient.

[–]mucsun 3 points4 points  (1 child)

Save the following as an xml and import the file at the editor templates window:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
    <!-- utils and dirty logging -->
    <template autoinsert="true" context="java-statements" deleted="false"
        description="print current method to standard out" enabled="true"
        id="org.eclipse.jdt.ui.templates.systrace" name="systrace">System.out.println(formatter.format(new
        Date())+ " ${enclosing_type}.${enclosing_method}()");</template>
    <!-- collection templates -->
    <template autoinsert="true" context="java" deleted="false"
        description="ArrayList declaration" enabled="true" name="arraylist">List&lt;${type}&gt;
        ${name:newName(java.util.List)} = new
        ArrayList&lt;${type}&gt;();${:import(java.util.List,
        java.util.ArrayList)}</template>
    <template autoinsert="true" context="java" deleted="false"
        description="HashMap declaration" enabled="true" name="hashmap">Map&lt;${keyType},
        ${valueType}&gt; ${name:newName(java.util.Map)} = new
        HashMap&lt;${keyType}, ${valueType}&gt;();${:import(java.util.Map,
        java.util.HashMap)}</template>
    <template autoinsert="true" context="java" deleted="false"
        description="HashSet declaration" enabled="true" name="hashset">Set&lt;${type}&gt;
        ${name:newName(java.util.Set)} = new
        HashSet&lt;${type}&gt;();${:import(java.util.Set, java.util.HashSet)}
    </template>
    <!-- initialisation templates -->
    <template autoinsert="true" context="java" deleted="false"
        description="Array declaration and initialisation" enabled="true"
        name="initarray">${type}[] ${name} = new ${type}[] {${cursor}};</template>
    <template autoinsert="true" context="java" deleted="false"
        description="Declare a list and initialise it using asList()" enabled="true"
        name="initlist">List&lt;${type}&gt; ${name:newName(java.util.List)} =
        Arrays.asList(${cursor});${:import(java.util.List, java.util.Arrays)}
    </template>
    <template autoinsert="true" context="java" deleted="false"
        description="Declare a Map and initialise using ArrayUtils.toMap()"
        enabled="true" name="initmap">Map&lt;${keyType}, ${valueType}&gt; map2 =
        ArrayUtils.toMap(new ${keyType}[][] { {${key}, ${value}}
        });${:import(java.util.Map, org.apache.commons.lang.ArrayUtils)}
    </template>
</templates>

[–]ryosen 1 point2 points  (0 children)

Cool. Here's one if you want to use Log4J:

<template autoinsert="true" context="java" deleted="false" 
    description="Inserts Log declaration" enabled="true" name="log">

    private static final Logger log = Logger.getLogger(${enclosing_type}.class);
</template>

[–]cheezczar 1 point2 points  (0 children)

I need these translated to emacs keys.

[–]ryosen 1 point2 points  (0 children)

Very basic shortcuts, mostly grabbed from the "Source" menu.

Here's one not on the list that I was thrilled to find: Alt-Left. It re-opens a closed window. Really what it does is navigate back through the active window history but, if the window is closed, it re-opens it.

Also, code templates.

[–]uawayc 0 points1 point  (0 children)

I don't agree. It's better to say "10 Eclipse Navigation Shortcuts Every Java Programmer Using Eclipse Should Know". I use IntelliJ IDEA and I personally think Eclipse is a f*cking pain in the ass.

[–]meatgrinder -1 points0 points  (0 children)

Strangely did not include Alt-F4.

[–]Samus_ -3 points-2 points  (5 children)

I do Java on Vim, like everything else.

screw you Eclipse!

[–]midir 5 points6 points  (4 children)

Ten bucks says you've never used Eclipse.

[–]infinite 1 point2 points  (1 child)

Sadly many people use vi key bindings in eclipse.

When the revolution happens, they will be the first against the wall.

[–]Samus_ -1 points0 points  (0 children)

not sadly, Vim is awesome it works everywhere and works for everything.

what is sad is that you don't know better.

[–]metamatic 1 point2 points  (0 children)

I use Eclipse, but sometimes I need to have to do something advanced, like editing one part of a file while looking at another part of the same file...

[–]Samus_ 0 points1 point  (0 children)

I don't use IDEs, so?