Java common editor IntelliJ IDEA


IDEA overview

insert image description here

IntelliJ IDEA is an integrated development environment (IDE) developed by JetBrains for development in Java, Kotlin, Groovy, and other programming languages. It is one of the most popular and powerful Java IDEs and is widely used in the development of enterprise-level Java applications.

Here are some of the main features and capabilities of IntelliJ IDEA:

  1. Smart code editing: IntelliJ IDEA has powerful code editing features, including automatic code completion, refactoring, code navigation, syntax and error highlighting, code formatting, and more. It also supports smart code suggestions and bug fixing.

  2. Integrated debugger: IDEA integrates a powerful debugger that can be used to debug and track code execution during development. The debugger supports breakpoint setting, variable watching, expression evaluation, and stack traces.

  3. Version control system integration: IntelliJ IDEA supports common version control systems such as Git, SVN, and Mercurial. It provides an intuitive user interface for easy code version management, branch management, and team collaboration.

  4. Test tool support: IDEA integrates various test frameworks, such as JUnit, TestNG and Spock, which can easily write, run and manage unit tests and integration tests.

  5. Code quality tools: IDEA has many built-in code quality tools, including code inspection, duplicate code detection, code coverage analysis, etc. It helps developers improve the quality and maintainability of their code.

  6. Rich plug-in ecosystem: IntelliJ IDEA has an active plug-in library, which provides a large number of plug-ins and extension functions, which can extend the functions of IDEA according to the needs of developers, such as front-end development, database management, framework support, etc.

  7. Built-in development server and build tools: IntelliJ IDEA provides built-in application servers (such as Tomcat, Jetty, etc.) and build tools (such as Maven and Gradle), which can facilitate application development, testing and deployment.

IntelliJ IDEA is widely recognized and used for its excellent performance, feature richness and user-friendliness. It provides developers with a powerful and efficient working environment in Java projects, and it continuously introduces new features and improvements.

IDEA download and install

Here are the steps to download and install IntelliJ IDEA on Windows OS:

  1. Open the browser and visit the download page of JetBrains official website: https://www.jetbrains.com/idea/download/
    insert image description here

  2. On the download page, select the version for your operating system. Click the corresponding "Download" button to download.

  3. After the download is complete, double-click the downloaded installation file (usually ending with .exeor .dmg) to launch the installation wizard.

  4. Follow the instructions of the installation wizard to select the installation options and destination folder. By default, it is recommended to install with recommended settings.

  5. After completing the installation process, start IntelliJ IDEA. You may need to create or import a project, or simply use the initial interface to start working.

In addition, IntelliJ IDEA is a commercial software that provides a free Community Edition (Community Edition) and a paid Ultimate Edition (Ultimate Edition). You can choose the appropriate version to download and install according to your needs.

First code in IDEA

Here is a sample Java code created in IntelliJ IDEA:

public class HelloWorld {
    
    
    public static void main(String[] args) {
    
    
        System.out.println("Hello, World!");
    }
}

In IntelliJ IDEA, you can follow the steps below to create a new Java class and write code:

  1. Open IntelliJ IDEA and create a new project.
  2. In the project navigator, right-click on the source code folder (for example src/main/java), select "New" -> "Java Class".
  3. In the pop-up dialog box, enter the class name, for example HelloWorld, and click "OK".
  4. In the editor, copy and paste the above sample code into HelloWorld.javathe file.
  5. Click "Run" -> "Run 'HelloWorld.main()'", or use the shortcut key Ctrl+Shift+F10to run the program.

This code shows a simple Java application where mainmethod is the entry point of the program. In mainthe method, System.out.printlna "Hello, World!" message is printed out using print.

When you run this program, you will see "Hello, World!" output in IntelliJ IDEA's Run window.
insert image description here

IDEA's project and module operations

(1) Class operations

In IntelliJ IDEA, you can do the following to interact and manipulate classes:

  1. Create a class: In the project navigator, right-click the source code folder, select "New" -> "Java Class". Then enter the class name in the pop-up dialog box and click "OK" to create a new class file.

  2. Edit class: Open the class file in the editor, you can add, modify and delete the fields (properties), methods and constructors of the class, etc. Editing classes can be assisted with features such as code completion, refactoring, and formatting.

  3. Navigate to the class definition: If you want to view the class definition, you can put the cursor on the class name, then press the Ctrlkey and click the class name, IDEA will open the class definition.

  4. Navigate to where the class is used: If you want to view the usage of the class in the code, you can place the cursor on the class name, then press the key Ctrland click the class name, IDEA will display the place where the class is referenced.

  5. Refactoring classes: IDEA provides many refactoring operations that can help you modify the class structure, name, package path, etc. to improve code maintainability. For example, you can use "Refactor" -> "Rename" to modify the name of the class.

  6. Automatic code generation: IDEA can automatically generate some common code fragments, such as constructors, getter and setter methods, rewriting methods, etc. You can use shortcut keys Alt+Insert(Windows/Linux) or Command+N(Mac) to open the menu for generating code.

  7. Find a class: You can use "Find" -> "Class" to open the find class dialog box, and then enter the name of the class to find a specific class. You can use "Ctrl+N" (Windows/Linux) or Command+O(Mac) to quickly find a class.

  8. Delete a class: In the project navigator, right-click the class file to be deleted, select "Delete" and confirm the deletion. Note that deleting a class will permanently delete the class and its associated files from the project, so proceed with caution.

(2) Operation of the module

In IntelliJ IDEA, a module refers to an independent unit in a project, which can contain a set of related source code, resource files, and configuration files. Modules allow you to logically group code in your project and configure and manage it individually. Here are some common operations on modules in IntelliJ IDEA:

  1. Create a module: In the project navigation bar, right-click the project name, select "New" -> "Module", then select the type of module to be created (such as Java, Kotlin, etc.) and follow the wizard to complete the creation process.

    1. Right-click [Project Name], select [New]——click [Module...] to pop up a new module dialog box
    insert image description here2. Set the created module name, path, etc., and click the [Create] button after the setting is complete.
    insert image description here3. Created successfully Test module
    insert image description here

  2. Edit module: In the project navigator, right-click the module name, select "Open Module Settings", and then edit the module in the "Project Structure" dialog box. You can configure module dependencies, source code directories, output directories, resource files, and more.

    1. Right-click the [Test] module, click [Open Module Settings]
    insert image description here
    2. As shown in the figure below, you can set the module's dependencies, source code directory, output directory, etc.
    insert image description here

  3. Add/Remove Source Code Directories: In the "Project Structure" dialog, "Sources" tab, you can add or remove source code directories for modules. Click the "+" button to add a new source code directory, and click the "-" button to remove an existing source code directory.
    insert image description here
    insert image description here

  4. Add/Remove Dependencies: In the Dependencies tab of the Project Structure dialog, you can add or remove dependencies for a module. Click the "+" button to add new dependencies, such as additional modules, third-party libraries, etc.
    insert image description here

  5. Set the output path: In the "Paths" tab in the "Project Structure" dialog box, you can set the output path of the module. You can specify compile output directory and test output directory.
    insert image description here

  6. Adjust module order: In the "Modules" tab of the "Project Structure" dialog box, you can drag the order of modules up or down to adjust their relative order. The order of modules can affect compile and runtime behavior.

  7. Delete a module: In the "Modules" tab of the "Project Structure" dialog box, select the module to be deleted, and then click the "Remove" button to delete. Note that before removing a module, make sure it is no longer depended on by other modules or projects.

(3) Operation of the project

In IntelliJ IDEA, a project represents a complete software project, including multiple modules, source code, resource files, configuration files, etc. Here are some common operations on projects in IntelliJ IDEA:

  1. Create a project: Click "New Project" in the start interface or select "File" -> "New" -> "Project" to create a new project. Then follow the wizard to select the project type, project template, project name and save location, etc.

  2. Open project: Click "Open" in the start interface or select "File" -> "Open" to open an existing project. Then select the project folder and click "OK" to open the project.

  3. Navigate the project structure: In the project navigation bar, you can view and navigate the file structure of the project. It shows the modules, source code, resource files, configuration files, etc. in the project. You can expand and collapse folders to browse the project's file structure.

  4. Import external projects: If you have an existing project, you can choose "File" -> "New" -> "Project from Existing Sources" to import the project. Then follow the wizard to select the type of project (such as Java, Kotlin, etc.) and project folder.

  5. Close the project: Select "File" -> "Close Project" in the menu bar to close the currently open project. After closing the project, you can return to the initial interface of IDEA and wait to open other projects.

  6. Export project settings: If you want to export the project settings as a file, you can choose "File" -> "Export to Zip File" to export the current project settings. This makes it easy to share project settings or backup project configurations.

  7. Delete a project: In the project navigator, right-click on the project name, select "Delete" and confirm the deletion. Note that deleting a project permanently deletes the project from disk, so proceed with caution.

Guess you like

Origin blog.csdn.net/m0_62617719/article/details/131948022