Theory:IDEA
# IntelliJ IDEA
IntelliJ IDEA is an intelligent, context-aware IDE for working with Java and other JVM languages like Kotlin, Scala, and Groovy on all sorts of applications. It has an ergonomic user interface, supports a lot of plugins, and provides a very powerful automatic code completion feature. IntelliJ IDEA has three editions: community, enterprise, and educational. All editions support multiple programming languages, including Java, Kotlin, Scala, and some others. The educational edition has a convenient functionality for downloading programming problems from the Hyperskill platform and checking your solutions directly from the IDEA. However, the community edition is enough to complete any project.
The logo of IntelliJ IDEA
If you want to know more about this IDE, please, visit the official website (opens new window). You can also learn about its more powerful features (opens new window).
# Creating the first project in IntelliJ IDEA
Let's write some text using IntelliJ IDEA. Here we assume that you have the community edition already installed on your computer. The other editions have minor differences in the interface.
\1. If no project is currently open in IntelliJ IDEA, click Create New Project on the Welcome screen. Otherwise, select File | New | Project. As a result, the New Project wizard opens.
The color scheme of your window may be different. Later, in the IDEA Settings paragraph, is a description of how to change it.
\2. In the panel on the left, select your language (for example, Java or Kotlin). There is also an option to create an empty project without any language support:
You may see additional options, like the JDK (Java Development Kit), that you may want to modify for your project. Just leave them unchanged for now.
\3. The next pages may propose different templates. Code templates are prewritten snippets of code provided by the IDE. Now we are going to study the very basics of IntelliJ IDEA, and do everything from scratch, so we aren't selecting any of the options. Just leave the default.
\4. On the final page, specify the project name (e.g. HelloWorld
). If necessary, you can change the project location on disk, but you can also use one suggested by IntelliJ IDEA.
\5. Click Finish.
Wait while IntelliJ IDEA creates the project. When this process is complete, the structure of your new project is shown in the Project tool window.
Let's take a look at the project structure on the left side of the window.
There are two top-level nodes:
- HelloWorld. This node represents your project module. The
.idea
folder and the fileHelloWorld.iml
are used to store configuration data for your project and module respectively. The foldersrc
is for your source code. - External Libraries. This is a category that represents all the "external" resources necessary for your development work. The standard files of your project language are placed there. Also, you can add other resources manually.
# Writing
Now we are going to write a text for the Hello World project.
\1. In the Project tool window, select the src
folder and select File | New, or right-click the folder src
and select New from the context menu.
\2. In the New menu, select File.
\3. In the New File dialog that opens, type text.txt
in the text field. Press Enter to create the file.
Now, you can see this file in the src
folder. At the same time, the file opens in the editor. So, we've just created a text file and in the future, you can use the same way to create source code files for your language.
We are to create something like this:
This is my test text file in IDEA.
Or is there a mistake?
2
3
But do not rush! Let's do it gradually, step by step.
As you see, there is a typo. And our IDE warns us about it:
There are many features of the IDEA. Now we want to introduce you to one called "Context actions". Place the cursor at the wrong word, press Alt+Enter, select Typo: Change to... with arrows and press Enter, and finally select the correct word from the list and press Enter again. The typo disappears 😃
IDEA supports other context actions for code, give it a try.
Congratulations! You have written your probably first text in IntelliJ IDEA and understood that there is a hidden power. You can always refer to the more complete official tutorial (opens new window). We especially recommend reading about templates (opens new window) and code completion (opens new window).
# IDEA Settings
IntelliJ IDEA has a lot of settings that can be configured as you wish. Go to File | Settings. There are many sections in the open Settings tab.
As an example, please go to Appearance & Behavior | Appearance and choose different themes. In this lesson, we use Darcula.
Note: If you would like to find something in the settings, use the search box as shown below.
# How to start my program?
Of course, you can create and run your programs in IDEA. Just create a new language-specific file, write content, find the green triangle "run" button ( ), and click it.
Sometimes, your program cannot be started from IDEA for various reasons.
- Make sure your program contains the
main
method. If not, then add it. - The source code should be placed inside the
src
directory, not next to it. - Sometimes no JDK is selected. To fix this, go to File | Project Structure | Project settings | Project and then set your JDK in the Project SDK section.
If you have another problem, please write it in the comments or Google it.
# Conclusion
IntelliJ IDEA is one of the best IDEs for Java and JVM languages. It allows programmers to easily work and code while having convenient access to all of its functions. Features like automatic code completion and ergonomic UI make the working experience quite pleasant.