Proficient in Eclipse V3.4, part 3rd: JDT text editor tips and tricks

Source: Internet
Author: User

This section of the "Mastering Eclipse" series will detail the Java editor for Eclipse. Developers will spend a lot of time on the editor, so knowing their advanced features can significantly improve your productivity.

Organize Imports Command

The Organize Imports command adds the missing import and organizes the existing import declarations into the Java file. You can run this command in the current editor by using the Ctrl+shift+o key combination. To apply the Organize Imports command to the entire project, right-click the project in the Project Explorer and select Source > Organize Imports.

Suppose you used a class somewhere in the Java file, but you forgot to import the class: Organize imports can automatically import the class for you. If the command does not determine the location of the class, a window opens and displays a list of options that you can choose from. For example, if you use the List class in your code, when you run the Organize Imports command, a window may pop up asking you to choose between Java.util.List and Javax.swing.List, because the command cannot be selected by itself.

Organize imports also divides the import declarations of commonly used. * Styles into separate import statements. For example, suppose your file has an import statement such as import java.util.*, and only the List class from that package is used. The Organize Imports command replaces the initial import statement with the import java.util.List.

Select part of a string

Typically, you need to concatenate a variable between two strings. In most cases, these strings belong to a single statement, and it is easy to make mistakes that omit spaces on either side of the string. For example, you might get output like have5seconds left rather than your have 5 seconds left. Eclipse will prevent you from falling into this trap:

Type the string as usual in your code:static String getMsg(int time)
{
   return "You have 5 seconds left";
}

Select the part of the string that you want to replace with the variable-in this case, the number 5.

Press the CTRL+1 key combination and select Pick out selected part of String.

Figure 1. Select Pick out selected part of String

The results are shown in Figure 2.

Figure 2. Select the selected string portion

Replaces the middle string with a variable.

Figure 3. Replace a string with a variable

You can now make sure that you do not make space errors.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.