You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/pages/learn/01_tutorial/01_your-first-java-app/02_building-with-intellij-idea.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,12 +30,14 @@ author: ["MaritvanDijk"]
30
30
31
31
<aid="overview"> </a>
32
32
## Overview
33
+
33
34
An IDE (Integrated Development Environment) allows you to quickly create applications, by combining a source-code editor with the ability to compile and run your code, as well as integration with build, test and debug tools, version control systems, and so on. Finally, an IDE will let you search and navigate your codebase in ways your file system won’t.
34
35
35
36
One of the [most widely used integrated development environments (IDEs)](https://www.jetbrains.com/lp/devecosystem-2023/java/#java_ide) for Java is IntelliJ IDEA. Its user-friendly interface, rich feature set, and vast ecosystem make it an ideal environment for beginners to learn and grow as developers. In this tutorial you’ll learn how to use some of its features to simplify your development process and accelerate your learning curve with Java programming.
36
37
37
38
<aid="install"> </a>
38
39
## Installing IntelliJ IDEA
40
+
39
41
To install IntelliJ IDEA, download the version you want to use from the [IntelliJ IDEA website](https://www.jetbrains.com/idea/) and follow the instructions.
40
42
Note that IntelliJ IDEA is available in two editions:
41
43
-**_IntelliJ IDEA Community Edition_** - free and open-source. It provides all the basic features for Java development.
@@ -51,6 +53,7 @@ To start working with Java, you will need to install a JDK. You can do this your
51
53
52
54
<aid="new"> </a>
53
55
## Creating a new project
56
+
54
57
We can create a new project from the **Welcome** screen, or we can go to **File | New | Project** in the main menu.
@@ -94,6 +97,7 @@ You can add a new Java file using the shortcut **⌘N** (on macOS) or **Alt+Inse
94
97
95
98
<aid="edit"> </a>
96
99
## Writing and editing code
100
+
97
101
The entrypoint to execute your `HelloWorld` Java program is the main method. Add the main method by typing:
98
102
```java
99
103
publicstaticvoid main(String[] args) {
@@ -126,6 +130,7 @@ IntelliJ IDEA will manage the formatting of your code as you write it. If needed
126
130
127
131
<aid="run"> </a>
128
132
## Running your application
133
+
129
134
A major benefit of using an IDE is that you can directly run your code without having to first manually compile it on the command line.
130
135
131
136
You can run the `HelloWorld` application directly from the editor, by clicking the green run button in the gutter near the class declaration, or using the shortcut **⌃⇧R** (on macOS) or **Ctrl+Shift+F10** (on Windows/Linux).
@@ -146,6 +151,7 @@ The popup **Run/Debug Configurations** appears and there you can modify JVM opti
146
151
147
152
<aid="test"> </a>
148
153
## Testing
154
+
149
155
Testing your code helps you to verify that the code does what you expect it to do. You can run your application and test it yourself, or add automated tests that can verify your code for you. Thinking about what to test and how, can help you to break a problem up into smaller pieces. This will help you get a better solution faster!
150
156
151
157
For example, let's say we have a `Calculator` class containing the following method that calculates the average of a list of values, and we want to make sure the average is calculated correctly:
@@ -210,6 +216,7 @@ In our example, we see that the second tests fails. We expected to get the value
210
216
211
217
<aid="debug"> </a>
212
218
## Debugging
219
+
213
220
We might want to see how our code runs, either to help us understand how it works and/or when we need to fix a bug or failing test, like the one above. We can run our code through the [debugger](https://www.jetbrains.com/help/idea/debugging-code.html) to see the state of our variables at different times, and the call stack - the order in which methods are called when the program executes. To do so, we must first add a [breakpoint](https://www.jetbrains.com/help/idea/using-breakpoints.html) to the code.
214
221
215
222
To add a breakpoint, click the gutter at the line of code where you want execution to stop. Alternatively, place the caret at the line and press **⌃F8** (on macOS) or **Ctrl+F8** (on Windows/Linux). We can run our test or application using the **Debug** option; either by right-clicking the **Run** button in the gutter and selecting the **Debug** option from the list, or by selecting the **Debug** button at the top right.
@@ -240,7 +247,7 @@ public class Calculator {
240
247
```
241
248
Now, when we run our tests, we see that they pass.
242
249
243
-
For more information on debugging, see [Debugging in Java](https://dev.java/learn/debugging/)
250
+
For more information on debugging, see [Debugging in Java](https://dev.java/learn/debugging/).
244
251
245
252
<aid="refactor"> </a>
246
253
## Refactoring code
@@ -259,12 +266,14 @@ Pull up the refactoring menu to see what is possible, using the shortcut **⌃T*
259
266
260
267
<aid="document"> </a>
261
268
## Documenting code
269
+
262
270
We can add documentation to our code. IntelliJ IDEA provides completion for documentation comments, which is enabled by default. Type `/**` before a declaration and press **Enter**. IntelliJ IDEA auto-completes the documentation comment for you.
263
271
264
272
IntelliJ IDEA provides a way for you to easily understand and read JavaDoc comments by selecting _Reader Mode_. **Toggle Reader Mode** in the editor using **^⌥Q** (on macOS) or **Ctrl+Alt+Q** (on Windows/Linux). Right-click the icon in the gutter to select **Render All Doc Comments** if you want all comments to show in reader mode.
265
273
266
274
<aid="navigation"> </a>
267
275
## Searching and navigating
276
+
268
277
IntelliJ IDEA also helps us by providing ways to navigate around our codebase, for example by going backwards and forwards between files, finding usages and declarations, finding interfaces and their implementations, viewing recently opened files and location, or even opening a window by name.
269
278
270
279
One popular way to search is [Search Everywhere](https://www.jetbrains.com/help/idea/searching-everywhere.html) (using **Shift** twice). Search everywhere allows you to search your project files and directories, as well as your project settings and IntelliJ IDEA settings.
@@ -277,6 +286,7 @@ Another popular way to search is [Find in Files](https://www.jetbrains.com/help/
277
286
278
287
<aid="summary"> </a>
279
288
## Summary
289
+
280
290
In this article, we’ve seen how IntelliJ IDEA can help you with code suggestions and completion while writing code, running your application, adding tests and using the debugger to help figure out how code is run, refactoring code, and more.
281
291
282
292
IntelliJ IDEA continues to improve and evolve, adding new features and offering new integration. You can sharpen your coding skills by taking a look at the [documentation](https://www.jetbrains.com/help/idea/getting-started.html), [blog](https://blog.jetbrains.com/idea/), [YouTube channel](https://www.youtube.com/intellijidea), or [guide](https://www.jetbrains.com/guide/java/).
0 commit comments