Skip to content

Commit bc04cd6

Browse files
committed
Doc: Update getting started with java tutorial
1 parent 64c57ff commit bc04cd6

11 files changed

+60
-8
lines changed

02_django/01_getting_started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $ cd demo_project
5454
```
5555
![Change Directory](/02_django/images/getting_started/cd_demo_folder.png)
5656

57-
It is recommended to install Django in a virtual environment. You can run:
57+
It is recommended to install Django in a virtual environment. Virtual environments are used to isolate the needs of one application from another, or from cluttering the OS. You can run the command below in your terminal:
5858

5959
```python
6060
$ python3 -m venv venv
@@ -158,7 +158,7 @@ In the terminal, I will run the command `tree` to see the project's structure.
158158

159159
You may not have this command installed. To use it, you will need to install it first. Thankfully, there is some instruction on the terminal on how to do the installation. Follow it and then re-run the `tree` command.
160160

161-
Above, you can see that we are currently in our initial project directory, denoted by the `.`. Our actual project is called `blog_app` and it has a few more files in it. In the top-level directory. There is also the `manage.py` file which acts as the entry point to the application.
161+
Above, you can see that we are currently in our initial project directory, denoted by the `.`. Our actual project is called `blog_app` and it has a few more files in it. In the top-level directory, there is also the `manage.py` file which acts as the entry point to the application.
162162

163163
### VS Code File Explorer
164164

03_java/01_getting_started_with_java.md

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ To build things using Java, you need the Java Development Kit (JDK). It is one o
1212
- [Install Your IDE](#install-your-ide)
1313
- [Install Java In Your Ubuntu OS](#install-java-in-your-ubuntu-os)
1414
- [Quickstart](#quickstart)
15+
- [Modify Path to New JDK](#changing-the-default-jdk)
1516

1617

1718
## Download JDK
1819

1920
I will show you how to install the open-source JDK (OpenJDK) from Amazon called the [Amazon Corretto](https://aws.amazon.com/corretto/?filtered-posts.sort-by=item.additionalFields.createdDate&filtered-posts.sort-order=desc). As of this writing, I will be showing you how to download [Amazon Corretto 17](https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html).
2021

21-
![Amazon Corretto JDK](/images/java/getting_started/download_jdk.png)
22+
![Amazon Corretto JDK](/03_java/images/getting_started/download_jdk.png)
2223

2324
You can choose to either use the terminal commands to download the JDK or you can click on the highlighted link to download directly from the site. Ensure that you download the file to a location you want, say in the home directory, for example.
2425

@@ -33,6 +34,10 @@ We will need to use an Integrated Development Environment when working with Java
3334

3435
## Install Java in Your Ubuntu OS
3536

37+
This can be done in two ways:
38+
39+
### Using apt
40+
3641
- To use the Corretto Apt repositories on Debian-based systems, such as Ubuntu, import the Corretto public key and then add the repository to the system list by using the following commands:
3742

3843
```java
@@ -46,6 +51,8 @@ We will need to use an Integrated Development Environment when working with Java
4651
$ sudo apt-get update; sudo apt-get install -y java-17-amazon-corretto-jdk
4752
```
4853

54+
### Manual download and installation
55+
4956
- Before you install the JDK, install the java-common package.
5057

5158
```java
@@ -114,18 +121,63 @@ When working with Java Projects, VS Code does not offer core support the way Int
114121
115122
At this point, you should already have the [Extension pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) installed. To create a Java Project, open VS Code.
116123
117-
![Open VS Code](/images/java/getting_started/open_vs_code.png)
124+
![Open VS Code](/03_java/images/getting_started/open_vs_code.png)
118125
119126
Select on "File Explorer" to access the "Create Java Project" button. Click on it.
120127
121-
![No build tools](/images/java/getting_started/no_build_tools.png)
128+
![No build tools](/03_java/images/getting_started/no_build_tools.png)
122129
123130
Select the "No build tools" option. This will open the location you want to create your project. Choose an appropriate location in your system.
124131
125-
![Name project](/images/java/getting_started/create_project.png)
132+
![Name project](/03_java/images/getting_started/create_project.png)
126133
127134
Once you have selected a location, give your project a name as seen in the input box. Press "Enter" to confirm.
128135
129-
![Java Project](/images/java/getting_started/java_project.png)
136+
![Java Project](/03_java/images/getting_started/java_project.png)
137+
138+
Notice that the project comes with a structure already. In the example above, I have already clicked on the `App.java` file. You can do the same. To run it, you can press the "play" button on the top-right, or `f5`. Alternatively, you can right-click on the file to access the command "Run Java". Select it and you will see the text "Hello World" displayed on the terminal.
139+
140+
## Changing the Default JDK
141+
142+
You may notice that when you run the script above, the default JDK 11 is used instead of the newly installed Amazon Corretto 17. Typically, this is an issue to do with the path to the jdk. If we want to use Amazon Corretto 17, then we need to modify our settings to point to this jdk.
143+
144+
145+
- Click on "Java Projects" at the bottom left of the VS Code's sidebar to access `...` more actions option.
146+
![More Actions](/03_java/images/getting_started/more_actions.png)
147+
148+
- Click on "Configure Java Runtime".
149+
![Java Version](/03_java/images/getting_started/java_version.png)
150+
- My VS Code is already configured to use Corretto 17, but by default, the version number may be 11. This is different from our installation efforts above. To change it to version 17, or whatever version you may have, we need to modify VS Code's configurations to point to Corretto 17.
151+
152+
- Get the path to Amazon Corretto. From your home directory, list the available JVMs:
130153
131-
Notice that the project comes with a structure already. In the example above, I have already clicked on the `App.java` file. You can do the same. To run it, you can press the "play" button on the top-right, or `f5`. Alternatively, you can right-click on the file to access the command "Run Java". Select it and you will see the text "Hello World" displayed on the terminal.
154+
```java
155+
// Navigate to the home directory
156+
$ cd ~
157+
158+
// Change directory
159+
$ cd /usr/lib/jvm
160+
161+
// List available JVMS
162+
/usr/lib/jvm$ ls
163+
164+
// My output
165+
default-java java-1.11.0-openjdk-amd64 java-11-openjdk-amd64 java-17-amazon-corretto
166+
```
167+
- The path we want is `/usr/lib/jvm/java-17-amazon-corretto`.
168+
- Open `settings.json` from the command pallette in VS Code by pressing "Ctrl + Shift + P".
169+
![User setting VS Code](/03_java/images/getting_started/user_settings.png)
170+
- Add the path to Amazon Corretto to the file
171+
![Add path](/03_java/images/getting_started/add_path.png)
172+
- The path is:
173+
```json
174+
"java.jdt.ls.java.home": "/usr/lib/jvm/java-17-amazon-corretto/"
175+
```
176+
- Save the modified fille and reload VS Code to apply the changes. If you open "Configure Runtime Java" as we did above, you should see that the version number has now changed to 17.
177+
- When you run any Java program, you will notice that our new path is being used the terminal:
178+
```java
179+
$ /usr/bin/env /usr/lib/jvm/java-17-amazon-corretto/bin/java -XX:+ShowCodeDetailsInExceptionMessages -cp /home/harry/software_development/java/practice_projects/expressions_statements/bin MainChallenge
180+
181+
// Output
182+
Your final score was 11600
183+
```
370 KB
Loading
178 KB
Loading
209 KB
Loading

0 commit comments

Comments
 (0)