在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):BruceEckel/AtomicKotlinExamples开源软件地址(OpenSource Url):https://github.com/BruceEckel/AtomicKotlinExamples开源编程语言(OpenSource Language):Java 81.6%开源软件介绍(OpenSource Introduction):Atomic Kotlin ExamplesIf you want to experiment with the code examples from the book Atomic Kotlin, 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
IntroductionThe easiest way to access and experiment with the book examples is to clone/download this repository and open it with IntelliJ IDEA. This is all that most people need, and those people can ignore the rest of this README. The remainder of this README shows you how to build and test the examples using both IntelliJ IDEA and the command line. Exercises and solutions for the book can be found at AtomicKotlin.com/exercises. Note: If any terminology or processes described here are still not clear 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. Compiling and Running Programs in IntelliJ IDEAThe easiest and fastest way to start using the examples in this book is by compiling and running them using IntelliJ IDEA:
Building From the Command Line: Quick VersionBefore you can run the examples from this repository, you must install the current version of Java, although some earlier versions should also work. (If you get any errors, try upgrading to a more recent version of Java). 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 To compile and run examples using the Kotlin command-line tools, see Command-Line Hello World. Building From the Command Line: Detailed InstructionsIf you are not familiar with the command line, first read Command-Line Basics. Install JavaKotlin runs on top of Java, so you 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 Kotlin 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: Command-Line Hello WorldThis appendix explains how to compile and run the program shown in the "Hello World" atom in the book, using the latest version (1.5 or higher) of the Kotlin command-line compiler. Open up a console window in the
Assuming you've typed the code correctly, you should get back the console prompt, with no other messages. If you get error messages, try to discover where you've mis-typed the code, correct it and try again. Once you are successful, you're ready to run the program. There's one more thing: When you run Now we can run the program:
And you'll see the output on the console:
PackagesIf the program is in a package, the package name is also required to run the
program. That is, if
then you cannot simply say:
You'll get a message starting with If you were to compile this program, you'd see there's a new subdirectory
called If the program is packaged under
Appendix C: The Kotlin REPLThe Kotlin interpreter is also called the REPL (for Read-Evaluate-Print- Loop). To use this you must first install the latest version (1.5 or higher) of the Kotlin command-line compiler.
Install KotlinIn this book, we use Kotlin version 1.5, the latest available at the time. The detailed installation instructions for the command-line compiler are available at The Kotlin Site. To check your installation, open a new shell and type:
at the shell prompt. You'll see the version information for your Kotlin installation. The REPLTo start the REPL, type
The exact version numbers will vary depending on the versions of Kotlin and Java you've installed, but make sure that you're running Kotlin 1.5 or greater. The REPL gives you immediate interactive feedback, which is helpful for experimentation. For example, you can do arithmetic:
Find out more by typing
To compile and run examples using the Kotlin command-line tools, see Command-Line Hello World. Appendix D: 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 There are two steps in creating and running the tests, which you can run
separately if you want (again, just running the Gradle
Alternatively, |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论