IntelliJ IDEA 2023.1 for macOS to develop Java projects

image

1. Introduction to IntelliJ IDEA

1.1 Jetbrains company introduction

JetBrains is a global software provider that builds intelligent tools for software developers and their teams to increase productivity. The company is headquartered in Prague, Czech Republic, and has 12 offices worldwide. JetBrains currently employs more than 1,800 people and continues to grow without external financing. Its product catalog covers every stage of the software development cycle as well as major technologies, programming languages, and educational processes.

JetBrains official website https://www.jetbrains.com JetBrains Chinese official website https://www.jetbrains.com.cn

image

Jetbrains has released more than 34 products since its establishment and has more than 12.8 million users.

image

IDE for developers

image

  • IntelliJ IDEA — The leading Java and Kotlin IDE

  • PyCharm — Full-stack Python IDE

  • PhpStorm — Efficient and intelligent PHP IDE

  • RubyMine — Smart Ruby and Rails IDE

  • WebStorm — the smartest JavaScript IDE

  • AppCode — a smart IDE for iOS/macOS development

  • CLion — Cross-platform C/C++ IDE

  • DataGrip — SQL IDE

  • GoLand — Cross-platform Go IDE

  • Rider — Cross-platform .NET IDE

  • DataSpell — IDE for data science

  • Fleet — the next generation IDE built by JetBrains

  • Aqua — a powerful test automation IDE

No matter which platform or language you use, JetBrains has the right development tools.

  • Code With Me — real-time collaborative development

  • Toolbox App — Control panel for tools and projects

Languages ​​and frameworks for developers

  • Kotlin — modern, clean, secure programming language

  • Ktor — An asynchronous framework for creating microservices, web applications, and more

  • Compose Multiplatform — Kotlin declarative multi-platform UI framework

  • MPS — create your own domain-specific language

Team oriented

image

  • Space — a complete software development platform

  • TeamCity — powerful continuous integration out of the box

  • Upsource — code review, project analysis

  • Datalore — a collaborative data science platform for teams

  • YouTrack — Powerful project management for all teams

  • Hub — YouTrack and TeamCity connector

  • Qodana — Your favorite code quality platform for CI

1.2 Introduction to IntelliJ IDEA

IntelliJ IDEA is the leading IDE for Java and Kotlin development. It has a suite of features that help increase productivity, including smart coding assistance, reliable refactoring, instant code navigation, built-in developer tools, web and enterprise development support, and more.

image

1.2.1 Latest changes in IntelliJ IDEA

I want to know what changes have taken place in the latest version of IntelliJ IDEA, and what new functions and features have been added. Then you can access the latest changes in IntelliJ IDEA

In IntelliJ IDEA 2023.1, we have made a lot of improvements to the new UI based on valuable feedback from users. We've also implemented performance enhancements to import Maven faster and provide IDE functionality earlier when a project is opened. The new version provides a streamlined submission process with background submission checking. IntelliJ IDEA Ultimate now supports navigation of Spring Security matchers and request maps.

image

1.2.2 IntelliJ IDEA functions

Want to know the following main functions of IntelliJ IDEA

  • Developer Ergonomics

  • Deeper code insights

  • Quick navigation and search

  • Run, test and debug

  • Built-in tools and integrations

  • version control

  • JVM framework

  • Web development

  • deploy

  • Remote development and collaboration

Then you can access IntelliJ IDEA functionality

image

1.2.3 IntelliJ IDEA resources

IntelliJ IDEA resources provide a rich knowledge base, videos, blogs, documents and some commonly used quick access

image

  • The knowledge base provides information on getting started, creating Java applications, mastering shortcut keys, managing plug-ins, integrating with Git, studying editor basics, migrating from Eclipse and migrating from NetBeans. These contents actually come from IntelliJ IDEA Help

  • The video provides tips for using IntelliJ IDEA

  • Quick access allows you to jump to shortcut keys, IntelliJ IDEA help , plug-in market , and community forums

1.2.4 IntelliJ IDEA shortcut keys

If you want to use IntelliJ IDEA efficiently, you must master the IntelliJ IDEA shortcut keys

Since the keyboard layouts of Windows, Linux, and macOS are different , their shortcut keys are also different.

IntelliJ IDEA shortcut keys for Windows and Linux

image

IntelliJ IDEA shortcut keys for macOS

image

1.2.5 IntelliJ IDEA plug-in market

In addition to many built-in plug-ins, IntelliJ IDEA also supports a large number of third-party plug-ins, and most plug-ins are free to use.

Search for the desired plug-in in the IntelliJ IDEA plug-in market, download it, install it and use it.

image

1.2.6 IntelliJ IDEA Help

If you have any problems in the process of using IntelliJ IDEA, you can visit IntelliJ IDEA Help to solve it. It is a detailed manual about IntelliJ IDEA officially provided by Jetbrains , which is better than any book about IntelliJ IDEA on the market .

image

In the help of IntelliJ IDEA, functions about all aspects of IntelliJ IDEA are provided, such as installation, uninstallation, configuration, project configuration, operation, debugging, deployment, testing, analysis, version control, remote development, integration tools and other languages, Framework, platform support and usage.

2. Installation and uninstallation of IntelliJ IDEA 2023.1 for macOS

2.1 IntelliJ IDEA 2023.1 download for macOS

  1. Visit IntelliJ IDEA official website

image

  1. Click Download to jump to the download page

image

IntelliJ IDEA download address https://www.jetbrains.com/idea/download

At this time, the corresponding version of IntelliJ IDEA will be selected based on the version of the operating system currently used.

IntelliJ IDEA supports mainstream desktop operating systems, including Windows, macOS, and Linux (Ubuntu)

Since you are currently using macOS, the macOS version of IntelliJ IDEA is selected by default.

However, it should be noted that the Intel chip version is selected by default when clicking Download at this time . If your Apple computer uses an Intel chip, you can use this version.

image

If your mac computer uses an ARM architecture chip, such as M1 Max, M2 Max, etc., then you need to choose to download the Apple Silicon version

image

  • System requirements lists the requirements for using IntelliJ IDEA

image

However, I suggest that if you use IntelliJ IDEA for Java project development, then refer to the following configuration

  1. The latest stable version of macOS system, such as macOS Ventura

  2. M1 Max and above CPUs, such as M1 Max, M2 Max

  3. 64GB and above memory

  4. 2TB and above SSD

  • Other versions can download other versions, such as 2022.3.3 and so on

image

  1. Download IntelliJ IDEA Ultimate

Normally, Jetbrains releases three major versions of IntelliJ IDEA every year . For example, 2023 will be Intellij IDEA 2023.1, Intellij IDEA 2023.2, and Intellij IDEA 2023.3.

IntelliJ IDEA is divided into two versions: IntelliJ IDEA Ultimate and IntelliJ IDEA Community Edition

Each major version of IntelliJ IDEA Ultimate can be tried for free for 30 days, and payment is required after 30 days.

IntelliJ IDEA Community Edition can be used permanently for free, but its functions are relatively simple , so we will use IntelliJ IDEA Ultimate when developing projects in the company

image

Since my MacBook Pro uses the M1 Max CPU, you can click on the Apple menu in the upper left corner > About This Mac to view

image

Therefore it is also necessary

①Click .dmg △

②Click .dmg(Apple Silicon)

image

When you click .dmg (Apple Silicon), the browser will automatically start downloading the ARM chip version of IntelliJ IDEA

image

After the download is successful, you can see ideaIU-2023.1.3-aarch64.dmg in the download directory (/Users/liuguanglei/Downloads)

image

2.2 Installation of IntelliJ IDEA 2023.1 for macOS

  1. Double-click ideaIU-2023.1.3-aarch64.dmg

image

  1. Drag IntelliJ IDEA.app to the Applications folder

The Applications folder is the Finder application folder

image

The dragging process takes about 5 seconds

image

After dragging successfully, IntelliJ IDEA can be found in the application folder of Finder.

image

IntelliJ IDEA can also be found in the Launchpad

image

  1. Launch IntelliJ IDEA. Select IntelliJ IDEA on the desktop, right-click and select launch. You can also use the shortcut Command+E to launch it.

image

  1. Put IntelliJ IDEA into the Dock. In order to start IntelliJ IDEA in the Dock more conveniently, it is recommended to drag IntelliJ IDEA from the launch pad to the Dock.

image

In this way, you can start IntelliJ IDEA by clicking on it in the dock.

image

2.3 macOS version IntelliJ IDEA 2023.1 first use

Since IntelliJ IDEA requires a license before it can be used for the first time , here is how to get a free 30-day trial by registering and logging into your Jetbrains account.

  1. Start IntelliJ IDEA

Double-click the IntelliJ IDEA shortcut in the Dock to start it

image

When starting up for the first time, the system will prompt that IntelliJ IDEA is an App downloaded from the Internet. Are you sure you want to open it? We can click to open it here .

image

  1. Agree to the User License Agreement

If you have already agreed to the user agreement when installing IntelliJ IDEA, you do not need to agree to the user agreement even after uninstalling and reinstalling IntelliJ IDEA. However, if it is the first installation of a new system, you can only see Agree to the User Agreement. In the window, check I confirm that I have read and accept the terms of this User Agreement and click Continue.

image

  1. data sharing
  • If you do not want to share data, click Don't Send

  • To share data, click Send Anonymous Statistics

I won't share data here, so click Don't Send

image

  1. Get License

There are two ways for IntelliJ IDEA to obtain a License.

image

The first is to click Activate IntelliJ IDEA

When you click Activate IntelliJ IDEA has 3 ways to obtain the License

Method 1: Obtain License from Jetbrains account

image

This method requires registration and login to Jetbrains account

image

Method 2: Fill in the Activation Code to obtain the license

image

Method 3: Fill in the License Server to obtain the license

image

Click Buy license to jump to the address for purchasing the IntelliJ IDEA license . If conditions permit, it is recommended that you support the genuine version.

image

The second way is to click Start trial

image

We choose the second method here, click Start trial, and try it for free for 30 days after registering and logging in to your Jetbrains account.

①Select Start trial

② Click Register… to register a Jetbrains account

image

Then open the Jetbrains Account page in IntelliJ IDEA

① Fill in your email address

② Click Sign Up

image

Jetbrains will then prompt to thank you for registering your JetBrains account! Please follow the instructions we just emailed you

image

Then log in to the email client (such as Netease Mailbox Master ), check the Complete your account registration email sent to you by Jetbrains, and click Confirm your account to jump to the registration page

image

After filling in the account information on the registration page, click Submit to submit.

image

After successful registration, JetBrains Account will jump to the license page.

image

Now return to IntelliJ IDEA Licenses and click Log in to Jetbrains Account... Log in to Jetbrains account

image

Then fill in the account information on the Jetbrains Account page and click Sign In to log in to the Jetbrains account.

image

After successful login, the page will prompt that the authorization is successful. You can close this page and return to the IDE.

image

And IntelliJ IDEA will automatically log in to the account you just registered.

image

Then click Start Trial to start the trial

image

In this way, you can see the license information of IntelliJ IDEA in the Licenses window, which can be used until August 3, 2023, which is a one-month trial.

image

Then click Continue to close the Licenses window.

image

You can see the IntelliJ IDEA welcome window, which means you can use IntelliJ IDEA to develop Java projects.

image

2.4 Uninstalling IntelliJ IDEA 2023.1 for macOS

2.4.1 Instructions for uninstalling IntelliJ IDEA 2023.1 on macOS

Q: When do I need to uninstall IntelliJ IDEA?

A: ① Uninstall the old version of IntelliJ IDEA before using the new version of IntelliJ IDEA ② Uninstall IntelliJ IDEA when you no longer use IntelliJ IDEA

Required to uninstall IntelliJ IDEA

  1. Uninstall IntelliJ IDEA application

  2. Delete the specified directory

2.4.2 Uninstall the IntelliJ IDEA application

  1. Remove IntelliJ IDEA to the Trash Open Finder , then select the application folder, find IntelliJ IDEA, right-click and select Move to Trash

image

It should be noted that IntelliJ IDEA needs to be closed before removing it to the trash. Click the x in the upper left corner to close it or use the shortcut key Command+Q to close it.

image

Otherwise you will see that the project "IntelliJ IDEA.app" cannot be moved to the Trash because it is already open.

image

  1. Empty the Trash Open the Trash in the Dock

image

Then right click to empty the Trash

image

Empty the trash

image

Trash has been emptied

image

2.4.3 Delete the specified directory

~/Library/Application Support/JetBrains/IntelliJIdea2023.1
~/Library/Caches/JetBrains/IntelliJIdea2023.1

~ represents the home directory, such as /Users/liuguanglei, where liuguanglei is the user name. The user names of different Mac computers are different.

So how to delete these two directories?

We can delete it through the finder or delete it through the rm command. Use Finder to delete it here

  1. Delete the ~/Library/Application Support/JetBrains/IntelliJIdea2023.1 directory

After opening the Finder, click Go->Go to Folder. The shortcut key to go to the folder is Shift+Command+G.

image

Then enter ~/Library/Application Support/JetBrains and press Enter

image

image

Then select IntelliJ IDEA 2023.1, right-click and remove to the trash

image

IntelliJ IDEA 2023.1 of ~/Library/Application Support/JetBrains has been removed to the trash

image

  1. Delete the ~/Library/Caches/JetBrains/IntelliJIdea2023.1 directory

After opening the Finder, click Go->Go to Folder. The shortcut key to go to the folder is Shift+Command+G.

image

Then enter ~/Library/Caches/JetBrains and press Enter

image

image

Then select IntelliJ IDEA 2023.1, right-click and remove to the trash

image

IntelliJ IDEA 2023.1 of ~/Library/Caches/JetBrains has been removed to the trash

image

  1. Empty the trash

Open the Trash in the Dock

image

image

Then right click to empty the Trash

image

Empty the wastebasket

image

image

3. IntelliJ IDEA 2023.1 settings for macOS

3.1 IntelliJ IDEA 2023.1 setup instructions for macOS

Before using IntelliJ IDEA to develop a project, you need to make some settings. After completing these settings, the project development will be smoother.

IntelliJ IDEA related settings are all done in the settings window , so you first need to know how to open the settings window

First start IntelliJ IDEA

Left-click IntelliJ IDEA in the Dock to start IntelliJ IDEA

image

After opening, you can see the welcome window of IntelliJ IDEA

image

Then click Customize>All settings…

image

You can open the settings window of IntelliJ IDEA and complete the settings of IntelliJ IDEA in this window.

image

Since IntelliJ IDEA provides a lot of settings, such as appearance and behavior, shortcut keys, editors, plug-ins, version control, etc., a search function is provided to search for settings. It is recommended that you search for relevant setting items in the search box when making relevant settings.

image

There are a few more things to note:

  1. If you want to cancel the modification, click Cancel in the lower right corner, and the settings window will close.

  2. After making most of the settings, click Apply in the lower right corner and the settings will take effect immediately.

  3. After all settings are completed, click OK in the lower right corner to close the settings window.

image

3.2 Appearance and behavior settings

3.2.1 Appearance settings

3.2.1.1 Theme settings

IntelliJ IDEA default theme selection Darcula

image

You can switch to other themes according to your preferences, such as IntelliJ Light

image

However, it should be noted that if you enable the new UI of IntelliJ IDEA, the Darcula theme will be replaced by the Dark theme.

image

3.2.1.2 Appearance font settings

The default appearance of IntelliJ IDEA uses the .AppleSystemUIFont font with a font size of 13

image

If it doesn't feel right, you can customize the font and font size

I changed the appearance font size from the default 13 to 16

image

After making changes, it is recommended to reopen the settings window.

image

3.2.2 New UI settings

After IntelliJ IDEA 2022.3, a new UI is provided. For a detailed introduction to the new UI, you can visit the official website of IntelliJ IDEA

image

However, IntelliJ IDEA has not started the new UI by default because it is still in the Beta version, which is not a stable version.

image

If you want to try the new UI, then check Enable new UI and check the need to restart IntelliJ IDEA

image

IntelliJ IDEA welcome interface after enabling the new UI

image

Although the UI has changed, the menu name has not changed, so you can still click Customize>All settings…

image

Enter the settings window

image

Compared with the previous UI, the new UI will be simpler, more beautiful, and more efficient to operate. In the future, IntelliJ IDEA will also enable the new UI by default, so we will use the new UI throughout the process from now on.

image

3.2.3 System settings

3.2.3.1 Reopen project settings on startup

By default, IntelliJ IDEA reopens the project when it starts , that is, it directly opens the recently closed project after starting IntelliJ IDEA.

image

Usually, when a company does Java development, multiple projects may be developed at the same time , so it is recommended to uncheck Reopen projects on startup.

image

In this way, if there are multiple projects after starting IntelliJ IDEA, you can select the specified project and then open IntelliJ IDEA

image

3.2.3.2 IntelliJ IDEA update settings

IntelliJ IDEA checks for updates to IntelliJ IDEA and related plug-ins by default

image

If you do not want to update IntelliJ IDEA or are currently using a stable version , it is recommended to uncheck Check IDE update for Stable Relases and just keep checking for plug-in updates.

image

3.3 Editor settings

3.3.1 Editor general settings

IntelliJ IDEA editor is not enabled by default to use Ctrl+mouse wheel to adjust font size

image

It is recommended to enable the use of Ctrl+mouse wheel to adjust the font size, so that when writing code, you can hold down the Ctrl key and scroll the mouse to change the font size at any time. However, this change only takes effect temporarily for the content currently being edited, and the modification will become invalid after restarting IntelliJ IDEA .

image

3.3.3.1 Automatically import settings

IntelliJ IDEA automatic import settings are not enabled by default to dynamically add explicit import statements and dynamically optimize import statements.

image

When writing a Java program, by default, if you are using a Java class other than the java.lang package, you need to manually import the package (that is, write an import statement)

In order to develop more efficiently, it is usually recommended to enable dynamic addition of explicit import statements and dynamic optimization of import statements .

image

However, if there are classes with the same name in different packages (for example, Date is in java.sql and java.util), then you need to manually select the specified package.

3.3.3.2 Appearance settings

By default, IntelliJ IDEA does not enable the separator between display methods

image

Because we will write many methods in the same class later when writing Java code, in order to make it easier to read the code (to distinguish the method where the code is located), it is recommended to enable the display of separators between methods, that is, between multiple methods add a horizontal line

image

3.3.3.3 Code completion

Code completion will be performed when using the IntelliJ IDEA editor to write code. For example, if you enter Sy, System will be completed. However, if you enter sy, it will not be completed as System because by default code completion is case-sensitive.

image

In daily development, it is recommended that code completion is not case-sensitive . Uncheck Match case so that the code can be completed without case-sensitivity. For example, entering sy will complete System

image

3.3.3.4 Console settings

The default console buffer size is 1024KB

image

It is recommended to change the buffer size of the console to 10240KB so that you can see more console output during later development projects.

image

3.3.3.5 Editor tab settings

By default, the editor displays tabs in a row . If there are many open files, some file tabs will be hidden.

image

It is recommended to display tabs on multiple lines so that all tabs can be seen in the editor

image

3.3.2 Editor font settings

The default font of the IntelliJ IDEA editor is JetBrains Mono, and the font size is 13

image

The smaller the font size, the more code you can see in the editor, but it takes more effort on your eyes.

Therefore, I changed the font size from the default 13 to 18. After the modification is completed, you can preview the effect on the right

image

3.3.3 Editor color scheme

IntelliJ IDEA's default font color for single-line comments and multi-line comments is gray, and its color value is hexadecimal 7A7E85

You can view it by selecting Line comment and Block comment of Comments in Editor>Color Scheme>Language Defaults.

Line comment

image

Block comment

image

However, the document comment color in IntelliJ IDEA 2023.1 is green , and the color value of the multi-line comment text content is hexadecimal 5F826B

image

It is recommended to change the color value of the comment content of single-line comments and multi-line comments to the same color as the content of multi-line comments, which is 5F826B in hexadecimal . Of course, you can also choose the color you like.

Change the font color of single-line comments to green

image

Change the font color of multi-line comments to green

image

When you write code later, you will see that the color of the contents of the three types of comments (single-line comments, multi-line comments, and document comments) in the program are all green.

image

3.3.4 File and code template settings

3.3.4.1 File header settings

By default, the file header configuration content of files and code templates is empty

image

We can add the following document comment content

/**
* ${description}
* @author tony [email protected]
* @version  ${DATE} ${TIME}
* @since  Java17
*/

image

  • ${description} is used to describe the role of the class

  • @author The author's email is used to describe the author and email of the class

  • @version ${DATE} ${TIME} uses the current date and time as the version number to describe the version of the class

  • @since Java17 project uses Java17 JDK used to describe project dependencies

This documentation comment will be used later when creating Class, Interface, Enum, and Record.

Because file headers are used in Class, Interface, Enum, and Record file templates

image

image

image

image

For example, my first Java program used documentation comments for class headers

image

3.3.5 Editor file encoding settings

Default editor file encoding settings

image

The default encoding of the properties file should be adjusted to UTF-8, and check the box to automatically convert to Ascii but display native content.

image

3.4 Build, Execution, and Deployment Settings

3.4.1 Compiler settings

When using IntelliJ IDEA to develop Java projects, it is recommended to enable automatic project building and parallel compilation of independent modules.

image

Automatically building projects only works when not running/debugging. Parallel compilation of independent modules requires larger heap memory, so the default 700M is adjusted to 4096M, which will be used if multi -module projects are developed in the future.

image

3.5 Advanced settings

3.5.1 User interface settings

When we write code, we often use shift to switch between Chinese and English, and this easily triggers double-clicking shift to open the search box of IntelliJ IDEA . This search box can search for any content, so it is recommended to disable double-clicking shift to open the search box .

image

So what do you do if you want to search for any content?

You can use Command+O to open the search box search class of IntelliJ IDEA. Click All to search for any content in the search box.

image

You can use Shift+Command+O to open the search box of IntelliJ IDEA to search for files. Click All to search for any content in the search box.

image

After all settings are completed, click OK to close the window.

image

Click x or use the shortcut Commnad+Q to close IntelliJ IDEA

image

3.6 IntelliJ IDEA JVM settings

IntelliJ IDEA runs on the JVM. We can modify the JVM options to adjust the performance of IntellliJ IDEA. The IntelliJ IDEA help document also provides detailed configuration methods https://www.jetbrains.com/help/idea/tuning-the- ide.html#configure-jvm-options

image

First enter the bin directory/Applications/IntelliJ IDEA.app/Contents/bin of the IntelliJ IDEA installation directory

image

Then modify the idea.vmoptions file, which can be opened using a text editor (such as Visual Studio Code)

image

image

Visual Studio Code opens the idea.vmoptions file

image

It is strongly recommended to back up before modifying . The purpose is to prevent IntelliJ IDEA from being unable to start due to modifying the file and restore it to the backup.

-Xms128m
-Xmx750m
-XX:ReservedCodeCacheSize=512m
-XX:+UseG1GC
-XX:SoftRefLRUPolicyMSPerMB=50
-XX:CICompilerCount=2
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-XX:+IgnoreUnrecognizedVMOptions
-XX:CompileCommand=exclude,com/intellij/openapi/vfs/impl/FilePartNodeRoot,trieDescend
-ea
-Dsun.io.useCanonCaches=false
-Dsun.java2d.metal=true
-Djbr.catch.SIGABRT=true
-Djdk.http.auth.tunneling.disabledSchemes=""
-Djdk.attach.allowAttachSelf=true
-Djdk.module.illegalAccess.silent=true
-Dkotlinx.coroutines.debug=off

If your computer has more than 32G of memory, you can refer to the following configuration

Modify the following parameters

  • -Xms1024m

  • -Xmx3000m

  • -XX:ReservedCodeCacheSize=2048m

  • -XX:SoftRefLRUPolicyMSPerMB=200

  • -XX:CICompilerCount=8

    -Xms1024m
    -Xmx3000m
    -XX:ReservedCodeCacheSize=2048m
    -XX:+UseG1GC
    -XX:SoftRefLRUPolicyMSPerMB=200
    -XX:CICompilerCount=8
    -XX:+HeapDumpOnOutOfMemoryError
    -XX:-OmitStackTraceInFastThrow
    -XX:+IgnoreUnrecognizedVMOptions
    -XX:CompileCommand=exclude,com/intellij/openapi/vfs/impl/FilePartNodeRoot,trieDescend
    -ea
    -Dsun.io.useCanonCaches=false
    -Dsun.java2d.metal=true
    -Djbr.catch.SIGABRT=true
    -Djdk.http.auth.tunneling.disabledSchemes=“”
    -Djdk.attach.allowAttachSelf=true
    -Djdk.module.illegalAccess.silent=true
    -Dkotlinx.coroutines.debug=off

Remember to restart IntelliJ IDEA after the modification to test whether it can be opened normally

image

Later, when developing large-scale projects, you will find that after adjusting the JVM Options, it becomes smoother and silkier than the default configuration.

4. Develop Java projects with IntelliJ IDEA 2023.1 for Windows

4.1 Process of developing Java projects with IntelliJ IDEA

  1. Create a new project (Project)

  2. Create a new module (Module)

  3. Create a new package

  4. Create a new class

  5. Run and debug Java programs

About the relationship between projects, modules, packages and classes

  • A project (Project) can contain multiple modules (Module)

  • A module (Module) can contain multiple packages (Package)

  • A package (Package) can contain multiple classes (Class)

image

This is similar to a school having multiple grades, a grade having multiple classes, and a class having multiple students.

4.2 IntelliJ IDEA new project

  1. Start IntelliJ IDEA

Click IntelliJ IDEA on the Dock bar to start IntelliJ IDEA

image

IntelliJ IDEA started successfully

image

  1. New Project

Click Projects->New Project to create a project

  • New Project Create a new project

  • Open Open an existing project

  • Get from VCS Get the project from the version control system

image

  1. Set the project type, project name and project path in sequence. Set the project type to Empty Project, set the project name to java, and set the project path to ~/Documents/projects/java/ittimeline. Please note that the project path does not contain Chinese characters and spaces .

image

After the settings are completed, click Create to create the project.

image

Project created successfully

image

  1. set items

First click IDE and Project Settings in the upper right corner, and then click Project Structure to open the project settings. The shortcut key is Command+;

image

The project structure is divided into project settings (Project Settings) and platform settings (Platform Settings)

image

Project name, SDK (Software Development Kit), language level and compiler output directory can be set in Project Settings

  • The project name is java

  • Project SDK no selection

  • Language level is 20

  • The compilation output directory is ~/Documents/projects/java/ittimeline/java/out, which is used to store bytecode files.

image

Here we set the project SDK to Java8, and the language level to 8. Usually, the version of the SDK and the language level are consistent.

It should be noted that the module will use the default settings of the project, that is, the SDK after the new module is also Java8, and the language level is 8

image

When creating a Project, IntelliJ IDEA will also automatically create a Module with the same name.

image

In the SDKs of Platform Settings, IntelliJ IDEA automatically reads the locally installed Java17 and Java8, but the prerequisite is that the local environment has installed Java17 and third-party Java8.

image

If you want to integrate other versions of SDK, just click the plus sign (+)->Add JDK

image

Then select the installation directory of other versions of JDK and click open

image

Finally click Apply

image

In this way, three different versions of JDK of Java8, Java11 and Java17 are integrated in IntelliJ IDEA

image

After the project setting is complete, click OK to close the project setting window

image

4.3 IntelliJ IDEA new module

  1. New Module

Select the java project, then right-click New Module

image

  1. Setup module

Set module name, module path, language, build system, JDK new module default settings

Since the SDK was set to Java8 in the project settings before, when creating a new module, the JDK defaults to Project SDK1.8

image

The module settings are as follows

image

  • Module name: java-core

  • Module path: ~/Documents/projects/java/ittimeline/java

  • Language:Java

  • Build system: IntelliJ

  • JDK:Java17

  • Uncheck Add sample code

After the module is set up, click Create to create the module.

image

After creating the module, IntelliJ IDEA will create an index for Java17, so that the search efficiency can be improved when searching for the API provided by Java17 in the future. We need to wait for the index creation to be completed before performing other operations.

image

image

The java-core module was created successfully

image

  1. Module settings

First click IDE and Project Settings in the upper right corner, and then click Project Structure to open the project settings. The shortcut key is Command+;

image

In the Modules of Project Settings, you can see that the Language Level of javac-core inherits the Language Level of Project, which is Java8

image

Since the new features of Java17 will be used later, it will be changed to Java17

image

After the module settings are completed, click OK to close the project settings window.

image

4.4 IntelliJ IDEA new package

  1. New Pacakge

Select the src directory of the java-core module and right-click New Package

image

  1. Set the package name, enter net.ittimeline.java.core.foundational.object and press Enter

image

Why should it be set to net.ittimeline.java.core.foundational.object? In fact, it has a special meaning

The Java development specifications stipulate that package names must be lowercase English words, and use . to separate multiple words.

  • net.ittimeline represents the inversion of the ittimeline.net domain name. If you develop a Taobao project, the package name is com.taobao

  • java.core represents the java language, which stores Java language-related code, such as basic syntax, object-oriented, collections, concurrency, and network-related APIs.

  • foundational means java basic syntax, which is to store the content of java basic syntax, such as variables, data types, operators, program flow control, arrays

  • object indicates that the object is to store the first Java program

Package created successfully

image

What exactly is a bag?

We can open the package in Finder

image

Then you will see its essence, which is actually a folder that stores Java source files with different functions.

image

4.5 IntelliJ IDEA new class

  1. New Class

Select the net.ittimeline.java.core.foundational.object package and right-click New Java Class

image

  1. To set the class name, enter HelloWorld and press Enter. It should be noted that you select Class. As for Interface, Record, Enum, and Annotation, you will learn about it later.

image

Then enter the description and click OK after entering to create the HelloWorld class.

image

HelloWorld class created successfully

image

And IntelliJ IDEA also helps us write the following code

package net.ittimeline.java.core.foundational.object;

/**
 * 我的第一个Java程序
 *
 * @author tony [email protected]
 * @version 2023/7/6 16:07
 * @since Java17
 */
public class HelloWorld {
}
  • package net.ittimeline.java.core.foundational.object; defines the package (that is, the folder) where the HelloWorld class is located

  • public class HelloWorld {} is to define the public class HelloWorld

The content of the documentation comment was previously configured in the file header of the file and code template.

image

  1. Writing HelloWorld

    package net.ittimeline.java.core.foundational.object;

    /**

    • My first Java program
    • @author tony [email protected]
    • @version 2023/7/6 16:07
    • @since Java17
      */
      public class HelloWorld {
      public static void main(String[] args) {
      System.out.println(“macOS & Java17 & IntelliJ IDEA 2023”);
      }
      }

However, writing Java code in IntelliJ IDEA will be more efficient than Notepad

  • Enter psvm or main and press Enter to generate the main method.

  • Enter soout to generate a print statement

This is the Live Templates function provided by IntelliJ IDEA. You can view it in the Live Templates of the IntelliJ IDEA settings window. First click on IDE and Project Settings in the upper right corner, then click Settings. The shortcut key is Command+,

image

You can open the settings window

image

Then search for Live Templates in the settings window and select Live Templates for Java

image

When you see Java's psvm Live Template, you will know why entering psvm can generate the main method.

image

When you see Java's sout Live Template, you will know why typing soout can generate the print statement System.out.println();

image

As for other Live Templates, we will use them later when learning other content.

4.6 IntelliJ IDEA runs Java programs

IntelliJ IDEA has four ways to run Java programs, of which method 4 is the most commonly used because the position is always fixed.

Method 1: Right-click in the editing area and select Run. The shortcut key is Control+Shift+R.

image

Method 2: Click the Rerun button in the run window to run

image

Method 3: Click the triangle button on the left side of the main method

image

Then select Run

image

Method 4: Click the triangle button of the Toolbar to run

image

No matter which way you run it, you will see the same running result in the Run window, which is to print out macOS & Java17 & IntelliJ IDEA 2023 and wrap it in a new line.

image

4.7 IntelliJ IDEA project structure

This is our java project structure so far

image

  • Java project name storage Learn Java from novice to architect 's project code, documents, etc. with Guanglei

    • The .idea folder stores project configurations, such as project version control configuration, project module configuration, etc. This directory is created by IntelliJ IDEA. We generally do not modify the contents of files in this directory.

    • The java-core module name stores content related to the Java language, such as Java's basic syntax, object-oriented, advanced API, etc.

      • src stores Java source files , resource files (html, css, js), and configuration files (application.yml)

        • The package name net.ittimeline.java.core stores source files related to the Java language.

        • .gitignore git ignores files. If some files and directories do not want to be submitted to the Git repository, you can configure it in this file.

      • java-core.iml module configuration file, each module will have a module configuration file, generally we will not modify it, this file is created by IntelliJ IDEA

    • out store the bytecode file and configuration file output by project compilation

    • java.iml module configuration file, each module will have a module configuration file, generally we will not modify it, this file is created by IntelliJ IDEA

  • External Libraries stores the class libraries that the project depends on, currently only depends on Java17

Guess you like

Origin blog.csdn.net/Tony_CTO/article/details/131987722