1. The introduction of the eclipse

Eclipse is a well-known integrated development environment around the world that is primarily used to develop Java programs. Like the AK47 in the hands of soldiers, it won the hearts of programmers as soon as it appeared.

By the way, be sure to install JDK before using Eclipse!!

1.1 Latest download address on the official website

https://www.eclipse.org/downloads/
Copy the code

But! But! But! The latest version of Eclipse requires the lowest JDK version to be JDK11. However, currently jdK11 is charged for all the above versions, so I recommend that you use the corresponding VERSION of JDK8, after all, 90% of enterprises use JDK8.

Here is an eclipse for the JDK8 version:

Link: https://pan.baidu.com/s/1M2A55me16otDT4kF2dK09Q Extraction code:1234 
Copy the code

In addition, I would like to recommend a domestic mirror address: university of Science and Technology mirror. It not only contains all versions of Eclipse, but also synchronizes updates with the official website and is very fast to download. You can download it on demand.

http://mirrors.ustc.edu.cn/eclipse/technology/epp/downloads/release/
Copy the code

2. The eclipse installation

2.1 Decompress – Double-click to run

2.2 Desktop Shortcuts

Sometimes you forget where to install it, so right-click Eclipse.exe to send the software icon to the desktop shortcut.

2.3 Workspace

Double-click the icon to run, the first interface will appear:

A workspace is called a workspace, where all your code is stored, and the default is drive C. But our computer C disk is generally the system disk, too many things will be stuck, so it is recommended to install in the C disk outside the hard disk inside.

Use this as the default and do not ask again means that the workspace is there by default, and the next time you open Eclipse, you will not be asked again. Let’s also tick it here so it doesn’t beep next time.

3. The eclipse configuration

3.1 the layout

The first page of Eclipse is the welcome screen, which means “Welcome to the world of bald programmers!!”

I quickly clicked the close button next to Welcome, which showed the Eclipse layout. Here I’ve broken the Eclipse layout into five parts:

    1. Project directory
    1. Where you write code
    1. The menu bar
    1. Shortcut button
    1. The console

3.2 Adjusting the Interface

Sometimes we can make a mistake and the layout will look like a mess. For example:

To restore the default layout, click Window -> Perspective -> Reset Perspective

3.3 Setting the Encoding

In the development process, we often encounter Chinese garbled characters, so we need to set the encoding format to be consistent, generally set the encoding format to UTF-8 format.

What’s more, in our senior year, we have to do our computer graduation project. Some of us may have bought some programs from a treasure or a fish.

But when importing procedures have found all kinds of garbled error, this time also need to modify the encoding format.

3.3.1 Setting the coding format of the workspace

Window -> Preferences -> General -> Workspace
Copy the code

3.3.2 Set the coding format of the project

Select Project -> Right-click -> Properties -> Resource -> Set UTF-8Copy the code

3.3.3 Setting JSP page coding format

Window -> Preferences -> Web -> JSP Files -> Encoding Set to ISO 10646/Unicode(UTF-8)Copy the code

3.4 Change the code font size

Window -> Preferences -> General -> Appearance -> Colorsand Fonts -> Basics -> Text Font
Copy the code

Before the change:

After the changes:

3.5 Customizing Code Templates

We often write a lot of repetitive code, but people are lazy, so is there a way to type a letter or a few letters and get lines or even hundreds of lines of code?

The answer is yes.

Window -> Preferences -> Java -> Editor -> Templates
Copy the code

A list code template is defined above. I type a list and press Alt + / at the same time to see that the page displays the code template I just created

Press Enter again

Remember: First type the template name (custom shortcut name), then be sure to press Alt + / and then Enter.

3.6 Setting a Custom Comment

Detailed comments are crucial for readable and maintainable code, but relying on them by hand is inefficient and difficult to standardize. Here’s a look at eclipse’s custom annotation capabilities.

Window -> Preference -> Java -> Code Style -> Code Template
Copy the code

  • Types: Annotates classes
  • Constructors: Comment on Constructors
  • Methods: Comments Methods
  • Overriding Methods: Comment on Overriding Methods
  • Getters: Comments the get method
  • Setters: Comments the set method

Here we set up a custom comment template for the class:

/** * @className: ${file_name} * @description: TODO * @author: Eclipse * @university: Eclipse * @date: ${date} */Copy the code

Then we create a new class, and our custom annotation template is displayed automatically on top of the class.

Note: Always check Automatically add….

4. Common Eclipse operations

4.1 Creating a Java Project

File -> New -> Java Project
Copy the code

Then enter a project name and click Finish

4.2 the new package

Bags can hold books, stationery, snacks and other items. Java bags can hold different types of files.

Select SRC -> New -> PackageCopy the code

Enter the package name

Note: The package name is recommended in lower case, try not to use pinyin.

4.3 the new class

New -> Class
Copy the code

Enter the name of the class

Note: It is recommended to use words or phrases for class names. Capitalize all words.

4.4 Quickly generate the Main method

Type main -> simultaneously press Alt and / -> press EnterCopy the code

4.5 Quickly generate printing methods

In the main method -> type syso -> press Alt and / -> Enter simultaneouslyCopy the code

4.6 Generating set/ GET methods

Right-click -> source -> Generate Getters and Setters -> Select Properties -> GenerateCopy the code

4.7 Generating the constructor

Right-click -> source -> Generate Constructor using Fields -> Select Properties -> GenerateCopy the code

4.8 Installing and Configuring Tomcat

  • After we develop javaweb program, we need to access the browser through IP or domain name.
  • When users use a browser to access a website, they send HTTP requests and the Web server responds. So it’s up to the Web server to receive user requests and respond to user resources.
  • There are many Web servers, and Tomcat is one of the most used Web application servers worldwide.

4.8.1 install tomcat

  • Download decompression
Link: https://pan.baidu.com/s/1Ey-gg8tpHT9P-xNOUcrZmg extracted code: 1234Copy the code

  • Start tomcat

Go to the bin directory and double-click startup.sh

Open your browser and type:

http://localhost:8080/
Copy the code

When the following screen appears, you have successfully installed!!

4.8.2 Configuring Tomcat for Eclipse

Window -> Preference -> Server -> Runtime Environments
Copy the code

If the Servers folder appears, the configuration is successful!

4.9 Creating a JavaWeb Project

file -> New -> Dynamic Web Project
Copy the code

Next

Right-click WebContent and create index.jsp

Select index. JSP and right-click Run As Server

If the following occurs, the port is occupied.

Locate the local Tomcat installation directory

Double-click the shutdown. Sh

Select index. JSP and right-click Run As Server

Configuration successful!! Cow force!!!!!

Note: We can also set the browser to boot, Chrome is recommended

4.10 Importing projects

File -> Import -> General ->  Existing Projects into Workspace
Copy the code

5. Eclipse common shortcuts

No matter what software you are learning, I highly recommend that you focus on the shortcut keys of the software, because shortcut keys can save you time.

5.1 Formatting Code

Ctrl+Shift+F
Copy the code

5.2 annotations

Ctrl+/ comment the current line. Press again to uncomment multiple lines. Ctrl+ Shift +/ Comment multiple lines simultaneouslyCopy the code

5.3 Quick Repair/Automatic generation of return value objects

Ctrl+1 
Copy the code

For example, if the package path is missing in the student class below, select the line where the error occurred and press Ctrl+1

5.4 Deleting the current Row

Ctrl+D
Copy the code

5.5 Quickly Locating a Row

Ctrl+L enter the number of linesCopy the code

Now it’s in the third row

Press Ctrl+L at the same time to enter 5

5.6 Closing the Current File

Ctrl+W 
Copy the code

5.7 The selected text is in uppercase letters

Ctrl+Shift+X
Copy the code

5.8 All selected texts are in lower case

Ctrl+Shift+Y
Copy the code

5.9 Renaming Files

Alt+Shift+R 
F2
Copy the code

5.10 Extraction method

You can extract a bunch of seemingly messy code into a method

Alt+Shift+M
Copy the code

5.11 Search and Replace the current File

Ctrl+F 
Copy the code

5.12 Searching for Files globally

Ctrl+Shift+R
Copy the code

5.13 Displaying the inheritance structure of the current class

Ctrl+T 
Copy the code

5.14 Fast access to implementation class methods

Hold Ctrl and click on the method nameCopy the code

5.15 Quickly Import Classes or Delete Useless Classes

Ctrl+shift+O
Copy the code

5.16 Word completion

Alt+/
Copy the code

5.17 Quickly Locating to the End of a Line

Ctrl + end
Copy the code

5.18 Quickly Locating to the Start of a Line

Ctrl + home
Copy the code

5.19 Where is the method called

Ctrl+Shift+G
Copy the code

5.20 Quickly Locate a File in a Project

Next up: The use of IDEA

Wechat official account: Eclipse programming. Focus on programming technology sharing, adhere to lifelong learning.