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/03_building-with-eclipse.md
+24-22Lines changed: 24 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,15 +26,15 @@ author: ["DanielSchmid"]
26
26
27
27
The Eclipse IDE (or Eclipse for short) is a commonly used application that provides tooling that helps developers write, run and debug Java code. This article describes how to get started with Eclipse for developing Java applications.
28
28
29
-
The easiest way to install Eclipse is to download and run the Eclipse installer from [this site](https://www.eclipse.org/downloads/packages/installer). This provides multiple options for packages to install. In most cases, `Eclipse IDE for Java Developers` is a good installation for Java development.
29
+
The easiest way to install Eclipse is to download and run the Eclipse installer from [this site](https://www.eclipse.org/downloads/packages/installer). This provides multiple options for packages to install. In most cases, `Eclipse IDE for Java Developers` is a good installation for Java development.
Upon selecting a workspace, it will show a Welcome screen presenting you with mutliple options. For example, there is an option giving you an interactive tutorial showing you how to create a simple Hello-World application.
37
+
Upon selecting a workspace, it will show a Welcome screen presenting you with mutliple options. For example, there is an option giving you an interactive tutorial showing you how to create a simple Hello-World application.
@@ -43,19 +43,20 @@ This article will show you how to create Java projects manually so you can close
43
43
<aid="creating"> </a>
44
44
## Creating a Java Project
45
45
46
-
After installing Eclipse you should have an empty workspace. In order to create a new Java project, click on the `File` toolbar in the top left corner of the Eclipse window and select `New` > `Java Project`.
46
+
After installing Eclipse you should have an empty workspace. In order to create a new Java project, click on the `File` toolbar in the top left corner of the Eclipse window and select `New` > `Java Project`.
47
47
48
48
[](/assets/images/eclipse/file_create_project.png)
49
49
50
50
This will then open up a dialog window that allows you to configure your project. You will need to enter a name next to `Project name:` at the top. For example, you can choose the name `HelloWorld`. In the `Module` section at the bottom, disable the option `Create module-info.java file`. You can configure a custom Java installation (commonly referred to as the *JDK* or Java Development Kit) in the `JRE` box.
This creates a Java project that is shown on the left side of the Eclipse window. When expanding this project, there should be a folder named `src`. Java classes can be created inside this directory by right-clicking on it and selecting `New` > `Class`.
54
+
This creates a Java project that is shown on the left side of the Eclipse window. When expanding this project, there should be a folder named `src`. Java classes can be created inside this directory by right-clicking on it and selecting `New` > `Class`.
This opens a dialog similar to the project creation dialog. It allows specifying various options about the class you want to create. For now, you will need to enter a class name like `HelloWorld`. If you want to, you can also configure a package which can be used to group multiple classes together.
58
+
This opens a dialog similar to the project creation dialog. It allows specifying various options about the class you want to create. For now, you will need to enter a class name like `HelloWorld`. If you want to, you can also configure a package which can be used to group multiple classes together.
59
+
59
60
[](/assets/images/eclipse/java_class_creation.png)
60
61
61
62
<aid="content_assist"> </a>
@@ -67,11 +68,11 @@ For example, typing `main` in a class followed by pressing `Ctrl`+`Space` sugges
67
68
68
69
[](/assets/images/eclipse/content_assist_main.png)
69
70
70
-
Inside methods, Eclipse can suggest changing `sysout` to a `System.out.println();` statement.
71
+
Inside methods, Eclipse can suggest changing `sysout` to a `System.out.println();` statement.
71
72
72
73
[](/assets/images/eclipse/content_assist_sysout.png)
73
74
74
-
Furthermore, it can complete class and method names.
75
+
Furthermore, it can complete class and method names.
75
76
76
77
[](/assets/images/eclipse/content_assist_suggest_class.png)
77
78
@@ -81,32 +82,32 @@ Furthermore, it can complete class and method names.
81
82
<aid="run"> </a>
82
83
## Running Your Program
83
84
84
-
In order to run a Java application, you first need to have a class with a `main` method. You can right-click the class in the package explorer or right-click in the editor where you are writing the code for the class and select `Run as` > `Java application`.
85
+
In order to run a Java application, you first need to have a class with a `main` method. You can right-click the class in the package explorer or right-click in the editor where you are writing the code for the class and select `Run as` > `Java application`.
85
86
86
-
[](/assets/images/eclipse/run_as_editor.png)
87
+
[](/assets/images/eclipse/run_as_editor.png)
87
88
88
89
[](/assets/images/eclipse/run_as_package_explorer.png)
89
90
90
91
Alternatively, you can run the application using the Run [](/assets/images/eclipse/run_button.png) button in the toolbar. [](/assets/images/eclipse/run_buttons_toolbar.png)
91
92
92
-
When running the program, Eclipse should show the output of the program in the `Console` view.
93
+
When running the program, Eclipse should show the output of the program in the `Console` view.
93
94
94
95
[](/assets/images/eclipse/console_output.png)
95
96
96
97
<aid="errors"> </a>
97
98
## Dealing with Compilation Errors and Warnings
98
99
99
-
When Eclipse detects a compilation error, the relevant lines are underlined in red. When hovering over the line with the error or the error icon to the left of the said line, Eclipse provides information about what went wrong and also suggests how to fix the error. However, in many cases there are multiple ways to get rid of the error. You need to carefully check whether the suggestions are actually matching what you want to do. After all, IDEs cannot predict your intent.
100
+
When Eclipse detects a compilation error, the relevant lines are underlined in red. When hovering over the line with the error or the error icon to the left of the said line, Eclipse provides information about what went wrong and also suggests how to fix the error. However, in many cases there are multiple ways to get rid of the error. You need to carefully check whether the suggestions are actually matching what you want to do. After all, IDEs cannot predict your intent.
100
101
101
102
[](/assets/images/eclipse/compilation_error.png)
102
103
103
-
Furthermore, Eclipse shows a list of errors in the `Problems` view. If this view is not displayed, it can be shown using the menu `Window` > `Show View` > `Problems`.
104
+
Furthermore, Eclipse shows a list of errors in the `Problems` view. If this view is not displayed, it can be shown using the menu `Window` > `Show View` > `Problems`.
[](/assets/images/eclipse/problems_view.png)
108
109
109
-
As with Errors, Eclipse can also detect code that compiles but likely contains some issues or is pointless. In this case, Eclipse will display a warning.
110
+
As with Errors, Eclipse can also detect code that compiles but likely contains some issues or is pointless. In this case, Eclipse will display a warning.
110
111
111
112
[](/assets/images/eclipse/warning.png)
112
113
@@ -117,15 +118,15 @@ As with Errors, Eclipse can also detect code that compiles but likely contains s
117
118
118
119
When a program doesn't do what you expect it to do, you might want to debug it. The process of debugging is explained in [this article](id:debugging). Eclipse provides a lot of functionality making it easy to debug Java applications.
119
120
120
-
In order to debug an application, you need to set a breakpoint. When the program gets to executing the line with the breakpoint, it will temporarily stop ("suspend"), allow you to inspect its current state and step through the program. To set a breakpoint, you need to double-click on the area to the left of the line you want to suspend the program at. After doing that, a blue dot should appear there.
121
+
In order to debug an application, you need to set a breakpoint. When the program gets to executing the line with the breakpoint, it will temporarily stop ("suspend"), allow you to inspect its current state and step through the program. To set a breakpoint, you need to double-click on the area to the left of the line you want to suspend the program at. After doing that, a blue dot should appear there.
121
122
122
123
[](/assets/images/eclipse/breakpoint.png)
123
124
124
-
When running a program normally, it will ignore all breakpoints. For debugging, you need to run the program in debug mode. This can be done by clicking on the green button with the bug icon [](/assets/images/eclipse/debug_button.png) next to the run button or using `Debug As` > `Java Application`.
125
+
When running a program normally, it will ignore all breakpoints. For debugging, you need to run the program in debug mode. This can be done by clicking on the green button with the bug icon [](/assets/images/eclipse/debug_button.png) next to the run button or using `Debug As` > `Java Application`.
125
126
126
127
[](/assets/images/eclipse/debug_button_in_toolbar.png)
127
128
128
-
When the program execution gets to a breakpoint in debug mode, Eclipse will ask you to switch to the Debug perspective. This perspective gives you more information about the program you are currently debugging so you likely want to do this and click on the `Switch` button.
129
+
When the program execution gets to a breakpoint in debug mode, Eclipse will ask you to switch to the Debug perspective. This perspective gives you more information about the program you are currently debugging so you likely want to do this and click on the `Switch` button.
129
130
130
131
[](/assets/images/eclipse/debug_perspective_switch.png)
131
132
@@ -153,7 +154,7 @@ public class Person {
153
154
}
154
155
```
155
156
156
-
When right-clicking in that class, there is an option called `Source` providing various ways to generate code. Here, we can select `Generate Getters and Setters...` in order to generate accessor methods for the fields in the `Person` class.
157
+
When right-clicking in that class, there is an option called `Source` providing various ways to generate code. Here, we can select `Generate Getters and Setters...` in order to generate accessor methods for the fields in the `Person` class.
157
158
158
159
[](/assets/images/eclipse/context_generate_getters_setters.png)
159
160
@@ -190,7 +191,8 @@ public class Person {
190
191
}
191
192
```
192
193
193
-
Similarly, it is possible to generate the `hashCode` and `equals` methods using the menu `Source` > `Generate hashCode() and equals()...`.
194
+
Similarly, it is possible to generate the `hashCode` and `equals` methods using the menu `Source` > `Generate hashCode() and equals()...`.
195
+
194
196
[](/assets/images/eclipse/generate_hashcode_equals.png)
195
197
196
198
This also opens a window which allows to select the fields to include in the `hashCode` and `equals` methods.
@@ -244,7 +246,7 @@ public class Person {
244
246
```
245
247
246
248
Another method that is often generated is `toString()` which returns a `String` representation of the object.
247
-
To generate that method, select `Generate toString()...` in the `Source` menu.
249
+
To generate that method, select `Generate toString()...` in the `Source` menu.
When working on Java applications, it is often necessary to change existing code in various ways while preserving functionality. Eclipse supports developers doing that by providing various refactoring options. An example of that is renaming class, methods or fields. This can be done by clicking on a class, method or variable name, right-clicking and selecting `Refactor` > `Rename`.
312
+
When working on Java applications, it is often necessary to change existing code in various ways while preserving functionality. Eclipse supports developers doing that by providing various refactoring options. An example of that is renaming class, methods or fields. This can be done by clicking on a class, method or variable name, right-clicking and selecting `Refactor` > `Rename`.
It is then possible to change to name to something different and confirming it using the `Enter` key. This also updates all references to the renamed element.
316
+
It is then possible to change to name to something different and confirming it using the `Enter` key. This also updates all references to the renamed element.
315
317
316
318
[](/assets/images/eclipse/rename_box.png)
0 commit comments