Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

IntelliJ IDEA is a popular integrated development environment (IDE) for Java programming. It’s best known for its powerful features and user-friendly interface. To count lines of Java code in IntelliJ IDEA, we can use built-in tools or third-party plugins.

In this tutorial, we’ll explore several ways of counting lines of Java code using IntelliJ IDEA. For a profound understanding, we’ll look at each method with screenshots.

2. Counting Lines of Java Code Using Statistic Plugin

Statistic is a third-party plugin for IntelliJ IDEA. It’s important to note that it isn’t pre-installed in the IntelliJ idea by default. However, we can install it from the plugin marketplace to use its code analysis and line-counting features.

For this purpose, first, let’s open the IntelliJ IDEA settings by pressing CTRL+ALT+S or by navigating to the File tab and clicking on the Settings option:

 

open settings

Now we go to the Plugin tab, type statistic in the Search bar, and finally click on the Install button under the Statistic plugin to install the selected plugin:

 

install the statistic plugin

After installing the Statistic plugin, we restart the IDE to ensure it works correctly. The plugin icon appears at the bottom left side of the IntelliJ Idea. To demonstrate how it works, let’s click on it to open the Overview:

 

open the statistic overview

The Statistic plugin shows there are a total of 15 lines in our code. Apart from the line count, it also shows the file size, minimum size, maximum size, etc. Moreover, we can navigate to the java tab for more precise results:

 

java tab

The java tab shows the total lines, source code lines, commented lines, etc.

In IntelliJ IDEA, Search is a built-in feature that enables us to search for specific text within a file, project, or across multiple files. More specifically, to count lines of Java code using the Search feature, we need to use regular expressions like \n or \n+.

For instance, we can use keyboard shortcut keys CTRL+F to search within the current file and CTRL+SHIFT+F to search across the entire project or multiple files:

open search feature

Let’s click on the .* icon in the search box to switch to Regex mode:

 

regex mode

Now we can use \n to count the total lines of Java code, including empty as well as non-empty lines:

 

total lines

The output shows that we’re currently on line 4 out of a total of 14 lines. Similarly, we can use the regex \n+ to count only non-empty lines:

 

non empty lines

The output shows that there are a total of 13 non-empty lines in this Java file.

The Statistic plugin is suited for users who prefer automated checks and work with larger codebases. On the other hand, Regex in Search is ideal for users who don’t want to install additional plugins and are comfortable with manual input, particularly in smaller codebases.

To illustrate this in detail, let’s compare the Statistic plugin with regex in the search feature:

Feature Statistic Plugin Regex in Search
Installation We need to install it from the plugin marketplace. Pre-installed in IntelliJ IDEA.
Ease of Use Provides a simple interface for code analysis after installation. It requires a basic understanding of regular expressions.
Line Counting Options Counts total lines, source lines, comment lines, blank lines, etc. Counts total lines or non-empty lines based on the regex used.
Output Detailed breakdown of line types and file statistics. Displays the current line number and the total lines in a file or a project.
Customization Designed specifically for code statistics with file size info. More manual but flexible for custom searches using regex.
Use Case Best for detailed code analysis, especially when needing precision. Suitable for quick, simple line counting without installing additional plugins.
Performance Efficient for larger projects, providing a comprehensive view. May be slower or tedious for large projects due to manual input.
Advanced Metrics Provides additional metrics like file size, and minimum or maximum size. Lacks additional metrics beyond basic line counting.

Overall, the Statistic plugin provides detailed, user-friendly analysis, while Regex in the Search feature offers a quick, flexible method for basic line counting.

5. Conclusion

In this article, we explored two methods for counting lines of Java code in IntelliJ IDEA: the third-party Statistic plugin and the built-in Search feature with regex. Specifically, the Statistic plugin offers detailed and user-friendly analysis, making it ideal for comprehensive code metrics and larger projects.

In contrast, using regex in the Search feature provides a quick, flexible alternative for basic line counting without requiring additional installations. Finally, choosing between these methods depends on our need for detailed analysis or a simple, immediate count.

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW