Introduction to common shortcut keys in eclipse & myeclipse

Source: Internet
Author: User

I believe that friends who often develop Java applications often use some shortcut keys. In this article, I will summarize some of the shortcut keys I have used.

1. Import the required package

For example, let's write a collection class-arraylist. The required package is called import Java. util. arraylist; If eclipse does not provide us with reference to this package, we need to add it ourselves. If we do this manually, the efficiency will be very low, eclipse provides a shortcut to introduce the required package-Ctrl + Shift + O, you only need to press these keys to import the required package (I usually click these keys ).

2. Code comments

There are two types of code Annotations: one is code block annotation and the other is line annotation.

A code block refers to a piece of code. Generally, the code is closely related to each other, and it is like the following:

/* Private Static void addtoarray () {long begin = system. currenttimemillis (); For (INT I = 0; I <count; I ++) {my_array.add (I);} long over = system. currenttimemillis (); system. out. println ("operation" + "arraylist. the time required for the add () method is: "+ (over-begin) +" millisecond ");}*/

The comments of code lines refer to one or several lines of code that are commented out. The operation is like this after execution:

// System. Out. println ("operation" + "arraylist. Add () method takes the following time:" // + (over-begin) + "millisecond ");

The shortcut keys used in the two annotation methods are:

Code block: Ctrl + Shift +/

Code line: Ctrl +/

Of course, you can also manually add comments. However, is this faster and more convenient?

3. view the class source code

Sometimes, when writing code, we want to know the internal implementation of classes in JDK. The general practice is to view the JDK documentation, where there are comments and source code. However, you can also do this in eclipse. You only need to press Ctrl + T to view the source code of this class (including the parent class and subclass). For example, I want to view the source code of arraylist, after I press the shortcut key, I can see its source code. When you perform the operation, the screen is like this:


4. view the methods provided by the class

Sometimes we only need to check the methods provided by this class, but do not want to view the source code. Eclipse also provides the shortcut key -- Ctrl + O. When you press it, the screen is like this:


Note: The Red Square indicates the private method, and the Green indicates the public method.

5. Add comments to the code

After we write a method or a class, we usually add some comments to the Code for later maintenance convenience. Generally, our comments will be like this:

/*** Delete data from arraylist -- delete */Private Static void delfromarray () {long begin = system. currenttimemillis (); For (INT I = 0; I <my_array.size (); I ++) {my_array.remove (I);} long over = system. currenttimemillis (); system. out. println ("operation" + "arraylist. the remove () method takes the following time: "+ (over-begin) +" millisecond ");}

The shortcut for this operation is: Alt + Shift + J.

6. Code formatting

Most of the time, your code pays great attention to the format requirements. However, sometimes it is inevitable that there will be some "errors". For example, if you forget to place spaces on both sides of the arithmetic operator, forget to add a space after if ..., at this time, of course, you do not want to check it yourself. At the same time, because this is your own mistake and you do not want to bother others, haha, and you need the help of Eclipse, we only need to press Ctrl + Shift + F. Here, F means format. For example, we have the following code:

Private Static void delfromarray () {long begin = system. currenttimemillis (); For (INT I = 0; I <my_array.size (); I ++) {my_array.remove (I);} long over = system. currenttimemillis (); system. out. println ("operation" + "arraylist. the remove () method takes the following time: "+ (over-begin) +" millisecond ");}

This is of course unacceptable. However, after we press the shortcut key to format it, it becomes like this:

Private Static void delfromarray () {long begin = system. currenttimemillis (); For (INT I = 0; I <my_array.size (); I ++) {my_array.remove (I);} long over = system. currenttimemillis (); system. out. println ("operation" + "arraylist. the remove () method takes the following time: "+ (over-begin) +" millisecond ");}

Note: Some shortcut keys may conflict with the shortcut keys set for some applications. Therefore, do not make mistakes when using them.

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.