IntelliJ IDEA
IntelliJ is certainly a surprising good and super productive IDE for Java programmers (after using Eclipse and NetBeans for many many years).
IntelliJ IDEA is an integrated development environment (IDE) written in Java for developing computer software written in Java, Kotlin, Groovy, and other JVM-based languages. It is developed by JetBrains (formerly known as IntelliJ).
IntelliJ IDEA has a free community version. It also has a paid Ultimate version, but you can get the Ultimate version free by registering it for education purpose, with a .edu account.
Install
Download (either the free community version or paid Ultimate) and install.
Launch ⇒ Take a quick onboarding tour ⇒ Start Java Tour.
First Java Project
First Java Project: click "New project" ⇒ Java ⇒ In "Name", enter "FirstJavaProject" ⇒ In "Build system", select "Maven" ⇒ Un-check "Add sample code" ⇒ Expand "Advanced settings" (used by Maven) ⇒ In "GroupId", enter your package name (e.g., com.nowhere
) ⇒ Create.
First Java Class
Expand "src
" ⇒ main
⇒ Right-click "java
" ⇒ New ⇒ Package ⇒ Enter "com.nowhere
" ⇒ Right-click "com.nowhere
" ⇒ New ⇒ Java Class ⇒ In "Name", enter "Hello
" to create "Hello.java
" in the editor.
In the editor ⇒ Position your cursor inside the class ⇒ Enter "m
" and select "main
" to generate main()
method ⇒ Enter "sout
" and hit enter to generate System.out.println()
.
Run the Java program
There is no need to do explicit compilation.
To run the program, click "Run" button beside the "Current File" on the top menu bar.
Debug the Java Program
To debug the program ⇒ First, set a breakpoint by clicking the line-number at the left margin (e.g., at the main()
). A red dot appears indicating a breakpoint.
Click the "Debug" button beside the "Current File" on the top menu bar.
You can then "Step Over", "Step Into", "Step Out", "Stop", "Resume" by clicking the buttons at the "Debug" pane menu bar. Similar to all other IDEs.
Tips and Tricks
[TODO]
Maven Build System
Check out the "pom.xml
" which is the configuration file for Maven. You can configure dependencies. For example, the following codes added "JUnit
<?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.nowhere</groupId>
<artifactId>JavaProject2</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
</dependency>
</dependencies>
</project>
Try the following program, which uses "Apache Commons Text" library. You do not need to download and install the external JAR files, which is handled by Maven automatically.
package com.nowhere;
import static org.apache.commons.text.StringEscapeUtils.escapeHtml4; // Apache Commons Text 1.12
public class Hello {
public static void main(String[] args) {
System.out.println(escapeHtml4("<hello&hello>"));
}
}