如何安装、使用IntelliJ IDEA?

If you have successfully installed Intellij IDEA on your computer, it's time to run it for the first time. You will see the Welcome Screen which gives you main entry points to the IDE. Here you can create a new project, open an existing one, or check out the project from version control.

Run Your First Java Application

Let's create a simple Java Hello World project. Click Create new project . The New Project Wizard opens.

The main thing you should pay attention to is the Project SDK. SDK (Software Development Kit) is a set of software development tools that lets you develop applications. IntelliJ IDEA does not include an SDK, so If you have none, download and install it. Since we make a Java project, we need a Java SDK (JDK). After installation, click Newand point to the installation folder of the JDK.

In the New Project Wizard, you can choose technologies your project will support, but as you're making a plain Java Application, select none of them and just click Next. Then IDE offers you to create project from a template. We don't need this now, so clickNext .

Specify the name and location of the project. Click Finish .

You have src folder inside your project. This is the folder for your source code. Right click on this folder, then choose New | Java Class .

Enter the name of this class, say, quickstart.HelloWorld, and clickFinish .

输入类名,如quickstart.HelloWorld,然后点击Finish。

Now the new class opens in the editor. Notice, that HelloWorld class is created in quickstart package. HelloWorld program text is a known one.

packagequickstart;publicclassHelloWorld{publicstaticvoidmain(String[]args){System.out.println("Hello, World!");}}

Put it inside the class.

Every time you run an application, you need to have a configuration, which this process is based on. For creating a run configuration click Run | Edit configurations' Then click add.png and choose Application .

Here you can specify the main class and program arguments. Since we have a simple application, we need to point the Main class only. Put quickstart.HelloWorld into the Main class text field. Print something in Name field, for example, HelloWorldConfig . Run configuration is ready.

Now you can immediately run your application and make sure all works properly. Choose Run | Run 'HelloWorldConfig' from the main menu. Get a result!

For debugging your application, choose Run | Debug. You should also have Run Configuration for this. To learn more, see Run/Debug Configuration: Application.

Look Around

Let's have a closer look on the main window of IntelliJ IDEA. There are several logical areas:

  1. Menus and toolbars contain commands that affect the entire project or large portions of it. Additionally, context-sensitive pop-up menus let you perform the commands, which are specific to a part of a project, like source file, class, etc.
  2. Navigation bar helps navigate through the project and open files for editing.
  3. The status bar indicates the status of your project, the entire IDE, and shows various warning and information messages.
  4. The editor where you create and modify the code.
  5. Tool windows perform different functions: help you explore and navigate through the projects and file structures, view search and inspection results, run, debug and test applications, work in interactive consoles, and more.
  6. Left gutter —the vertical stripe which shows the breakpoints you have, and provides a convenient way to navigate through the code hierarchy like going to definition/declaration. It also shows line numbers and per-line VCS history.
  7. Right gutter —this stripe constantly monitors the quality of your code and always shows the results of its code analysis: errors, warnings, etc. The square in the top right-hand corner shows the overall status of code analysis for the whole file.

Smart Coding

IntelliJ IDEA has a powerful editor and always helps you creating error-free applications. There are many smart features in IDE, let’s have a look on the most important ones.

Code completion

Code completion takes into account the current context and saves your time. There are two main types of code completion in IntelliJ IDEA: basic (Ctrl+Space) and smart (Ctrl+Shift+Space). Basic completion works as you type and completes any name instantly. Smart completion analyzes the context you’re currently working in and offers more accurate suggestions based on that analysis. It filters the list of functions and variables to match the expression type.

Intention actions

When a possible problem is suspected, IntelliJ IDEA suggests a solution, and in certain cases can implement this solution (properly assign variables, create missing references and more). Besides syntax problems, IntelliJ IDEA recognizes code constructs that can be optimized or improved, and suggests appropriate intention actions, denoted with the special icons. If you want to know exactly what IDE suggest you in current situation, click the light bulb, or press Alt+Enter.

Refactoring

IntelliJ IDEA provides a huge set of automated code refactorings from mere renaming to such complicated things as changing a method signature.

Project Configuration in a Nutshell

In Intellij IDEA all exists in the context of a Project, the highest level of organization in the IDE. To specify the configuration of your project choose File | Project Structure

Here you can see several items is Project Settings. Let's have a look at them.

Project . Strictly speaking, here are the settings referring to the project generally, where you can configure the name, SDK, language level, and the compiler output path.

Modules . Every project consists of modules. Module is a discrete unit of functionality that can be compiled, run, debugged and tested independently. Modules contain everything that is required for their specific tasks: source code, build scripts, unit tests, deployment descriptors, and documentation. A module can be a dependency for another module in the project.

Libraries . It is one of the module dependency types in Intellij IDEA, an archive of compiled code that a module can depend on. A Java library, for example, can include class files, archives and directories with class files as well as directories with Java native libraries (.dll,.so or .jnilib).

Facets . Each module can have a number of facets. Facets are required by the IDE to to provide framework-specific coding assistance, e.g. Web, Spring, Persistence. Mostly, facets are detected automatically by IDE, but here you can onfigure them manually.

Artifacts . An artifact is the output you want to be generated by your project. It may be a Java archive (JAR), Web application archive (WAR), an enterprise archive (EAR), etc. When you use a build tool, the artifacts are configured automatically, otherwise configure them manually in this section

For more information about project structure, read Project Structure Dialog or watch "Project Structure and Configuration"video tutorials.

Build Your Project

If your project doesn't use a build tool, use Build menu with the following commands:

  • Compile: Compiles files in the selected scope, whether they've changed or not.
  • Make: Compiles files if they have changed.
  • Rebuild Project: Forces a recompile of the entire project.
You can also look at the  'Make, compile and rebuild  ' tutorial and see  Compilation Types  .

IntelliJ IDEA supports Ant , Maven and Gradle . You can either create a new project by using the Project Wizard and choosing a corresponding build tool, or by importing an existing project from source and choosing the corresponding build file to import from.

If your project uses a build tool, you can also run the tasks of your build tool just from Intellij IDEA. Build menu still works for that kind of projects.

IntelliJ IDEA provides a tool window for a build tool where you can manage specific operations. To open it go to View | Tool Windows | Build Tool Name .

In this window you can also control behavior of the build, run build tasks and add tasks to run configuration as well.

For more information about supported build tools, you can see web help pages about Ant , Gradle or Maven or take a look at"Building on Ant, Gradle and Maven" video tutorial.

Run and Debug Your Application

Run/Debug configuration describes what happens when you click the Run or Debug button in the Toolbar or from Run menu. You can create several configurations and use the particular one you need by choosing from the dropdown. To edit run configuration click Run | Edit configurations'

To learn different types of run configurations, please look at theRun/Debug Configurations . See also Run/Debug Configuration basics .

Run and Debug Your Application

Make sure that appropriate test framework is specified in the dependencies of your module.

For running all tests in your application, right-click the test folder and then click Run 'All Tests' .

You can run particular test by pressing Ctrl+Shift+F10 on it. It is also based on run configuration.

Don't forget to watch Testing video tutorials and read Testing web help page .

Deploy Your Application to an Application Server

Before you deploy an application to an application server, make sure to configure this application server in File | Settings | Build, Execution, Deployment | Application Servers

Once you have your application server configured, create a corresponding Run/Debug configuration, and specify your application server:

Also, in the Deployment tab specify the actual artifacts to be deployed:

Find more comprehensive tutorial about deploying a Java EE application to an application server at Developing a Java EE Application .

Customize Everything

Customize IDE appearance in File | Settings | Appearance & Behaviour | Appearance. . Intellij IDEA provides light and dark appearance themes. There can be several light ones, depending on your OS, and a dark one called Darcula .

Customize the behaviour of the text editor in File | Settings | Editor .

In File | Settings | Editor | Colors and fonts , you can choose any color scheme for the Editor, modify them and save them as your own.

For configuring styles, go to File | Settings | Editor | Code Style.IntelliJ IDEA automatically applies a code style you've configured.

There are lots of shortcuts you can use in the text editor. Begin with checking the shortcuts you cannot miss . Also, download a reference card with most frequently used shortcuts for the various platforms: Win/Linux , MacOS .

For choosing from several keymaps Intellij IDEA offers you, go toFile | Settings | Keymap. You can also assign your own shortcut to any action.

Some customizations can be shared with your team via VCS.

Finding Your Way Around

If you've just forgotten a shortcut, use Find Action (Ctrl+Shift+A) and look for action by name.

Finally, if you want to find something, but you have no idea where to search, use Search everywhere function by pressing Shift twice.

Generally, if you want to find something in settings, use the search bar in the Settings/Preferences dialog .

Try start typing anywhere with trees or lists and find out that speed search is working in many places.

Version Control Integration

IntelliJ IDEA supports Git, CVS, Mercurial, Perforce and others. Having decided which one to use, specify its settings in File | Settings | Version Control. It's possible to add your current project or an existing project as a new VCS root.

Besides general VCS settings, here you can configure all that corresponds to the particular VCS you are going to use.

IDE lets you add, delete, commit, revert, manage branches, see history, push, pull and do many other things. Some operations are available in Version control tool window called by VCS | Show Changes View .

Others can be called from corresponding point of VCS menu.

To learn more about VCS see Version Control with IntelliJ IDEA and watch Version Control video tutorials .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值