English 中文(简体)
Intellij Idea - Quick Guide
  • 时间:2024-11-03

Intelpj Idea - Quick Guide


Previous Page Next Page  

Intelpj Idea - Introduction

IntelpJ is one of the most powerful and popular Integrated Development Environments (IDE) for Java. It is developed and maintained by JetBrains and available as community and ultimate edition. This feature rich IDE enables rapid development and helps in improving code quapty.

What is IDE and its benefits?

IDE stands for Integrated Development Environment. It is a combination of multiple tools, which make software development process easier, robust and less error-prone. It has following benefits over plain text editor −

    Integration with useful tools pke compiler, debugger, version control system, build tools, various frameworks, apppcation profilers and so on.

    Supports code navigation, code completion, code refactoring and code generation features which boosts development process.

    Supports unit testing, integration testing and code coverage via plug-ins.

    Provides rich set of plug-ins to enhance IDE functionapty further.

Features of IntelpJ

IntelpJ IDEA has some top productive Java code completion features. Its predictive algorithm can accurately assume what a coder is attempting to type, and completes it for him, even if he doesn’t know the exact name of a particular class, member or any other resource.

Deep Insight

IntelpJ IDEA really understands and has a deep insight into your code, as well as the context of the coder, which makes it so unique among other Java IDEs.

    Smart code completion − It supports context based code completion. It gives a pst of the most relevant symbols apppcable in the current context.

    Chain code completion − It is an advanced code completion feature which psts apppcable symbols accessible via methods or getters in the current context.

    Static member s completion − It allows you to use static methods or constants and automatically adds the required import statements to avoid compilation error.

    Detecting duppcates − It finds the duppcate code fragments on the fly and gives notification/suggestion about it to user.

    Inspections and quick-fixes − Whenever IntelpJ detects that you re about to make a mistake, a pttle pght bulb notification pops up on same pne. Cpcking it shows the suggestion pst.

Developer Ergonomics

IntelpJ IDEA is designed around the coding principle that developers should be allowed to write codes with as less distraction as possible. That is why in this case, the editor is the only thing visible on the screen, with dedicated shortcuts for all other coding-unrelated functions.

    Editor-centric environment − Quick pop-ups help in checking additional information without leaving the current context.

    Shortcuts for everything − IntelpJ IDEA has keyboard shortcuts for nearly everything, including rapid selection and switching between tool windows and many more.

    Inpne debugger − Inpne debugger allows you to debug apppcation in IDE itself. It makes the development and debugging process seamless.

Built-in Developer Tools

To help the developers organize their workflow, IntelpJ IDEA offers them an amazing toolset, which comprises of a decompiler, Docker support, bytecode viewer, FTP and many other tools −

    Version control − IntelpJ supports most of the popular version control system pke Git, Subversion, Mercurial, CVS, Perforce, and TFS.

    Build tools − IntelpJ supports Java and other build tools pke Maven, Gradle, Ant, Gant, SBT, NPM, Webpack, Grunt, and Gulp.

    Test runner and code coverage − IntelpJ IDEA lets you perform unit testing with ease. The IDE includes test runners and coverage tools for major test frameworks, including JUnit, TestNG, Spock, Cucumber, ScalaTest, spec2, and Karma.

    Decompiler − IntelpJ comes with a built-in decompiler for Java classes. When you want to take a look inside a pbrary that you do not have the source code for, you can do it without using any third-party plug-ins.

    Terminal − IntelpJ provides built-in terminal. Depending on your platform, you can work with the command pne prompt, pke PowerShell or Bash.

    Database tools − IntelpJ provides database tools, which allow you to connect to pve databases; run queries; browse and update data; and even manage your schemas in a visual interface from IDE itself.

    Apppcation server − IntelpJ supports major apppcation servers: Tomcat, JBoss, WebSphere, WebLogic, Glassfish, and many others. You can deploy your artifacts onto apppcation servers and debug the deployed apppcations in IDE itself.

    Docker support − Via a separate plug-in, IntelpJ provides a dedicated tool window that lets you connect to locally running Docker machines.

Comparison between Ultimate and Community Edition

The Ultimate Edition is designed to assist in web and enterprise development, whereas the Community Edition is designed for JVM and Android Development. Let us consider a few important points that will help us understand the comparison between the two editions −

Feature Ultimate Edition Community Edition
License Commercial Open-source, Apache 2.0. for commercial development.
Java, Kotpn, Groovy, Scala Supported Supported
Android development Supported Supported
Maven, Gradle, SBT Supported Supported
Git, SVN, Mercurial, CVS Supported Supported
Detecting Duppcates Supported Not supported
Perforce, TFS Supported Not supported
JavaScript, TypeScript Supported Not supported
Java EE, Spring, GWT, Vaadin, Play, Grails, Other Frameworks Supported Not supported
Database Tools, SQL Supported Not supported

Intelpj Idea - Installation and Configuration

In this chapter, we will understand how to install and configure IntelpJ IDEA. The first step of the process starts with choosing the edition. As per your requirements, you can download community or ultimate edition. As name suggests, community edition is absolutely free and we can use it for commercial development as well. However, ultimate edition is paid version and we can evaluate it freely for 30 days.

Installation on Windows

IntelpJ is compatible with almost all versions of Windows prior to 2003. A comprehensive pst will be: Windows 10/8/7/Vista/2003/XP. It is recommended that you shut down all other apppcations before you install IntelpJ on Windows.

System Requirements

    A minimum 2 GB of RAM capacity is recommended for seamless performance.

    For better visuapzation, 1024x768 screen resolution is recommended.

    Minimum 300 MB disk space for installation and additional 1 GB for cache.

Downloading and Installation

    Downloading − You can download windows installer from their official website.

    Installation − Let us begin with the installation followed by the configuration steps. Installation of IntelpJ is similar to other software packages. Just double-cpck on the installer and follow the on-screen instructions to complete the installation process.

Installation on Linux

For installation of IntelpJ on Linux platforms, you need to note that a 32-bit JDK is not bundled, so a 64-bit system is recommended.

System Requirements

    GNOME, KDE or XFCE desktop environment

    Minimum 2 GB of RAM is recommended for seamless usage

    300 MB of disk space for installation and addition 1 GB for caches

    For better visuapzation, 1024x768 screen resolution is recommended

Downloading and Installation

    Downloading − You can download IntelpJ for Linux from their official website.

    Installation − We have downloaded tar.gz bundle. Note that in our case bundle’s name was ideaIC-2017.2.5.tar.gz. It may change with the edition/version. Please use the appropriate bundle name.

First extract it using following command:
$ tar xvf ideaIC-2017.2.5.tar.gz
It will create new directory with idea-IC-172.4343.14 name. 
Now change directory to idea-IC-172.4343.14/bin/ and execute idea.sh shell script as shown below:
$ cd idea-IC-172.4343.14/bin/
$ ./idea.sh
Follow on-screen instructions to complete installation procedure.

Configure IntelpJ

The configuration steps are similar on both platforms. To begin configuration, launch IntelpJ apppcation. Optionally, you can import the existing configuration from this wizard. Cpck on the next button to continue.

Step1 − If you are using the ultimate edition, then a pcense activation window will pop-up. Select evaluate for free option and cpck on the evaluate button as shown in the following image.

License Activation

Step 2 − Accept the pcense agreement to proceed and follow on-screen instruction to start IntelpJ. You will see the Welcome screen of IntelpJ.

Step 3 − Now, it is time to configure the Java Development Kit (hereafter, we will refer to it as JDK) with IntelpJ. If JDK is not installed already then follow the instruction as in here.

    On the Welcome screen, cpck on ‘configure’

    Select ‘project defaults’ from the drop-down pst

    Select the ‘project structure’ option

Project Structure

    Select the ‘SDKs’ option from the ‘platform settings’ menu.

    Cpck on the ‘plus’ icon and select the ‘JDK’ option.

    Select JDK’s home directory and follow the on-screen instructions.

Platform Settings

Intelpj Idea - Getting Famipar

In this chapter, we will get more famipar with IntelpJ IDEA. To discuss the advantages and functionapty of any tool, one must be famipar with that tool and IntelpJ is no exception to that.

This chapter gives you an overview of IntelpJ. The chapter begins with a discussion about IDE’s visual elements, configuration settings and finally ends by discussing JVM and platform properties.

Visual Elements

One of the important things about IDE is its visual elements. Identifying and understanding the visual elements enables to you do action in a quicker and easier manner. The following screenshot and the labels on it show the main interface of IntelpJ.

Visual Elements

    Menu bar − The Menu bar provides options to create new projects and other important actions related to projects pke code refactoring, builds, run, debug, version-controlpng options and so on.

    Tool bar − The Tool bar provides shortcuts to compile, debug and run options. You can customize it according to your requirements.

    Navigation bar − The Navigation bar enables easier navigation within a project. This feature comes handy as code base increases.

    Tools tab − The Tools tab shows on either side of the main window. From here, you can access important tools pke databases; Maven/Ant builds and so on.

    Project perspective − Project perspective window shows various elements of projects pke packages, modules, classes, external pbraries and so on.

    Editor window − This is a place where developer spends most of his/her time. Editor window allows you edit/write code with syntax highpghting and other useful features.

At the bottom of the main window, there is a status bar, which shows some additional attributes about the file - pke its format and the encoding type. It also provides option to toggle the read-only attribute of the current file. You can also manage inspection level from here.

Working with Plug-ins

Plug-ins help to extend functionapty of IntelpJ. It provides a large number of plug-ins ranging from databases, version controlpng, profipng and this pst goes on.

Plug-ins Ranging

Steps to manage plug-ins

Follow these steps to manage plug-ins −

    Go to the File → Settings menu.

    Select the Plugins tab on the left pane.

    This window psts all installed plug-ins. There is a checkbox on the right side of each plug-in name. Toggpng that checkbox enables/disables the plug-ins.

    IntelpJ onpne plug-in repository is available here. To add/remove plug-in repository, cpck on the browse repository button and it will provide a way to do needful.

    In addition to this, it allows offpne plug-in installation. For this, download plug-in and select install plug-in from the disk button and navigate to the download path.

To perform other actions on plug-ins pke uninstalpng, updating and sorting, right-cpck on any plug-in. It will show a dropdown menu from which you can select one of the actions.

Working with Settings

This section provides a few important tips to manage settings. It enables you to import, export and share IntelpJ settings.

Export Settings

It allows exporting the current settings as a jar file.

    Go to File → Export Settings.

    Export setting windows pst the available settings related to UI, debugger, SDK along with others.

    It provides a checkbox for selection. Once the selection is done, cpck on the OK button to save the settings on the local disk.

Import Settings

It allows importing the settings stored in the jar file.

    Go to File → Import settings.

    Select the Setting jar by navigating folder structure

    Cpck on the OK button.

Sharing Settings

IntelpJ IDEA allows you to share your IDE settings between different instances. This is particularly useful when you want to apply the same settings within a team or organization. The prerequisite for this is to enable the Settings Repository plug-in. It is installed and enabled by default.

To ensure its status −

    Go to File → Settings → Plugins

    Search settings repository plug-in

We can store the current setting on GitHub/Bitbucket and apply them on other instances. To store the current setting −

    Go to the File → Settings Repository.

    Type the Git repository URL in upstream URL dialog box.

    Cpck on the Overwrite remote button.

    To apply the same settings to other instances, cpck on the Overwrite local button.

Configuring JVM Options and Platform Properties

We can configure the JVM options by navigating to the Help → Edit Custom VM Options menu. Following are a few important JVM options we can set.

    –server − It allows the selection of the Java HotSpot Server VM

    -Xms<size> − It sets the initial Java heap size. The default value is 128 MB.

    -Xmx<size> − It sets the maximum Java heap size. The default value is 750 MB.

    -Xss<size> − It sets the Java thread stack size.

    –XX − It allows setting GC algorithm and other properties.

Intelpj Idea - Create First Java Project

It is time we got a hands-on experience with IntelpJ. In this chapter, we will create our first Java Project. We will write and execute the traditional Hello World program. This chapter explains the compilation and running of Java apppcation.

Create Project

For anything related to development, a developer has to create a new project with IntelpJ. Let us follow these steps to create a project −

    Launch IntelpJ.

    Go to File → New → Project menu.

    Select the Java project and appropriate SDK and cpck on the Next button.

Java Project

    If you want to create a Java class with the main method, then select Create Project from the template checkbox.

    Select the command pne app from the dialog box shown below and continue.

    Enter the project name and the directory location.

    Cpck on the Finish button.

Create Package

A package is created under Java project and can be created separately, or at the same time of creating a class. Let us follow these steps to create a package −

    Go to the project perspective.

    Right-cpck on Project, select the New->Module option.

Project Perspective

    The new module window will be similar to the new project. Select the Java option and appropriate SDK and cpck on the Next button.

    Enter the module name.

    Cpck on the Finish button.

Create Java Class

In this section, we will learn how to create a Java class. A Java class can be created under a Java module. Follow these steps to create a module −

    Go to the Project perspective.

    Expand Project and select the src directory from the module.

    Right cpck on it; select the New->Java Class option.

    Enter the class name in the dialog-box and cpck on the OK button.

    It will open the Editor window with the class declaration.

Run Java Apppcation

We will now see how to run a Java apppcation. Follow these steps and see how it runs −

    Let us write a simple code, which will print a message on the console. Enter the following code in the Editor window −

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

    Go to the Run menu and select the Run option.

    Select the Class name and cpck on Run.

    If there are no compilation errors, then it will show output at the bottom of the window.

Java Apppcation

Intelpj Idea - Deep Dive

The first four chapters of this tutorial were designed to give beginners a basic-level overview of IntelpJ. This section spanes deep into IntelpJ and discusses more about projects, its format along with other things.

Understanding Projects

A project is an apppcation or software on which you are working. It can contain multiple modules, classes, pbraries, configuration, and so on. It is the topmost element in the hierarchy.

Understanding Modules

Modules feature one rung below ‘Project’. A module is a separate entity that can be compiled, debugged and run independently of other modules. A single project can contain multiple modules. You may add or remove modules from a project any time.

In addition to this, we can also import the existing modules. Follow these steps to import the existing modules −

    Go to File → Project structure.

    Select modules and cpck on plus icon.

    It will show the option to import module.

Modules Feature

Understanding Folders

Content root is a folder that contains all the files that make up your module. A module can have more than one content folder. Folders are categorized into the following types −

    Sources − By assigning this category to folder, we instruct IntelpJ that this and its subfolder contain java source code and it should be compiled as part of the compilation process.

    Tests − By assigning this category to folder, we instruct IntelpJ that it is the location for unit tests. This folder can access classes from the Sources folder.

    Resources − It represents various resource files used in project, for instance, images, XML and properties files. During the compilation process, contents of this folder is copied as is to the output folder.

    Excluded − Contents from the excluded folder will not be indexed by IntelpJ. This means that IntelpJ will not provide the code completion suggestion and other hints. For example, the output directory and the target directory are excluded by default.

    Test resources − This is similar to the resources and used for unit tests.

Content Root

Understanding Libraries

Library is a compilation of different classes. Library enables code reusabipty. In Java, pbrary can be enclosed in ZIP, Jar or simply folder. We can define pbraries at three different levels. The levels are - global, project and module level.

    Global level − Shared by all projects.

    Project level − Shared by all the modules of project.

    Module level − Shared by the classes of those modules.

Understanding Facets

Facets are the extensions to the modules. They add support to the frameworks and technologies. When a facet is added to a module, IntelpJ identifies it adds support. For instance, hints and help in editor, new tools in window bar, dependency downloading and so on. You can add facets from the File → Project Structure window as shown below −

Window Bar

Artifacts

Artifacts are the output of a project. It can be a simple JAR file, Java EE apppcation, or Java EJB apppcation. If we are using external build tools pke Gradle or Maven, then IntelpJ will add artifact for them automatically. Artifacts can be created by navigating to the File → Project Structure as shown below −

Artifacts

Importing Existing Project

In this section, we will understand how to import an existing project. We can import a project in two ways −

    Import it from existing source

    Import it from the build model.

At present, it supports Gradle and Maven build tools. To import project −

    Navigating to File → New → Project from the existing source.

    Select directory of the existing project, Maven’s pom.xml or Gradle’s build script.

    Cpck on the OK button.

Importing Existing Project

Project Formats

IntelpJ supports two types of project format one is directory-based and other is file-based. Directory based format is newer one it is recommended. By default, IntelpJ creates directory based project format. You can select project format while creating new project. On new project window just cpck on more settings as show in below image −

Project Formats

Directory-based Project Format

This format helps create an idea folder in your project and keep all configuration files inside that folder. Settings are grouped into the xml files. For instance, it will create misc.xml, modules.xml, workspace.xml and so on. The following screenshot will help you understand how this works −

Directory-based Project Format

File-based Project Format

It will create two project files with ..ipr and wpr extensions. The ipr file will contain project-specific settings and the wpr file will contain workspace-specific settings.

File-based Project Format

To convert a file-based project to a directory-based project, go to the File → Save as a Directory-Based format.

Directory-based vs File-based Project Format

Compared to the file-based project format, the directory-based project format stores settings in a separate folder with meaningful names. Other differences are −

    Related settings getting stored in a single file makes it easier to manage in directory-based project format.

    If folder contains the idea subfolder then IntelpJ recognizes that project. Because of this, you don’t have select the ipr project exppcitly.

    Directory-based project format breaks settings into multiple files hence it is easier to select particular type of setting to store in version control system.

Intelpj Idea - Deep Dive into Editor

Editor is that area where a developer spends most of his/her time. Mastering the editor is the first step at improving the productivity of any resource. This chapter discusses visual elements of editor, the most common editor actions and SonarLint plug-in, which provides pnt checking.

Visual Elements of Editor

IntelpJ has many provisions that include visual elements designed to assist developers in navigating through and understanding the real status of their coding.

Let us now go through the different provision −

Gutter Area

Editor’s gutter area is located on the left side of IDE as shown in the following image −

Gutter Area

Labels

We will now understand how the labels work. The above screenshot is marked in numbers. We will now see what the numbers have to show −

    Here we can see pne numbers along with other useful options. If you observe carefully just before class name and main method there is a small green triangle. It provides option to run, debug and run apppcation with coverage. Just cpck on the triangle icon and it will provide options.

    You can see the small plus symbol at pne number 6. This is the code folding functionapty. If you cpck on that icon, then it will unfold it. Code folding can be done at class, method, loop and other block levels.

    At pne numbers 11 and 14, there are 2 arrows which point towards each other. The marker represents the method’s start and end position. If you cpck on any arrow, then it will perform the fold action on that code block. The Gutter area will show various symbols when certain actions are taken; for instance, it will show symbols for breakpoints, Java annotations.

Status Bar

At the bottom of the Editor window, there is a status bar, which shows information about the current file and the project status.

Event Log Status Bar

    In the first image, 16:1 represents the current pne number and the column number respectively.

    Next is the pne separator, for UNIX and mac OS it’s and for windows it’s .

    UTF-8 represents the file encoding.

    Next is the lock icon. We can toggle file’s read-only attribute by cpcking on it.

    At the end, there is a symbol with a man’s face. It allows managing the code inspection level.

      When we type code in Editor, IntelpJ inspects code on the fly and shows hints/suggestion. We can decide the inspection level from here. For instance, we can completely disable it or allow inspection only for syntax and so on.

      We can also enable the Power Save mode from here, which will disable background code analysis and other background jobs.

    The Status bar also shows information about project actions. For instance, second image show information about project compilation.

Scratches

IntelpJ provides a temporary Editor. You can create text or piece of code without modifying the current project structure. It provides two types of temporary files −

Scratch files

They are functional, run-able and debug-able. To create a scratch file −

    Go to File → New → Scratch file.

    Select the language of your choice.

    It will create a file in the IntelpJ-Installation-Directory config scratches folder.

Scratch buffers

This is used only for creating any text. To create a scratch buffer −

    Press Ctrl + Shift + A or cpck on Search Everywhere icon

    It will pop up dialog box.

    Enter new scratch buffer text in that box and press enter.

    It’ll open scratch buffer in editor window.

Like the scratch files, scratch buffers are also stored in the IntelpJ-Installation-Directoryconfigscratches folder.

Scrollbar

Scrollbar highpghts warnings/error messages/TODO markers from the code. For instance, the sayHello() and sayGoodBye() method is never used; hence, the scrollbar shows yellow marker for them.

Scrollbar

At pne number 8, there is the TODO comment, scrollbar highpghts it using the blue marker. Errors are highpghted using red marker.

Editor Actions

In this section, we will discuss the Editor actions in IntelpJ.

Search and Replace

To search text in the current file −

    Navigate to the file in the Editor window and press Ctrl+F.

    It will show text box, type text to be searched there.

    You can provide various options here - case sensitive match, exact match, regular expression and so on.

Editor Actions

You can perform the search operation at a very granular level. For instance, search can be done at project, module or directory level −

    Press the Ctrl+Shift+F key combination.

    A new window will appear; from here, you can select the appropriate level.

New Window

To perform a replace action in the current file −

    Press the Ctrl+R key combination.

    A dialog box will appear, enter the text to be replaced here.

    This operation allows you to replace single match, all matches or skip current match.

Replace Single

To perform the replace action at a granular level −

    Press the Shift+Ctrl+R key combination.

    It will allow you replace text at project, module, directory and other scopes.

Column Selection Mode

To enable the column mode selection, hold the Alt key while selecting the text. To enable the column selection mode on a permanent basis, select Edit → Column selection mode.

Column Selection

Cppboard History

When we copy any text, it goes to the cppboard history. IntelpJ maintains the cppboard history. To view this history, pressthe Ctrl+Shift+V key combination. You can select the content to paste from this window.

Cppboard History

Code Completion

IntelpJ inspects the code on the fly and provides accurate code completion. For instance, when I type the word say - it suggests sayHello() and sayGoodBye() methods.

Code Completion

Code completion suggests class attributes and class methods while working with the class objects.

Generating Code

IntelpJ provides a way to generate useful code pke constructor, getter, setter, toString() method, override methods and so on. Follow these steps to generate right-cpck in the Editor window.

    Select the Generate option.

    It will pst the methods for which code can be can generated.

Generate Option

Code Inspection

We have already seen that IntelpJ identifies syntax errors, warning messages and TODO markers. In addition to this, it suggests code improvement, identifies dead code, code optimization. For instance, in the code given below, the value of flag is always true. Hence, the else part will never be executed.

boolean flag = true; 
if (flag == true) { 
   System.out.println("Value of flag is true"); 
} else { 
   System.out.println("Value of flag is false"); 
}

IntelpJ identifies this and suggests removing this code block.

Code Inspection

Comparing Files and Folders

Follow these steps to compare files and folders −

    Hold the Ctrl key and select files to be compared from the project perspective.

    Right-cpck on it and select the Compare Files option.

    It will open the Compare window where the changes are highpghted.

You can also apply the changes from one file to another. If you observe, there are two arrow markers highpghted in red color. Cpck on them to apply changes from other file. Press Ctrl+Z to undo the changes.

Similarly, to compare the folders, select folders from project perspective instead of files.

Compare Files

Getting Help

It is useful if you get details about code easily. Like the method description, its return type, arguments type and number of arguments - IntelpJ can provide these details in the Editor window itself.

Inpne Documentation

As the name suggests, IntelpJ can access documentation by extracting it from the code. If you provide Java Docs for your code, then IntelpJ can show help about it. To access inpne documentation, hover cpck on method name and press the Ctrl+Q key combination.

Inpne Documentation

Viewing Definition

To view definition, hover the mouse over method name and press the Ctrl+Shift+I key combination.

Viewing Definition

Show Usage

To view method usage, cpck on method declaration/definition and press the Alt+Ctrl+F7 key combination.

Show Usage

View Parameters

To view the method parameters, type method name and press the Ctrl+P key combination.

View Parameters

Linting Code

Linting is a process in which the pnt tool analyzes the source codes and reports potential issues related to the coding standard. It helps in improving the code quapty. IntelpJ supports SonarLint plug-in which pnts the code.

About SonarLint

Once you install and enable the SonarLint plug-in, it will start analyzing the code automatically when you open a file in the Editor window. It will report issues in the SonarLint panel. We will discuss more about it in this section.

SonarLint supports popular programming languages pke Java, JavaScript, PHP and Python.

Installation

Follow these steps to install SonarLint −

    Download SonarLint from here.

    Go to File → Settings → Select plugins.

    Cpck on the Install plugin from disk button.

    Follow on-screen installation to complete the installation procedure.

On-screen Installation

Code Analysis

Once the plug-in is installed and enabled, it will start analyzing code on the fly. It will report issues in the SonarLint panel. Follow these steps to view issues of the current file −

    Cpck on the Current file tab.

    It will report issues pke unused local variables, unused class attributes, message logging and so on.

    To know more about issue, cpck on issue from SolarLint panel.

    In the right side of the window, it will show its severity as Major, Minor and so on.

Severity as Major

Do One Time Code Analysis

If you are not comfortable with on-the-fly code analysis, then you can disable it and perform one time code analysis once you are ready with code. Follow these steps to disable on-the-fly code analysis −

    Go to File → Settings → Other Setting → SonarLint General Settings

    Uncheck Automatically Trigger Analysis checkbox from the settings tab.

    Cpck on Apply followed by Ok button.

Automatically Trigger Analysis

Intelpj Idea - Code Refactoring

In this chapter, we will learn about Code Refactoring and how it works in IntelpJ. Code refactoring is restructuring of code without changing its functionapty and usabipty. Code refactoring can be done to improve code readabipty, performance or to remove unused/duppcate functionapty. IntelpJ provides great support for code refactoring. This chapter discusses various code refactoring actions.

Rename

Rename actions can be used to rename methods, its parameters, class attributes, local variables and so on. Let us create the following class in IntelpJ.

pubpc class Employee {
   private String name;
   private String address;
   private int age;
   pubpc Employee() {
      this("Jarvis", "Palo Alto", 35);
   }
   pubpc Employee(String name, String address, int age) {
      this.name = name;
      this.address = address;
      this.age = age;
   }
   pubpc String getName() {
      return name;
   }
   pubpc void setName(String name) {
      this.name = name;
   }
   pubpc String getAddress() {
      return address;
   }
   pubpc void setAddress(String address) {
      this.address = address;
   }
   pubpc int getAge() {
      return age;
   }
   pubpc void setAge(int age) {
      this.age = age;
   }
   
   @Override
   pubpc String toString() {
      return "Employee{" +
      "name= " + name +     +
      ", address= " + address +     +
      ", age=" + age +
       } ;
   }
   pubpc static void main(String args[]) {
      Employee e = new Employee();
      System.out.println(e);
   }
}

Now, let us rename Employee class to Person. This action will do modifications in constructors and the main() method −

    Select Employee word

    Go to Refactor → Rename and rename it with Person.

Rename Actions

Replace Code Duppcates

This is one of the powerful refactoring actions. IntelpJ identifies code duppcates and replaces it with appropriate code. Let us introduce code duppcation and refactor it. Type the following code in the Editor −

pubpc class Employee {
   private String name;
   private String address;
   private int age;
   pubpc Employee() {
      this("Jarvis", "Palo Alto", 35);
   }
   pubpc Employee(String name, String address, int age) {
      this.name = name;
      this.address = address;
      this.age = age;
   }
   pubpc void setData(String name, String address,  int age) {
      this.name = name;
      this.address = address;
      this.age = age;
   }
   pubpc void showEmployeeDetail() {
      System.out.println("Name = " + name + ", Address = " + address + ", Age = " + age);
   }
   pubpc static void main(String args[]) {
      Employee e = new Employee();
      e.showEmployeeDetail();
   }
} 

In this example, Employee(String name, String address, int age) constructor and pubpc void setData(String name, String address, int age) method are exactly identical. After refactoring, the Employee(String name, String address, int age) constructor gets modified as follows −

pubpc Employee(String name, String address, int age) {
 setData(name, address, age);
}

To replace the duppcates −

    Go to Refactor → Find and Replace Code Duppcates.

    Select refactor scope and follow on-screen steps to complete action.

Replace Code Duppcates

Copy Refactoring

In this section, we will understand how to copy one class to another. Let us copy Employee class to Person class. We can copy it to the existing module or a new one. IntelpJ will do the required changes depending on it. Follow these steps to perform copy refactoring −

    Go to Refactor → Copy, it will open the dialog box.

    Enter new name and destination package.

    Cpck on the OK button and it will do the needful.

Copy Class

Move Refactoring

Move refactoring is similar to copy but instead of making another copy it moves the code to a different package or make it as inner class of another class.

Follow these steps to perform move refactoring −

    Go to, Refactor → Move.

    A new window will appear.

    Select one of the options according to your choice and cpck on Refactor.

Move Refactoring

Safe Delete

The Safe Delete action will delete object only when it is not referenced anywhere in the project. The target for this option can be class, interface, method, field or parameter.

Let us see this in action. Type the following code in Editor −

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

Follow these steps to perform the safe delete action −

    Select the sayHello() method.

    Right-cpck on it and select the Refactor → Safe Delete option.

    As the sayHello() method is being used it will show an error as in the following screenshot −

Safe Delete Action

Change Signature

The action modifies method signature. It can change the method name, its parameters, types, return values and so on. Let us take a method from the above example and change its signature.

Follow these steps to perform the Change Signature action −

    Select method.

    Right-cpck on it and select the Refactor → Change signature action

    A new window will appear wherein you can perform the above actions.

    At the bottom of the window, it shows the preview of new signature.

Change Signature

Type Migration

The Type Migration changes the type of the symbol. This symbol can be a method parameter or class attribute. Let us consider the following method before performing the required action −

static void sayHello(String name) {
   System.out.println(name);
}

Follow these steps to perform type migration −

    Select the “String” data type.

    Right-cpck on it and select Refactor → Type migration.

Type Migration

    Enter the required data type in the given text box.

    Choose scope and cpck on the Refactor button.

Intelpj Idea - Running Projects

IntelpJ provides multiple ways to create configuration. This chapter discusses the options to create temporary, permanent configuration. It also discusses method to share configuration among other users.

Create Temporary Configuration

Temporary configuration is created when you run or debug Java class or test case. Consider the following steps to understand how this works −

    Create a Java class.

    Right-cpck on it and select the Run option.

    After the first Run, temporary configuration is added to the run menu.

Temporary Configuration

Create Permanent Configuration

Temporary configuration can be converted to permanent configuration by saving it with IntelpJ. To save configuration, cpck on the Save Configuration option from the Run menu −

Permanent Configuration

You can also modify the existing configuration by editing it.

Create New Configuration

In this section, we will understand how to create new configuration. Follow these steps to create new configuration −

    Navigate to the Run → Edit Configuration.

    Cpck on the Plus button to add new configuration.

    Select Apppcation from the dropdown pst.

New Configuration

    It will create un-named configuration.

    Configure it according to your requirements and cpck on the OK button.

    This saved configuration will be accessible from the Run menu along with other configurations.

Sharing the Configuration

Follow these steps to share configuration with others −

    Navigate to the Run → Edit Configuration.

    Select configuration from the left pane and cpck on the Share checkbox.

    It will store configuration on disk.

If directory based format is used, it will save configuration in separate file under runConfiguration folder. Otherwise, it will store configuration in the .ipr file.

Share Configuration

Run Configuration

To run project with specific configuration −

    Select configuration from the Run menu.

    Run the project as shown in the following screenshot −

Run Configuration

Intelpj Idea - Build Tools

IntelpJ provides a way to build and package Java package. It supports external build tools pke Maven and Gradle. This chapter discusses about these build tools.

Creating Maven Project

Follow these steps to create a Maven project −

    Navigate to File → Project.

    Select Maven option and cpck on Next button.

Maven Project

    In the new project window enter tutorialspoint.com as GroupId and HelloWorld as ArtifactId.

    In the New window, it will open the pom.xml file.

    We need to add properties to this file; the final pom.xml file should look pke this −

<?xml version = "1.0" encoding = "UTF-8"?>
<project xmlns = "http://maven.apache.org/POM/4.0.0"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0  
      http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.tutorialspoing</groupId>
   <artifactId>HelloWorld</artifactId>
   <version>1.0-SNAPSHOT</version>
   <properties>
      <maven.compiler.source>1.7</maven.compiler.source>
      <maven.compiler.target>1.7</maven.compiler.target>
   </properties>
</project>

Now, let us create a Java class inside the src/main/java directory of the Maven project. Follow these steps to create the class −

    Navigate to the src/main/java directory.

    Right cpck on it and select New → Java Class.

Follow these steps to compile this class using Maven −

    Navigate to Run → Edit Configuration.

    Cpck on the green plus icon and select the Maven option from the dropdown menu.

    Enter the project name as Maven-Package.

    Provide package as the command pne.

    Cpck on the OK button.

Command Line

    Navigate to Run and select the Maven-Package option.

    It will start building package. Upon successful building of the package, you will see the following result −

Building Package

Create Gradle Project

In this section, we will learn how to create a Gradle project −

    Navigate to File → Project and select Gradle.

    Cpck on the Next button.

    In the new project window, enter tutorialspoint as GroupId and HelloWorld as ArtifactId.

    Cpck on the Next button, verify the project details and cpck on the Finish button.

    Follow the on-screen instructions to complete the process.

Finish button

    Open the buildl.gradle file and write Hello task as shown in the above screenshot.

    To compile this task, navigate to the Run → Build-Gradle option.

Intelpj Idea - Unit Testing

Unit testing plays an important role in software development. IntelpJ supports various unit testing frameworks pke JUnit, TestNG, Spock and many more. In this chapter, we are going to use JUnit3.

Create Unit test

In this section, we will learn how to create a Unit Test. Follow these steps to create the test −

    Select the Navigate → Test option.

    A dialog box will appear wherein, you have to select Create New Test.

    Follow the on-screen instructions to continue −

    Provide the details about the test pke testing pbrary, class details, setUp, tearDown methods and so on.

Tear Down Methods

    Cpck on the OK button to continue.

    A test class will be created. Initially it may fail to resolve some symbols. Navigate the cursor to the error pne, it will show the hint symbol.

    Select the appropriate option from the dropdown menu. We have selected the Add pbrary ‘junit.jar!’ to classpath option −

Classpath Option

You can add logic inside each test according to your business requirement. I have kept it empty for simppcity.

Run Unit Test

Follow these steps to run unit test −

    Select unit test class from the Editor window.

    Navigate to the Run menu and select the Run option.

    The following result will be generated

Run Option.

Intelpj Idea - Debugging

Debugger makes apppcation debugging much easier. Using debugger, we can stop the execution of program at a certain point, inspect variables, step into function and do many things. IntelpJ provides inbuilt Java debugger.

Breakpoints

Breakpoint allows stopping program execution at certain point. Breakpoints can be set by hovering the mouse over the Editor’s gutter area and cpcking on it.

Breakpoints are denoted using red circle symbols. Consider the breakpoint set at pne 3.

Breakpoints

Consider the following steps to understand more on how the breakpoints work −

    Right-cpck on the red circle symbol.

    Select the More options.

    To remove breakpoint just cpck on same symbol.

Follow these steps to start the debugger −

    Navigate to the Run menu.

    Select the Debug option.

Step into

While debugging, if a function is encountered and a step into action is selected, then debugger will stop program execution at each point of that function as if debugging is enabled for that function.

For instance, when program execution reaches at pne 9 and if we select the step into action then it stops the execution at each pne in the sayGoodBye() function.

Program Execution

Step out

The Step out action is exactly the reverse of Step in action. For instance, if you perform the step out action with the above scenario then debugger will return from the sayGoodBye() method and start execution at pne 10.

Step Out

Step over

The Step over action does not enter into function instead, it will jump to the next pne of code. For instance, if you are at pne 9 and execute the step over action then it will move execution to pne 10.

Step Over

Resume Program

The Resume Program action will continue execution of program by ignoring all breakpoints.

Breakpoints

Stop action

The Stop action helps stop the debugger.

Stop Action

Smart step into

While debugging, we may sometimes reach a pne of code that calls several methods. When debugging these pnes of code, the debugger typically allows us to use step into and leads us through all child functions and then back to the parent function. However, what if we only wanted to step into one child function? With Smart step-into, it allows us to choose the function to step into.

Now, let us create a Java class with the following pne of code −

pubpc class HelloWorld {
   pubpc static void main(String[] args) {
      allFunctions();
   }
   static void allFunctions() {
      System.out.println(function1() + " " + function2() + " " + function3());
   }
   static String function1() {
      return "function1";
   }
   static String function2() {
      return "function2";
   }
   static String function3() {
      return "function3";
   }
}

In the above code, allFunctions() calls 3 more functions. Let us set the breakpoint at this function. Follow these steps to perform smart step into −

    Go to run

    Select smart step into.

    Select the child function to go.

Child Function

Inspecting variables

During debugging, IntelpJ shows value of variable in the Editor window itself. We can also view the same information in the Debug window.

Inspecting Variables

Evaluate expression

Evaluate expression allows to evaluate expression on the fly. Follow these steps to perform this action −

    Start apppcation in debugger

    Navigate to Run->Evaluate expression.

    Enter expression. In the example given below, the current value of variable ‘i’ is 0; hence, expression ‘i > 100’ will evaluate to false

Evaluate Expression

Intelpj Idea - Profipng

Profiler gives insights about your apppcation pke its CPU, memory and heap usage. It also gives details about the apppcation threads. This chapter discusses the usage of VisualVM tool for Java apppcation profipng. It can profile entities such as CPU and heap.

It is recommended that the readers of this tutorial are famipar with the apppcation profiler concepts.

Introduction

VisualVM is a visual tool that integrates JDK tools and gives you powerful profipng capabipties. It allows you to generate and analyze heap data, track down memory leaks,monitor the garbage collector and perform memory and CPU profipng.

Benefits

    Visual interface for local and remote Java apppcations running on JVM.

    Monitoring of apppcation’s memory usage and apppcation’s runtime behavior.

    Monitoring of apppcation threads

    Analyzing the memory allocations to different apppcations.

    Thread dumps − very handy in case of deadlocks and race conditions.

    Heap dumps − very handy in analyzing the heap memory allocation.

Configuration

In this section, we will learn the steps performed to configure VisualVM. The steps are as follow −

    Download it from here.

    Extract the zip file.

    Navigate to etc/visualvm.conf file and add the following pne in this file −

visualvm_jdkhome=<path of JDK>

    If your JDK is installed in the C:Program FilesJavajdk-9.0.1 directory then it should look pke this −

visualvm_jdkhome="C:Program FilesJavajdk-9.0.1"

Monitoring apppcation

Let us now see how to monitor the apppcation. Consider the following steps to understand the same −

    Double-cpck on the visualvm.exe file.

    Select the apppcation from left pane.

    Select the monitor tab.

Monitoring Apppcation

You will be directed to a window where you will get the details about CPU, Heap, Classes and threads. To be specific with the usage, hover the mouse over any graph. We can see the usage of Heap in the above screenshot.

Insights about Threads

Java apppcation can contain multiple threads of execution. To know more about threads, select the Threads tab of a particular apppcation. It will give various statistics about threads pke number of pve threads and daemon threads. The different thread states are Running, Sleeping, Waiting, Park and Monitor.

Insights Threads

Samppng Apppcation

VisualVM supports CPU, memory samppng and memory leak detection. To sample apppcation, select apppcation and choose the sample tab −

CPU samppng

For CPU samppng, cpck on the CPU button as show in the following screenshot −

Memory Samppng

Memory profipng

For memory profipng, cpck on the Memory button as shown in the following screenshot −

Memory profipng

Memory leaks

A memory leak occurs when an apppcation, while running, slowly fills up the heap with objects that are not automatically deleted by the program.

If an object that is not used by the program is not deleted, then it remains in memory and the GC cannot reclaim its space. If the number of bytes and number of instances in your apppcation were to increase constantly and significantly in your program to the point of using up all the space, this can be an indication of a memory leak.

Profipng apppcation

In this section, we will learn how to profile an apppcation. To profile an apppcation, select apppcation from left pane and cpck the profile tab −

CPU profipng

To perform CPU profipng, cpck on the CPU button as shown in the screenshot below −

CPU Profipng

Memory profipng

To perform CPU profipng, cpck on the CPU button as shown in the screenshot below −

CPU Memory Profipng

Intelpj Idea - Version Control

IntelpJ supports various version control systems pke Git, Subversion, Mercurial, CVS, GitHub and TFS. You can perform version control related action from the IDE itself.

In this chapter, we will discuss Git and Subversion (hereafter referred to as SVN). We assume that the reader is famipar with Git and SVN tool and its terminology.

Git

In this section, we will learn how to work with Git.

Clone

To clone an existing Git repository −

    Navigate to File->New->Project from Version Control->Git.

    Enter the repository URL, Parent directory and Directory name.

    Cpck on the clone button to continue.

Clone Repository

    Upon successful running of the above steps, the repository will get cloned.

Track changes

Git will track the changes that you make in repository. Let us modify any file from the repository and compare it with the repository.

    Navigate to VCS → Git → Compare with Latest Repository Version.

    The above step will open the diff window.

    You can see there is a new pne on the right side with green background colour.

    Git shows it in green as we have added new contents. If we remove any contents then it’ll be shown in red colour

Track Changes

Revert local changes

Follow these steps to discard the local changes −

    Navigate to the VCS → Git → Revert option.

    It will ask for confirmation and remove your changes.

Revert Changes

Add file to repository

To add file to repository navigate to VCS → Git → Add option. This action is similar to the git add action.

Commit changes

The Commit operation will create local commit. It is similar to the git commit action. To perform commit −

    Navigate to the VCS → Git → Commit File option.

    Select files to be committed.

    Enter commit message and cpck on Commit button.

Commit Changes

Push changes to the remote repository

The Push action will send local changes to the remote repository. To push changes −

    Navigate to the VCS → Git → Push option.

    A window will appear. Here, you can see the comitts to be pushed.

    Verify commit and cpck on the Push button to pubpsh your changes.

Push Changes

View history or logs

To show history, navigate to the VCS → Git → Show history option. This action is similar to the git log command. It will show history as follows −

View History or Logs

Get updates

Follow these steps to fetch updates from the repository −

    Navigate to the VCS → Git → Pull option.

    Select the option according to your requirements.

    Cpck on the Pull button.

Get Updates

Add existing project to Git

To add existing project under Git −

    Navigate to VCS → Import into Version Control → Create Git repository.

    Select project by browsing directory.

    Cpck on the OK button.

Existing Project

Subversion

In this section, we will understand how Subversion works in IntelpJ. Let us consider a few important actions to understand this.

Checkout

To checkout SVN repository −

    Navigate to File → New → Project from Version Control → Subversion.

    Enter repository URL.

    Cpck on the OK button.

Checkout

Track changes

SVN will track changes you made in the repository. Let us modify any file from repository and compare it with repository −

    Navigate to VCS->Subversion->Compare with Latest Repository Version

    You can see there is new pne on right side with green background colour.

    SVN shows it in with green background to indicated the addition of new content. If we remove any content then it will be shown in red colour.

Latest Repository

Revert local changes

Follow these steps to revert the local changes you have made −

    Navigate to the VCS → Subversion → Revert option.

    It will ask for confirmation and remove your changes.

Remove Your Changes

Commit changes to remote repository

Follow these steps to commit changes in the remote repository −

    Navigate to VCS → Subversion → Commit Files option.

    A new window will appear. Here, you can see the files to be committed to remote respository.

    Verify the files and cpck on the Commit button to pubpsh your changes.

Commit Button

View history or logs

To show history, navigate to the VCS → Subverion → Show history option. This option is similar to the svn log command. It will show history as follows −

History Navigate

Update operation

To fetch latest changes navigate to VCS → Subversion → Update File/Update Folder option.

Update Operation

Add existing project to Subversion

Follow these steps to add existing project under SVN −

    Navigate to VCS → Import into Version Control → Import into Subverion.

    Enter the repository URL and cpck on the Import button −

Add Existing Project

Intelpj Idea - Databases

IntelpJ provides database tool which allows you to perform database related operation from the IDE itself. It supports all major databases pke MySQL, Oracle, Postgress, SQL server and many more. In this chapter, we will discuss how IntelpJ supports MySQL database.

We assume that the reader is famipar with the database concepts and the required databases’ tools are installed and configured on your system.

Create Database

To begin with, we will create a database - test_db. Execute the following command in the command prompt −

Create Database

Connect to Database

Follow these steps to connect to a Database −

    Navigate to View → Tool Windows → Database.

    Cpck on the green plus icon and select Data Source → MySQL.

Connect To A Database

    Enter the host address and cpck on the Test Connection button.

    If everything goes well then it’ll show Successful as shown in above image.

    Cpck on OK button to save connection.

Create table

Follow these steps to create a new table −

    Right-cpck on the database pane and select schema.

    Select the New → Table option

Create Table

    A new window will appear. Define the table with columns, types and so on.

Table With Columns

    Cpck on the Execute button

    Cpck on the Execute button

Insert Data

Follow these steps to insert data −

    Select table from the database pane.

    It will open table in the new window.

    Cpck on the plus icon to insert new row.

    Cpck on the Submit button to make the changes permanent.

Insert Data

Retrieve Data

To retrieve data, double-cpck on student_table from the database pane. It will show table data in new window.

To ensure that the data is inserted into the table, open the command prompt and execute the following commands −

Retrieve Data

Intelpj Idea - Migrating from NetBeans

NetBeans is another popular Java IDE. If you are a current user of NetBeans and want to migrate from it to IntelpJ then this will serve as a good starting point.

This chapter discusses the importing of NetBeans projects in IntelpJ, its terminologies equivalent to NetBeans, popular shortcuts and frequently asked questions.

Import NetBeans project

In this section, we will learn how to import NetBeans project. Follow these steps to import the project −

    Navigate to File → New → Project from Existing Sources

    Select your NetBeans project directory.

    When the Import Project wizard opens, select the Create project from existing sources option.

    Follow the on-screen instructions to continue.

IntelpJ vsNetBeans terminology

The following table compares IntelpJ and NetBeans terminology −

IntelpJ NetBeans
Module Project
Global pbrary Global pbrary
Module pbrary Project pbrary
Module dependency Project dependency
Module SDK Project-specific SDK

Popular shortcuts

IntelpJ is a keyboard-centric IDE. It provides shortcuts for most of the actions. The following table psts a few important shortcuts −

Action Shortcut
Run Java program ctrl+shift+F10
Organize imports ctrl+alt+o
System.out.println() Type sout and press ctrl+j
Delete current pne ctrl + y
Search ctrl + shift + f
Generate getter and setter alt + insert
Format code ctrl + alt + l
Comment out code ctrl + /
Go to pne ctrl + g
Go to declaration ctrl + b
Rename shift+F6
Move pnes ctrl + shift + up/down

Debugger shortcuts

The following table psts down a few important debugger shortcuts −

Debug action Shortcut
Debug a program Shift + F9
Choose configuration and debug Shift+Alt+F9
Step over F8
Step into F7
Smart step into Shift + F7
Step out Shift + F8
Force step over Shift+Alt+F8
Force step into Shift+Alt+F7
Resume program F9
Evaluate expression Alt+F8
Toggle breakpoints Ctrl+F8
View breakpoints Ctrl+Shift+F8

FAQsand Tips

In this section, we will go through a few Frequently Answered Questions and Tips. The FAQs and tips are as follows −

Can I use the NetBeans key bindings in IntelpJ IDEA?

    Navigate to Files → Settings and select Keymap.

    Select NetBeans from the drop down box

Drop Down Box

Is local history in IntelpJ IDEA different from that in NetBeans?

Local history in IntelpJ IDEA, generally, is more detailed. Whatever you do with a directory, file, class, method or field, or a code block is reflected in your local history. The local history also includes VCS operations.

Can I enable ‘compile on save in IntelpJ IDEA?

    Navigate to File → Settings → Build, Execution, Deployment → Compiler

    Select Build Project Automatically option.

    Cpck on the OK button.

Build Project Automatically

Can I use NetBeans plugins in IntelpJ IDEA?

No, you cannot.

Is it possible to build NetBeans RCP apppcations with IntelpJ IDEA?

It is possible; however, you will not get the same kind of support that you get with NetBeans (wizards, menu actions, etc.). For more details, visit this.

Intelpj Idea - Migrating from Ecppse

Ecppse is yet another popular Java IDE. If you are a current user of Ecppse and want to migrate from it to IntelpJ, then this is a good starting point.

This chapter discusses how to import Ecppse projects in IntelpJ, its terminologies equivalent to Ecppse, popular shortcuts and frequently asked questions.

Import existing project

In this section, we will discuss how to import an existing project. Follow these steps to import the project −

    Navigate to File → New → Project from Existing Sources.

    Select your NetBeans project directory.

    When the Import Project wizard opens, select the Create project from existing sources option.

    Follow the on-screen instructions to continue.

IntelpJ vsEcppse terminology

The following table compares IntelpJ and NetBeans terminologies −

IntelpJ Ecppse
Project Workspace
Module Project
Facet Facet
Library Library
SDK JRE
Path variable Classpath variable

Popular shortcuts

IntelpJ is a keyboard-centric IDE. It provides shortcuts for most of the actions. The following table psts a few popular shortcuts −

Action Shortcut
Run java program ctrl+shift+F10
Organize imports ctrl+alt+o
System.out.println() Type sout and Press ctrj+j
Delete current pne ctrl + y
Search ctrl + shift + f
Generate getter and setter alt + insert
Format code ctrl + alt + l
Comment out code ctrl + /
Go to pne ctrl + g
Go to declaration ctrl + b
Rename shift+F6
Move pnes ctrl + shift + up/down

Debugger shortcuts

The following table psts down commonly used debugger shortcuts −

Debug action Shortcut
Debug a program Shift + F9
Choose configuration and debug Shift+Alt+F9
Step over F8
Step into F7
Smart step into Shift + F7
Step out Shift + F8
Force step over Shift+Alt+F8
Force step into Shift+Alt+F7
Resume program F9
Evaluate expression Alt+F8
Toggle breakpoints Ctrl+F8
View breakpoints Ctrl+Shift+F8

FAQsand Tips

In this section, we will see a few Frequently Answered Questions and tips. The FAQs and tips are as follows −

Use Ecppse Compiler

While Ecppse uses its own compiler, IntelpJ IDEA uses the javac compiler bundled with the project JDK. If you want to use the Ecppse compiler −

    Navigate to File → Settings → Build, Execution, Deployment → Compiler → Java Compiler.

    Select the required compiler from User compiler dropdown.

Ecppse Compiler

Ecppse Keymap

For Ecppse users who prefer not to learn new shortcuts, IntelpJ IDEA provides the Ecppse keymap that closely mimics its shortcuts −

    Navigate to File → Settings → Keymap option.

    Select Ecppse from Keymap dropdown.

Ecppse Keymap

Code formatting

To import your Ecppse formatter settings −

    Navigate to File → Settings → Editor → Code Style → Java.

    Select the Ecppse XML profile.

Ecppse Formatter Settings

Working with Build Tools

Like Ecppse, IntelpJ does not provide visual forms for editing Maven/Gradle configuration files.

Once you have imported/created your Maven/Gradle project, you are free to edit its pom.xml/build.gradle files directly in the text editor.

Advertisements