8 Most Useful Keyboard Shortcuts For Beginner Eclipse IDE Users
Pinterest Stumbleupon Whatsapp
Advertisement

This article was originally written for Eclipse Juno but has since been updated for Eclipse Oxygen.

I recently had two pair-programming assignments, each in Java and each with a separate partner. Going into this without much knowledge, my first partner suggested using Eclipse IDE, and that turned out to be a great choice. If you’re just starting out in Java, Eclipse is the way to go.

In the past, I’d tried learning the notorious VIM editor, but despite all the VIM tutorials out there, I found the learning curve too steep. Eclipse is much easier to grasp: you can see a list of all the files in your Java (or Android for that matter) project in the package explorer, easily navigate to the desired function with the outline window, get suggestions for functions, imports, and more.

Fortunately for me, my first partner taught me a number of useful workflow keyboard shortcuts, which I then passed on to my second partner who knew as little as I did. As newbie-friendly as Eclipse’s interface is, you owe it to yourself to learn these keyboard shortcuts. They’ll boost your productivity even further, guaranteed.

1. Organize Imports (Ctrl + Shift + O)

Whether you’re working with Java’s native libraries and classes or incorporating third-party frameworks into your code, one thing is true: in order to use a class, you have to first import the class before Eclipse will identify it as valid and available for code autocompletion (real-time typing suggestions).

But who has time to memorize every single package path for every single class in every single library? You can let Eclipse handle it for you using the Ctrl + Shift + O shortcut, which automatically imports unrecognized classes in code.

For example, if you have this bit of code:

public class Hello {
  public static void main(String[] args) {
    ArrayList list = new ArrayList();
  }
}

And then use the Organize Imports shortcut, it becomes like this:

import java.util.ArrayList;

public class Hello {
  public static void main(String[] args) {
    ArrayList list = new ArrayList();
  }
}

Instead of typing import lines by hand, you can just write code as normal until you see the red squiggly lines (indicating unrecognized classes), then hit the Organize Imports shortcut.

Note that this shortcut also removes unused imports (in cases where you deleted code) and sorts the import statements by package.

2. Correct Indentation (Ctrl + I)

Code readability is important, not only for you (so you can come back at a later time and understand what you wrote) but for anyone else who may look at your code (partners, professors, open source contributors). Proper indentation is essential.

Does your code often look like this?

public void insertHead(int x) {
  Link newLink = new Link(x);
 if (isEmpty())
   tail = newLink;
 else
    head.previous = newLink;
  newLink.next = head;
   head = newLink;
}

Maybe you wrote it that way, or maybe you copy-pasted from elsewhere. Either way, the good news is that Eclipse makes it trivially easy to fix: highlight the portion of code that’s hard to read, then use the Ctrl + I shortcut to instantly bring it to proper indentation:

public void insertHead(int x) {
  Link newLink = new Link(x);
  if (isEmpty())
    tail = newLink;
  else
    head.previous = newLink;
  newLink.next = head;
  head = newLink;
}

You can change how Eclipse handles indentation by going to Window > Preferences, then in the left panel navigate to Java > Code Style > Formatter > Edit… > Indentation. Learn more about how to write clean code 10 Tips for Writing Cleaner & Better Code 10 Tips for Writing Cleaner & Better Code Writing clean code looks easier than it actually is, but the benefits are worth it. Here's how you can start writing cleaner code today. Read More .

3. Delete Current Line (Ctrl + D)

When coding in Java, it’s natural to remove entire lines of code at a time. The worst way to do this? Highlight with the mouse, then hit Backspace. The rookie way to do this? Hit the End key, hold Shift, hit the Home key, then Backspace. But the pro way? Simply hit Ctrl + D:

8 Most Useful Keyboard Shortcuts For Beginner Eclipse IDE Users java eclipse tips delete line

4. Autocomplete Recommendation (Ctrl + Space)

Java is unfortunately known for being extremely verbose — the names of classes, methods, and variables are some of the longest in the entire programming industry. Typing them all by hand every single time? Not my idea of a fun time.

Here’s what you do instead: type the first few letters of the class, method, or variable you want, then hit Ctrl + Space. This brings up a list of autocompletion recommendations along with method signatures, variable types, and more. Select the right one, hit Enter, and keep coding.

8 Most Useful Keyboard Shortcuts For Beginner Eclipse IDE Users java eclipse tips autocomplete

Features like autocompletion are some of the reasons why IDEs trump text editors Text Editors vs. IDEs: Which One Is Better For Programmers? Text Editors vs. IDEs: Which One Is Better For Programmers? Choosing between an advanced IDE and a simpler text editor can be hard. We offer some insight to help you make that decision. Read More .

5. System.out.println (“sysout” and Ctrl + Space)

When working with console applications, you’ll need to use System.out.println() for printing messages. But because this is so cumbersome, Eclipse has a quick shortcut for you: type “sysout” (without the quotes), then hit Ctrl + Space.

The best part? The cursor is immediately placed within the method call’s parentheses, so you start typing the message right away:

8 Most Useful Keyboard Shortcuts For Beginner Eclipse IDE Users java eclipse tips sysout

6. Search Entire Project (Ctrl + H)

When working on large codebases, it’s easy to forget where you declared certain classes, methods, or variables. Instead of wasting time combing through directories by hand, use the Search Entire Project prompt with the Ctrl + H shortcut.

By default, it comes with four search types: File Search, Task Search, Git Search, and Java Search. You’ll mostly use Java Search, which only searches through source files, but the other three can be useful in their own ways.

8 Most Useful Keyboard Shortcuts For Beginner Eclipse IDE Users java eclipse tips search

7. Run Application (Ctrl + F11)

The first time you run a new project, you should do it through Run > Run As… > Java Application. But after that, you can speed things up with the Ctrl + F11 shortcut, which runs the current project using the same configuration as the last time the project ran.

8 Most Useful Keyboard Shortcuts For Beginner Eclipse IDE Users java eclipse tips run

8. Rename (Alt + Shift + R)

Here’s the thing about class, method, and variable names: once declared, they can get referenced dozens, hundreds, or even thousands of time throughout a project. Now imagine if you ever need to change the name of a class, method, or variable. It could take hours (or days!) renaming every single reference.

Or you can right-click on the name, select Refactor > Rename, type in the new name, and have Eclipse change every single reference in the entire project in a second. Even faster, you can click on the name, hit Alt + Shift + R, type in the new name, and hit Enter. Bam, done!

8 Most Useful Keyboard Shortcuts For Beginner Eclipse IDE Users java eclipse tips rename

Other Tips for Beginner Java Programmers

As a Java programmer, you should absolutely understand how the Java virtual machine works Why the Java Virtual Machine Helps Your Code Run Better Why the Java Virtual Machine Helps Your Code Run Better What to know why the java virtual machine gives java more advantages over native programming for an application? Read on to find out! Read More and why it allows for cross-platform development. You should also be familiar with these core Java concepts 10 Core Java Concepts You Should Learn When Getting Started 10 Core Java Concepts You Should Learn When Getting Started Whether you are writing a GUI, developing server-side software, or a mobile application using Android, learning Java will serve you well. Here are some core Java concepts to help you get started. Read More , such as how to use exceptions in Java Java Exceptions: Are You Handling Them Right? Java Exceptions: Are You Handling Them Right? An Exception in programming signifies an exceptional condition in the program execution. It's used when the condition can be handled better elsewhere. Consider the following examples of Java exception handling. Read More .

I also highly recommend some of these free programming books 9 Free Programming Books That Will Make You A Pro 9 Free Programming Books That Will Make You A Pro Calling all programmers, whether new, old, or aspiring: we've found a great selection of free (as in beer) books to boost your coding skills to the next level. Hop in and enjoy. Read More , including Thinking in Java, Apprenticeship Patterns, and 97 Things Every Programmer Should Know. And don’t skip these tips for mastering a new programming language 7 Useful Tricks for Mastering a New Programming Language 7 Useful Tricks for Mastering a New Programming Language It's okay to be overwhelmed when you are learning to code. You'll probably forget things as quickly as you learn them. These tips can help you to better retain all that new information. Read More .

What other handy tips do you have for beginners to Java or Eclipse? Let us know in the comments below!

Leave a Reply

Your email address will not be published. Required fields are marked *