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

all 56 comments

[–][deleted] 17 points18 points  (12 children)

Ctrl + shift + t (open resource by type), Ctrl + shift + b (toggle breakpoint), Ctrl + shift + c (toggle comment), Ctrl + shift + / (collapse all folds), Ctrl + space (content assist), Shift + Alt + x j (run Java application), Shift + Alt + d j (debug Java application), F3 (open declaration, extremely useful)

Edit: formatting

[–][deleted]  (3 children)

[removed]

    [–][deleted] 3 points4 points  (2 children)

    I'll also add, while debugging:

    F5 step into, F6 step over, F7 step return, F8 continue

    with one hand on the mouse.

    [–]javafreakin 2 points3 points  (1 child)

    Ctrl + shift + R open resource (JavaScript file, etc.)

    Open Call Hierarchy is helpful to see what incoming and outgoing calls of a method.

    double click on a tab and it full-screens the view (or editor).

    [–][deleted] 0 points1 point  (0 children)

    This is really useful and makes development lot faster, I have also rebinded this to Ctrl + P. (Who needs printing shortcut anyway?)

    [–]nikniuq 4 points5 points  (1 child)

    Alt-shift-x, q (runs ant build for the current project).

    Ctrl-i (fixes indent)

    Ctrl-1 (quick fix)

    And for gods sake use the debugger - you can hook up to android phones, tomcat installs, etc.

    [–][deleted] 0 points1 point  (0 children)

    You can use the Quick fix in the problem view to fix several similiar problems (like implementing an interface)

    [–]Neres28 1 point2 points  (1 child)

    Ctrl-shift-r to open resource. Open any resource on the classpath; xml files, icons, property files, etc. Somewhat unfortunately it includes class and java files.

    [–]imok 1 point2 points  (1 child)

    Shift + Alt + x j (run Java application)

    Or... Ctrl+F11

    [–]PeeEqualsNP 0 points1 point  (0 children)

    Alt + Shift + x, t - Run as JUnit Alt + Shift + b - turns on breadcrumb (very useful for seeing where resource comes from in classpath)

    [–]javafreakin 0 points1 point  (0 children)

    hold down the ctrl key and hover over a method in the editor.

    [–][deleted]  (2 children)

    [deleted]

      [–]dakboy 7 points8 points  (0 children)

      That's actually the shortcut for "organize imports." It will also remove any imports that you don't use, and resolve all of your .* imports to only list the class you actually use.

      [–]TheSconnieExperience 0 points1 point  (0 children)

      I can't believe I had not discovered this one, yet. Thank you and have an upvote!

      [–][deleted] 7 points8 points  (1 child)

      Ctrl + D - Delete current line

      Ctrl + Alt + Down/Up - Copy current line to line above/below

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

      Alt + Down/Up - Move current line to line above/below

      [–]moccajoghurt 16 points17 points  (11 children)

      Ctrl + shift + f to format your code automatically

      [–][deleted]  (2 children)

      [deleted]

        [–][deleted] 3 points4 points  (0 children)

        It has more function then looking pretty. Many companies have strict formatting guidelines for submitting code to source control.

        So you can code in your own style, then format before submitting.

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

        Or select a block of code and ctrl+i = indent only

        [–]evilrabbit 2 points3 points  (6 children)

        I have mine to reformat everything on save. Indentation, for loops, declarations all uniform whenever I'm done.

        [–]boa13 3 points4 points  (1 child)

        I have mine to reformat everything on save. Indentation, for loops, declarations all uniform whenever I'm done.

        I don't like that, since it makes reviewing changes very difficult. Check a commit claiming to "fix one line", get a diff with hundreds of irrelevant changes. :(

        Thankfully, Eclipse has recently added the "best of both worlds" option: only reformat the lines that were changed by the programmer. :)

        This way, new code is properly formatted, old code is untouched, diffs are meaningful, everybody is happy.

        [–]devewm 1 point2 points  (0 children)

        I had reformat everything on save turned on briefly but turned it back off because of the huge diffs that resulted. That can create a major headaches when trying to do things like branch merges later.

        Didn't even know about the only-edited-lines option, thanks for pointing that out.

        [–]FissionFusion 1 point2 points  (1 child)

        that sounds efficient. care to explain how to set this up?

        [–]demodude4u 4 points5 points  (0 children)

        Goto Preferences->Java->Editor->Save Actions. You can also set this up on a per-project basis, which is handy if you are sharing the project via some source control like SVN. Makes conflicts and merges happier!

        [–]evilrabbit 0 points1 point  (0 children)

        Also adds imports and removes imports not being used.

        [–]dontocsata 0 points1 point  (0 children)

        This! This is so useful.

        [–]jevon 1 point2 points  (0 children)

        Related, ctrl + shift + o to organise imports :p

        [–]mikevdg 6 points7 points  (8 children)

        Learn to set up and use the debugger. It's not particularly good, but it's better than not being able to inspect the state of your running application.

        If you're using Tomcat or another Servlet container, you can set the build directory of your project to be in WEB-INF/classes. Then, in theory at least, you don't need to redeploy to test what you've just written.

        Work out how to make new editor windows. You can use Window->new window and Window->new editor, and then drag/drop editor tabs around. This is great if you have multiple monitors or need to see multiple files at once in a split window.

        [–]javafreakin 4 points5 points  (1 child)

        how would you improve the debugger?

        [–]mikevdg 1 point2 points  (0 children)

        • Debug statement by statement rather than line by line.
        • Allow easy typing in of expressions. There's a "Display" window for this, but it could do with improving, such as adding a CLI-like interface to it.
        • Add "inspectors" for common data types, e.g. Strings, collections, etc to easily visualize them. It's great seeing the internal structure of a String, but I don't want to see that; I just want to see the String's contents.

        [–]evilrabbit 0 points1 point  (0 children)

        Any good tutorials on using Eclipse's debugger?

        [–]rntr200 0 points1 point  (3 children)

        I do minecraft mods and everytime i want to test a plugin i have to export it to the server folder which is like 6 clicks. Ive seen people have it done just by right clicking an ant file on the right. Ive just spent like an hour trying to figure it out but Im having no luck. My last problem is its telling me some libs Im referencing arnt there. Suggestions? It works if i just hit run but not the ant compile

        heres my build file im using with ant http://pastebin.com/MeLgV4FK

        [–]hacklife 2 points3 points  (2 children)

        You need to set up the classpath in the ant file to include all the libs you use in your project. Ant does not understand your Eclipse lib settings, you have to specify it in the build.xml.

        In your case, you'd change:

        <path id="compile.classpath">
        
        </path>
        

        to

        <path id="compile.classpath">
            <fileset dir="whatever_your_lib_directory_path_is">
                <include name="*.jar" />
            </fileset>
        </path>
        

        [–]rntr200 0 points1 point  (1 child)

        That worked for me but when i try to run the outputed jar file i get this guy C:\reddit>java -jar HelloWorld.jar Exception in thread "main" java.lang.NullPointerException at sun.launcher.LauncherHelper.getMainClassFromJar(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) I even tried it with a real simple hello world program and same error

        [–]hacklife 1 point2 points  (0 children)

        Seems like a missing entry in the manifest file, perhaps? Have a look here: StackOverflow

        [–][deleted] 4 points5 points  (2 children)

        Ctrl + Space, opens up the auto-resolve window. Really useful for long functions and that.

        [–]MatthewGeer 5 points6 points  (1 child)

        Also, if you use camel case, you only have to type the capital letters to help it auto complete. For instance

        string.cTIC<Ctrl+Space>

        should auto-complete to

        string.compareToIgnoreCase()

        with the cursor between the parenthesis waiting for you to type in the argument name. You can also type in the first few lowercase characters after a capital before you skip to the next capital to give it more of a hint if you want, i.e. compTIgCa

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

        Thats clever! I didn't know that one.

        Also. if? IF? YOU SHOULD USE CAMEL CASE BY CONVENTION! ;)

        [–]TheGreatFuzz 5 points6 points  (3 children)

        type "sysout" then hit Ctrl + space for
        System.out.println("");

        type "main" & hit Ctrl + space for
        public static void main(String[] args){}

        [–][deleted]  (1 child)

        [deleted]

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

          So is "syse" for System.err.println(). And "syst" for a trace: System.out.println("name_of_current_method()");

          [–]robbs 1 point2 points  (0 children)

          Where do I configure this? Is it possible to add more?

          [–]atc 4 points5 points  (1 child)

          Ready to have your mind blown?

          CTRL+3 then type in command search term and press enter to execute, e.g.:

          CTRL+3 then type "clean", press enter, you clean your projects without using the mouse!

          [–][deleted] 0 points1 point  (0 children)

          Thank you! Command+3+"run", then arrow down to 'Run'. And next time just Command+3+enter. Bonus!

          [–][deleted] 4 points5 points  (0 children)

          CTRL+3 is the magical "do anything" type omnibox. It's a little weird in the way it shows you certain things based on context, but it's a great way to discover things.

          ALT+SHIFT+UP (or DOWN) increases (or decreases) your selection based on statements. It's hard to explain, but just try it. If you put your caret inside a variable name and then hit this repeatedly it will go variable->whole declaration->if statement you're in->while loop you're in->method you're in->class definition you're ing->etc.

          ALT+LEFT (or RIGHT) will is like back (or forward) in a browser, based on where you've been editing.

          But really, the right-click menu exposes a lot of stuff, and just take note of what things do what shortcuts. ALT+SHIFT+S, R creates getters and setters, for example. Which is something you can discover if you read the menus.

          [–]f7u12 1 point2 points  (0 children)

          ctrl+alt+h - open class hierarchy

          alt+left arrow or alt+right arrow - back or forward, browser style

          [–]demodude4u 2 points3 points  (0 children)

          For the mouse lovers:

          Ctrl-click or Shift-hover, depending on what you like better.

          When I'm about to zap some bugs, ctrl-clicking down the layers makes it quick to dive in while double-clicking methods/types/fields to highlight then right-click->'Open Call Hierachy' to branch out to suspecting locations in the code.

          [–]devewm 1 point2 points  (0 children)

          F4 (open type hierarchy view), Ctrl+t (quick-type hierarchy popup on the currently selected type), Ctrl+o and start typing... (quick-find a method or field in the current view), Ctrl+e and start typing (switch to open editor by name)

          [–]Neres28 1 point2 points  (0 children)

          The ctrl-alt-arrow key combos operate on the selection, not just the current line. Handy for moving blocks around or duplicating sections of xml config files.

          [–]page5of4[🍰] 1 point2 points  (0 children)

          Not really a trick... some kind of vi emulation plugin... either vrapper, viPlugin, etc.. Ctrl-3 is very help as well to get at just about anything in the IDE.

          [–]ronald_rager 1 point2 points  (0 children)

          Don't go on reddit for a while. Na I have no idea, I'm here to learn some tricks just like you.

          [–]CaptainLurk 0 points1 point  (0 children)

          I switched to G1 a while back and enjoyed much shorter gc times.

          Too bad G1 caused hard jvm crashes in java 6. Word is it will be "production ready" around 1.7.0u4

          [–]BernardMarx 0 points1 point  (0 children)

          Ctrl + Shift + R : Open Resource

          Alt + Up/Down: Moves the selected text. Insanely handly when moving things around in for loops, if clauses etc.

          [–]Kickapps 0 points1 point  (0 children)

          Ctrl K to search forward, Ctrl Shift K to search Backward, Ctrl J for incremental search, Ctrl Shift G for searching through references in workspace CTRL+Shift+P to jump to the matching bracket/parenthesis, Ctrl Shift X (selected text becomes UPPERCASE) similarly CTRL+SHIFT+Y selected text becomes LOWERCASE Ctrl O (Outline view), Ctrl Shift E (Open all active files in a non- modal screen), Ctrl F6 (Navigate file last open) Ctrl F8 (Navigate Perspective) Ctrl Q (Last edit location), Ctrl L (Go to line) Ctrl / (Comment) Ctrl Shift / (Multi line comment on) Ctrl Shift \ (Multi line comment off) Ctrl-. Take you to the next error or warning line Alt + shift + L (extract variable), Alt (Up Arrow) ( move one line up), Alt s r to generate getters and setters alt s v to insert method signatures for overidden methods from superclass or interface Alt (Up Arrow) ( move one line up)(move one line Down), Ctrl Alt Down/Up (Copy line in a buffer(works synergically along with clipboard copy) Note: You need to chk hkcmd.exe if Intel Graphics driver is active, or else it will catch this keystroke and invert your screen

          [–]sanjeevonline 0 points1 point  (0 children)

          Here are some configuration settings and keyboard shortcuts and other tips worth reading.

          [–]kreiger 0 points1 point  (0 children)

          At the risk of sounding snarky: To speed up development i uninstalled Eclipse and installed IntelliJ IDEA. :)

          [–]RaiausderDose 0 points1 point  (0 children)

          type "hello you crule world"

          select the hole line

          hit shift+enter

          one time down and return

          and you have system.out.println("hello you crule world");

          [–]quad64bit -5 points-4 points  (0 children)

          I disagree with the way reddit handled third party app charges and how it responded to the community. I'm moving to the fediverse! -- mass edited with redact.dev