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
To create and modify Java program files—the code listings shown in this
176
+
book—you need a program called an *editor*. You'll also need the editor to
177
+
make changes to your system configuration files, which is sometimes required
178
+
during installation.
179
+
180
+
Programming editors vary from heavyweight *Integrated Development Environments*
181
+
(IDEs, like Eclipse, NetBeans and IntelliJ IDEA) to more basic text
182
+
manipulation applications. If you already have an IDE and are comfortable with
183
+
it, feel free to use that for this book.
184
+
185
+
Numerous explanations in this book are specific to IntelliJ IDEA so if you
186
+
don't already have an IDE you might as well start with IDEA. There are many
187
+
other editors; these are a subculture unto themselves and people sometimes get
188
+
into heated arguments about their merits. If you find one you like better, it's
189
+
not too hard to change. The important thing is to choose one and get
190
+
comfortable with it.
191
+
192
+
## The Shell
193
+
194
+
If you haven't programmed before, you might be unfamiliar with your operating
195
+
system *shell* (also called the *command prompt* in Windows). The shell harkens
196
+
back to the early days of computing when everything happened by typing commands
197
+
and the computer responded by displaying responses—everything was text-based.
198
+
199
+
Although it can seem primitive in the age of graphical user interfaces, a shell
200
+
provides a surprising number of valuable features.
201
+
202
+
To learn more about your shell than we cover here, see
203
+
[Bash Shell](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) for Mac/Linux
204
+
or [Windows Shell](https://en.wikipedia.org/wiki/Windows_shell).
205
+
206
+
### Starting a Shell
207
+
208
+
**Mac**: Click on the *Spotlight* (the magnifying-glass icon in the upper-right
209
+
corner of the screen) and type "terminal." Click on the application that looks
210
+
like a little TV screen (you might also be able to hit "Return"). This starts a
211
+
shell in your home directory.
212
+
213
+
**Windows**: First, start the Windows Explorer to navigate through your
214
+
directories:
215
+
216
+
-*Windows 7*: click the "Start" button in the lower left corner of the screen.
217
+
In the Start Menu search box area type "explorer" and then press the "Enter"
218
+
key.
219
+
220
+
-*Windows 8*: click Windows+Q, type "explorer" and then press the "Enter" key.
221
+
222
+
-*Windows 10*: click Windows+E.
223
+
224
+
Once the Windows Explorer is running, move through the folders on your computer
225
+
by double-clicking on them with the mouse. Navigate to the desired folder. Now
226
+
click the file tab at the top left of the Explorer window and select "Open
227
+
Windows Powershell." This opens a shell in the destination directory.
228
+
229
+
**Linux**: To open a shell in your home directory:
230
+
231
+
-*Debian*: Press Alt+F2. In the dialog that pops up, type 'gnome-terminal'
232
+
233
+
-*Ubuntu*: Either right-click on the desktop and select 'Open Terminal', or
234
+
press Ctrl+Alt+T
235
+
236
+
-*Redhat*: Right-click on the desktop and select 'Open Terminal'
237
+
238
+
-*Fedora*: Press Alt+F2. In the dialog that pops up, type 'gnome-terminal'
239
+
240
+
241
+
### Directories
242
+
243
+
*Directories* are one of the fundamental elements of a shell. Directories hold
244
+
files, as well as other directories. Think of a directory as a tree with
245
+
branches. If `books` is a directory on your system and it has two other
246
+
directories as branches, for example `math` and `art`, we say that you have a
247
+
directory `books` with two *subdirectories*`math` and `art`. We refer to them
248
+
as `books/math` and `books/art` since `books` is their *parent* directory.
249
+
Note that Windows uses backslashes rather than forward slashes to separate the
250
+
parts of a directory.
251
+
252
+
### Basic Shell Operations
253
+
254
+
The shell operations shown here are approximately identical across operating
255
+
systems. For the purposes of this book, here are the essential operations in a
256
+
shell:
257
+
258
+
-**Change directory**: Use `cd` followed by the name of the
259
+
directory where you want to move, or `cd ..` if you want to move
260
+
up a directory. If you want to move to a different directory while
261
+
remembering where you came from, use `pushd` followed by the different
262
+
directory name. Then, to return to the previous directory, just say
263
+
`popd`.
264
+
265
+
-**Directory listing**: `ls` (`dir` in Windows) displays all the files and
266
+
subdirectory names in the current directory. Use the wildcard `*` (asterisk) to
267
+
narrow your search. For example, if you want to list all the files ending in
268
+
".kt," you say `ls *.kt` (Windows: `dir *.kt`). If you want to list the
269
+
files starting with "F" and ending in ".kt," you say `ls F*.kt` (Windows:
270
+
`dir F*.kt`).
271
+
272
+
-**Create a directory**: use the `mkdir` ("make directory") command
273
+
(Windows: `md`), followed by the name of the directory you want to create.
274
+
For example, `mkdir books` (Windows: `md books`).
275
+
276
+
-**Remove a file**: Use `rm` ("remove") followed by the name of the file
277
+
you wish to remove (Windows: `del`). For example, `rm somefile.kt` (Windows:
278
+
`del somefile.kt`).
279
+
280
+
-**Remove a directory**: use the `rm -r` command to remove the files in
281
+
the directory and the directory itself (Windows: `deltree`). For example,
282
+
`rm -r books` (Windows: `deltree books`).
283
+
284
+
-**Repeat a command**: The "up arrow" on all three operating
285
+
systems moves through previous commands so you can edit and
286
+
repeat them. On Mac/Linux, `!!` repeats the last command and
287
+
`!n` repeats the nth command.
288
+
289
+
-**Command history**: Use `history` in Mac/Linux or press the F7 key in Windows.
290
+
This gives you a list of all the commands you've entered. Mac/Linux provides
291
+
numbers to refer to when you want to repeat a command.
292
+
293
+
### Unpacking a Zip Archive
294
+
295
+
A file name ending with `.zip` is an archive containing other files in a
296
+
compressed format. Both Linux and Mac have command-line `unzip` utilities, and
297
+
it's possible to install a command-line `unzip` for Windows via the Internet.
298
+
299
+
However, in all three systems the graphical file browser (Windows Explorer, the
300
+
Mac Finder, or Nautilus or equivalent on Linux) will browse to the directory
301
+
containing your zip file. Then right-mouse-click on the file and select "Open"
302
+
on the Mac, "Extract Here" on Linux, or "Extract all ..." on Windows.
303
+
304
+
# Appendix B: Testing
305
+
306
+
The test system is built in so that we (the authors) can verify the correctness
307
+
of what goes into the book.
308
+
309
+
You don't need to run the tests, but if you want to, you can just run `gradlew
310
+
test` (on Windows) or `./gradlew test` (Mac/Linux).
9
311
10
312
To compile and run everything, the command is:
11
313
@@ -32,12 +334,39 @@ program in the **strings** chapter subdirectory:
32
334
33
335
`gradlew :strings:ReplacingStringTokenizer`
34
336
35
-
However, if the file name is unique throughout the book (the majority are), you can just give the
36
-
program name, like this:
337
+
However, if the file name is unique throughout the book (the majority are), you
338
+
can just give the program name, like this:
37
339
38
340
`gradlew ReplacingStringTokenizer`
39
341
40
-
Note that all commands are run from the base directory where the example code is installed, and where you find the
41
-
`gradlew` script.
342
+
Note that all commands are run from the base directory where the example code is
343
+
installed, and where you find the `gradlew` script.
42
344
43
345
You can learn about other options by just typing `gradlew` with no arguments.
346
+
347
+
# Troubleshooting
348
+
349
+
If any terminology or processes described here remain unclear to you, you can
350
+
usually find explanations or answers through [Google](https://www.google.com/).
351
+
For more specific issues or problems, try
352
+
[StackOverflow](http://stackoverflow.com/). Sometimes you can find installation
353
+
instructions on [YouTube](https://www.youtube.com/).
354
+
355
+
Sometimes a Gradle build will be unable to connect to the internet and download
356
+
the necessary components, producing an error message containing:
357
+
358
+
```
359
+
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
360
+
```
361
+
362
+
Normally this means you have multiple Java installations on your machine
363
+
(applications built with Java ordinarily install their own version of Java), and
364
+
somehow the `cacerts` security file is interfering with the `cacerts` file for
365
+
the Java you have installed. It can be difficult to know which `cacerts` file is
366
+
interfering with yours. The brute-force approach is to search for all the
367
+
`cacerts` files on your machine and begin uninstalling the associated
368
+
applications---or in some cases, simply removing the directory containing the
369
+
`cacerts` file---until the Gradle build begins to work. You might also need to
370
+
adjust some environment variables and/or your path. Once you get the Gradle
371
+
build working successfully, you should be able to reinstall any applications you
0 commit comments