在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:BruceEckel/OnJava8-Examples开源软件地址:https://github.com/BruceEckel/OnJava8-Examples开源编程语言:Java 98.4%开源软件介绍:Examples for On Java 8 by Bruce EckelIf you want to experiment with the code examples from the book On Java 8, you're in the right place. These examples are automatically extracted directly from the book. This repository includes tests to verify that the code in the book is correct.
Contents
Building From the Command Line: Quick VersionBefore you can run the examples from this repository, you must install JDK8, the Java Development Kit for version 8 of the language. If you just want to download and check the code, Download
Here
and unzip it into your destination directory. Open
a shell/command window and move into the
root of that directory. You'll know you are in the right directory if you see
the files You'll need an Internet connection the first time you compile the code, because Gradle needs to first install itself, then all the support libraries. Once these are installed you can perform additional compiling and running offline. On Mac/Linux, enter:
(If you get a Permission denied error, run On Windows, enter
If all goes well, the tests will run. Everything should complete without errors. All the book examples are in the subdirectory Building From the Command Line: Detailed InstructionsIf you are not familiar with the command line, first read Command-Line Basics. Install JavaYou must first install the Java Development Kit (JDK). Windows
MacintoshThe Mac comes with a much older version of Java that won't work for the examples in this book, so you'll need to update it to (at least) Java 8.
NOTE: Sometimes the default version of Java that you get with the above installation will be too recent and not validated by the Mac's security system. If this happens you'll either need to turn off the security by hand or install an earlier version of Java. For either choice, you'll need to Google for answers on how to solve the problem (often the easiest approach is to just search for the error message produced by the Mac). LinuxUse the standard package installer with the following shell commands: Ubuntu/Debian:
Fedora/Redhat:
Verify Your InstallationOpen a new shell and type:
You should see something like the following (Version numbers and actual text will vary):
If you see a message that the command is not found or not recognized, review the installation instructions. If you still can't get it to work, check StackOverflow. Installing and Running the Book ExamplesOnce you have Java installed, the process to install and run the book examples is the same for all platforms:
The first time you do this, Gradle will install itself and numerous other packages, so it will take some time. After everything is installed, subsequent builds and runs will be much faster. Note that you must be connected to the Internet the first time you run Appendix A: Command-Line BasicsBecause it is possible for a "dedicated beginner" to learn programming from this book, you may not have previously used your computer's command-line shell. If you have, you can go directly to the installation instructions. EditorsTo create and modify Java program files—the code listings shown in this book—you need a program called an editor. You'll also need the editor to make changes to your system configuration files, which is sometimes required during installation. Programming editors vary from heavyweight Integrated Development Environments (IDEs, like Eclipse, NetBeans and IntelliJ IDEA) to more basic text manipulation applications. If you already have an IDE and are comfortable with it, feel free to use that for this book. Numerous explanations in this book are specific to IntelliJ IDEA so if you don't already have an IDE you might as well start with IDEA. There are many other editors; these are a subculture unto themselves and people sometimes get into heated arguments about their merits. If you find one you like better, it's not too hard to change. The important thing is to choose one and get comfortable with it. The ShellIf you haven't programmed before, you might be unfamiliar with your operating system shell (also called the command prompt in Windows). The shell harkens back to the early days of computing when everything happened by typing commands and the computer responded by displaying responses—everything was text-based. Although it can seem primitive in the age of graphical user interfaces, a shell provides a surprising number of valuable features. To learn more about your shell than we cover here, see Bash Shell for Mac/Linux or Windows Shell. Starting a ShellMac: Click on the Spotlight (the magnifying-glass icon in the upper-right corner of the screen) and type "terminal." Click on the application that looks like a little TV screen (you might also be able to hit "Return"). This starts a shell in your home directory. Windows: First, start the Windows Explorer to navigate through your directories:
Once the Windows Explorer is running, move through the folders on your computer by double-clicking on them with the mouse. Navigate to the desired folder. Now click the file tab at the top left of the Explorer window and select "Open Windows Powershell." This opens a shell in the destination directory. Linux: To open a shell in your home directory:
DirectoriesDirectories are one of the fundamental elements of a shell. Directories hold
files, as well as other directories. Think of a directory as a tree with
branches. If Basic Shell OperationsThe shell operations shown here are approximately identical across operating systems. For the purposes of this book, here are the essential operations in a shell:
Unpacking a Zip ArchiveA file name ending with However, in all three systems the graphical file browser (Windows Explorer, the Mac Finder, or Nautilus or equivalent on Linux) will browse to the directory containing your zip file. Then right-mouse-click on the file and select "Open" on the Mac, "Extract Here" on Linux, or "Extract all ..." on Windows. Appendix B: TestingThe test system is built in so that we (the authors) can verify the correctness of what goes into the book. You don't need to run the tests, but if you want to, you can just run To compile and run everything, the command is:
If you are on a Unix/Linux based system, you must select the local directory for all commands, for example:
To only compile everything, the command is:
To compile only a single chapter (including dependencies), use for example:
To run only a single chapter, say:
Gradle can also be used to run a single program. Here, we run the ReplacingStringTokenizer.java program in the strings chapter subdirectory:
However, if the file name is unique throughout the book (the majority are), you can just give the program name, like this:
Note that all commands are run from the base directory where the example code is
installed, and where you find the You can learn about other options by just typing Appendix C: TroubleshootingIf any terminology or processes described here remain unclear to you, you can usually find explanations or answers through Google. For more specific issues or problems, try StackOverflow. Sometimes you can find installation instructions on YouTube. Sometimes a Gradle build will be unable to connect to the internet and download the necessary components, producing an error message containing:
Normally this means you have multiple Java installations on your machine
(applications built with Java ordinarily install their own version of Java), and
somehow the |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论