<- Blog Home

IntelliJ IDEA tips

Here are some IntelliJ IDEA tips.

Coding

  • Naming convention - class, method, package, fields and variables

  • Code formatting - IntelliJ IDEA has a built-in code formatting feature that can help you format your code according to a particular style. You can use the Code menu to access code formatting options, or use the keyboard shortcut (Ctrl+Alt+L).You can use (Ctrl+Shift+Alt+L) to open the format dialog

  • Code commenting - IntelliJ IDEA has a feature that allows you to quickly comment and uncomment code. You can use the Ctrl+/ shortcut to toggle comments, or the Ctrl+Shift+/ shortcut to add block comments.

  • Code folding - IntelliJ IDEA has a feature that allows you to collapse code blocks to make it easier to read and navigate. You can use the Ctrl+Shift+NumPad+ shortcut to fold code blocks, and the Ctrl+Shift+NumPad- shortcut to unfold them.

  • Code generation - IntelliJ IDEA has a feature called Code Generation that allows you to generate code for various use cases. You can use the Generate command (Alt+Insert) to generate code for constructors, getters and setters, and other use cases.

  • Code completion - IntelliJ IDEA has excellent code completion features that can help you write code faster. You can use the Ctrl+Space shortcut to get code completion suggestions.

Code navigation -

IntelliJ IDEA has several features to help you navigate code, such as Go to Declaration (Ctrl+B), Go to Implementation (Ctrl+Alt+B), and Find Usages (Alt+F7). These features can help you quickly find where a particular method or variable is defined or used. (Ctrl+Alt+Left) - Navigate back and Navigate Forward (Ctrl+Alt+Right)

"Go to declaration" (Ctrl + click) is used to navigate to the declaration of a variable, method, or class, typically within the same file or in a file within the same project. This feature is useful when you want to understand how a variable or method is defined, or if you want to quickly find where a particular piece of code is implemented.

"Go to implementation" is used to navigate to the implementation of an interface or an abstract class method. This feature is useful when you want to see how an interface method is implemented in a specific class, or if you want to find all the places where a particular interface or abstract class method is implemented in the project.

In both cases, these features can save time and help developers navigate and understand complex codebases. They are often bound to keyboard shortcuts for quick and easy access.

Code snippets and live templates

IntelliJ IDEA has a feature called Code Snippets that allows you to quickly insert code snippets into your project. You can use the Insert Live Template command (Ctrl+J) to insert a code snippet. Some popular snippets are

  • soutv - print variable
  • sout - System.out.println("Hello")
  • itar - Iterate array
  • itco - Iterate elements of collection
  • itli - Iterate elements of list
  • psvm - public static void main
  • fori
  • foreach

Some POM file shortcuts

  • dep
  • pl
  • repo

Maven, gradle support

Maven and gradle plugins are pre-installed. In Maven plugin, you can do below operations.

  • Execute specific maven goal
  • Execute goal with system properties
  • Add and/or Modify run configuration for maven command
  • View dependencies and analyze them
  • You can exclude conflicting dependencies io.rest-assured rest-assured 5.3.0 org.apache.httpcomponents httpclient

Run configurations

IntelliJ IDEA has a feature called Run Configurations that allows you to configure and run your applications with different settings. You can use the Run/Debug Configurations dialog to create and manage run configurations.

Test runners and Executions

IntelliJ IDEA has support for various test runners, such as JUnit and TestNG. You can use the Run menu to run your tests and view the results. This is possible due to JUnit and TestNG plug-ins.

Debugging

IntelliJ IDEA also has a Debug configurations feature that allows you to configure how your code is debugged. You can use the Run menu to create and manage debug configurations.

  • add breakpoints
  • view breakpoints
  • toggle breakpoints
  • step over/into/out
  • resume program
  • mute breakpoints
  • add watches
  • evaluate expression

Important Keyboard shortcuts

IntelliJ IDEA has a lot of keyboard shortcuts that can help you navigate the IDE faster. Some of the most useful ones are

  • double shift - Search files, classes
  • Ctrl+Shift+F (Find in Path)
  • Ctrl+Shift+R (Replace in Path)

Local history

IntelliJ IDEA has a Local History feature that allows you to view and revert changes made to your code. You can use the Local History tool window to view the history of changes made to a file. To view history of file, just right click and select local history -> Show history You can do below things with local history

  • Compare current file with old versions of file
  • Add or remove certain code
  • Navigate through differences
  • Reverting changes

Version control integration

IntelliJ IDEA has built-in support for various version control systems, including Git, Subversion, and Mercurial. You can use the Version Control tool window to manage your version control operations.

Here is the list of features provided by IntelliJ IDEA

  • clone repo
  • create branch
  • merge branch
  • view local and remote branches
  • Perform git operation on specific file
  • Create gist to be uploaded to github
  • Pull and push from git system like github
  • Open file in github
  • add files, commit and push changes
  • Skip analyze code and to do items
  • view git log for each branch

Project and module settings

  • Changing JAVA SDK
  • Changing language level or version

The project SDK in IntelliJ IDEA refers to the software development kit that is used to build the project, while the language level refers to the version of the programming language used in the project.

For example, in a Java project, the project SDK would typically refer to the version of the Java Development Kit (JDK) that is installed on the developer's computer and used to compile the code. This setting can affect the syntax and features available in the project.

On the other hand, the language level would specify the version of the Java language that the project is written in. This can affect which language features are available and how the code is compiled.

Both the project SDK and language level are important settings that can affect the behavior of the code in the project, and they can be configured in the Project Structure dialog in IntelliJ IDEA.

If you are using the Java Compiler (javac) command-line tool to compile your Java code outside of Maven, it will use the version of Java that is specified in the JAVA_HOME environment variable. If this variable is not set, it will use the default Java version installed on your system.

Similarly, If you are using a build tool other than Maven, such as Gradle or Ant, the version of Java used to compile the code may depend on the configuration of the build tool.

It's generally a good practice to explicitly configure the Java version used to compile your code to ensure consistency and compatibility across different systems. The Maven Compiler Plugin provides an easy way to do this within a Maven project by specifying the source and target versions in the pom.xml file.

Refactoring

  • Renaming file, method name, variables (short cut key - Shift + F6)
  • Safe delete
  • Extract method
  • Introduce variable or field
  • Move class or packages

Integration with other tools using plugins

IntelliJ IDEA can be integrated with other tools such as JIRA, GitHub, and other issue tracking systems. You can use the plugins section of the Settings/Preferences dialog to install and configure integrations.

IntelliJ IDEA has a large number of plugins that can extend its functionality. You can find and install plugins from the Settings/Preferences dialog (Ctrl+Alt+S). Some popular plugins are

  • cucumber for java
  • gherkin

Parameter hints

IntelliJ IDEA has a feature called Parameter Hints that displays the parameter names of a method call. You can use the Ctrl+P shortcut to display the parameter hints.

Find usages

IntelliJ IDEA has a powerful Find Usages feature that allows you to find all references to a method, class, or variable. You can use the Alt+F7 shortcut to find usages.

tabs

  • split tabs
  • pin tabs

Test coverage

IntelliJ IDEA has a test coverage feature that allows you to determine how much of your code is covered by your tests. You can use the Run menu to run your tests with test coverage, and then view the coverage results in the Coverage tool window.

Scratch files

IntelliJ IDEA has a feature called Scratch Files that allows you to create temporary files to experiment with code or take notes. You can use the Scratch Files tool window to create and manage scratch files.

Multiple cursors

IntelliJ IDEA allows you to use multiple cursors to edit your code more efficiently. You can use the Alt+Shift+Click shortcut to add multiple cursors to your code.

Code style

IntelliJ IDEA has a built-in code style feature that allows you to configure your code formatting and style preferences. You can use the Code Style section of the Settings/Preferences dialog to configure your code style preferences.

Quick documentation

IntelliJ IDEA has a feature called Quick Documentation that allows you to view documentation for classes and methods without leaving the editor. You can use the Ctrl+Q shortcut to display the documentation.

Code coverage

IntelliJ IDEA has a code coverage feature that can help you determine how much of your code is covered by your tests. You can use the Run menu to run your tests with code coverage, and then view the coverage results in the Coverage tool window.

Key promoter

IntelliJ IDEA has a plugin called Key Promoter that can help you learn and remember keyboard shortcuts. The plugin will display a popup with the keyboard shortcut whenever you perform an action using the mouse.

Live editing

IntelliJ IDEA has a feature called Live Editing that allows you to see changes to your code in real-time as you make them. You can use the Live Edit feature to make changes to your code and see the changes in your browser without refreshing the page.

Spring framework support

IntelliJ IDEA has excellent support for the Spring framework. You can use the Spring Assistant tool window to manage your Spring configuration files, and the Spring Diagrams feature to view the dependencies between your Spring components.

Learning resources - (Ctrl+Shift+F1)

IntelliJ IDEA has built-in learning resources to help you improve your skills as a developer. You can use the Learn IntelliJ IDEA command (Ctrl+Shift+F1) to access the learning resources.

Code collaboration

IntelliJ IDEA has built-in support for code collaboration. You can use the Code With Me feature to collaborate with other developers in real-time, or use the GitHub integration to collaborate on code changes.

Docker support

IntelliJ IDEA has built-in support for working with Docker containers. You can use the Docker tool window to manage your Docker containers and images.

Custom shortcuts

IntelliJ IDEA allows you to create custom keyboard shortcuts for frequently used actions. You can create custom shortcuts in the Keymap section of the Settings/Preferences dialog (Ctrl+Alt+S).

Multiple cursors

IntelliJ IDEA has a feature called Multiple cursors that allows you to edit multiple lines of code at the same time. You can use the Alt+Shift+Click shortcut to add multiple cursors, and then edit the code simultaneously.

Database support

IntelliJ IDEA has built-in support for working with databases. You can use the Database tool window to manage your database connections, execute SQL queries, and view database tables.

Remote development

IntelliJ IDEA has support for remote development, which allows you to work with code on a remote server. You can use the Remote Hosts tool window to manage your remote connections and work with files on the remote server.

Code analysis

IntelliJ IDEA has a code analysis feature that can help you identify potential issues in your code. You can use the Ctrl+Alt+Shift+I shortcut to run code analysis.

Web development and Automation testing

solutions delivered!!