8 Eclipse Keyboard Shortcuts Essential for Beginners | TechBuzz

- Advertisement -


Eclipse is one of the most popular integrated development environments (IDEs) for Java programming. While there are other tools available on the market, such as NetBeans, their learning curve is often quite steep.

You can use Eclipse’s package explorer to see a list of all the files in your Java (or Android) project. You can quickly move to a function using the outline pane, get suggestions for functions and imports, and more.

There are also numerous keyboard shortcuts that will aid you in your first steps with Eclipse. Here are some of the best keyboard shortcuts for efficient use of Eclipse.

1. Organize Imports (Ctrl + Shift + O)

To use a class in Java, you need to import it or the package it belongs to. Eclipse uses this import to validate your code and provide auto-completion (real-time typing suggestions).

- Advertisement -

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();

MAKEUSEOF VIDEO OF THE DAY
- Advertisement -

And then use the Organize Imports shortcut, it becomes 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 your code until you see the red squiggly lines indicating missing classes. Then hit the Organize Imports shortcut.

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

2. Correct Indentation (Ctrl + I)

- Advertisement -

Code readability is important—when you’re reading your own code at a later date, or when somebody else is.

Poor indentation is one of the most common programming mistakes people make in a hurry. In layman’s terms, indentation means the blank or empty space at the start of a code line.

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 it from elsewhere. Either way, the good news is that Eclipse makes it trivially easy to fix. Highlight the code that you want to clean up, then use the Ctrl + I shortcut to instantly bring it to proper indentation.

You can use Ctrl + A to select the entire file, then use this shortcut to quickly fix all the 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 also change how Eclipse handles indentation by going to Window > Preferences, then in the left panel, navigate to Java > Code Style > Formatter > Edit… > Indentation.

3. Delete Current Line (Ctrl + D)

When you start learning Java it’s natural to delete entire lines of code at a time. The worst way to do this? Highlight with the mouse and then hit Backspace. The rookie way to do this? Hit the End key, hold Shift, hit the Home key, then Backspace.

But what about the pro way? You just need to put your mouse cursor on the line and then press Ctrl + D to delete it in one go.

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 our idea of a fun time.

Here’s what you do instead:

  1. Type the first few letters of the class, method, or variable you want.
  2. Then hit the Ctrl + Space key combination. This brings up a list of autocomplete recommendations along with method signatures, variable types, and more.
  3. Select the recommendation you want to apply, hit the Enter key, and keep coding.

Things like Eclipse autocomplete shortcuts are some of the reasons why IDEs trump text editors. As newbie-friendly as Eclipse’s interface is, you owe it to yourself to learn such keyboard shortcuts. They’ll boost your productivity even further, guaranteed.

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, there’s a quick shortcut for System.out.println() in eclipse: 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 can start typing the message right away.

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 three search types: File Search, Git Search, and Java Search. You’ll mostly use Java Search, which only searches through source files, but the other two can be useful in their own ways.

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. This runs the current project using the same configuration as the last time you ran it.

8. Rename (Alt + Shift + R)

Here’s the thing about class, method, and variable names: your code might contain references to them many, many times. Now imagine if you ever needed to change the name of a class, method, or variable. It could take hours (or even days) to rename every single reference.

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

Other Tips for Beginner Java Programmers

There are many other Eclipse shortcuts that will help you. Ctrl + Shift + F formats code, Ctrl + E switches between editor tabs, Ctrl + 1 quickly fixes errors, and so on.

Eclipse is a powerful, feature-filled IDE that many Java programmers favor. However, it’s not the only IDE available. Make sure you check out the alternatives to discover which one suits you best.


NetBeans vs. Eclipse vs. IntelliJ
What’s the Best Java IDE? NetBeans vs. Eclipse vs. IntelliJ

Read Next


About The Author



Source link

- Advertisement -
Adminhttp://techbuzz.asia
I am admin of techbuzz.asia blog & I provide tech-related news. As a part of my hobby, I make content related to technology and gadgets reviews too. I love to be a content creator apart from it, I am a full-time employee in an MNC company and manage blogs systematically. You can mail me at [email protected]

More from author

Related posts

Advertisment

Latest posts

9-euro ticket: Vodafone makes a big promise to train passengers | TechBuzz

Many more people want to travel by train with the 9-euro ticket. At least that is what is expected at Deutsche Bahn and...

‘Call of Duty: Modern Warfare II’ stiže 28. listopada | TechBuzz

Good news for Call of Duty franchise fans! The new sequel, Modern Warfare II, will be released on October 28 this year. ...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!