Java Programming Ideas Fifth Edition (On Java 8) (2)-Install Java and Use Cases in this Book

Now, let's prepare for this reading trip!

Before starting to learn Java, you must first install Java and the source code examples of this book. Because considering that there may be "special beginners" to learn programming from this book, I will teach you how to use the command line in detail. If you already have experience in this area, you can skip this installation instruction. If you are still unclear about any term or process described here, you can also find the answer through Google search. Please try to ask specific questions or difficulties on StackOverflow . Or go to YouTube to see if there are relevant installation instructions.

editor

First you need to install an editor to create and modify the Java code in the use cases in this book. It is possible that you also need to use an editor to change the system configuration file.

Compared to some heavyweight IDEs (Integrated Development Environments), such as Eclipse, NetBeans and IntelliJ IDEA (Translator's Note: IDEA is highly recommended for projects), the editor is a more pure text editor. If you already have an IDE that works well, you can use it directly. In order to facilitate later learning and unify the teaching environment, I recommend everyone to use the editor Atom. You can download it on atom.io.

Atom is a free, open source, easy to install, and cross-platform (supports Window, Mac, and Linux) text editor. Built-in support for Java files. Compared to the thick and heavy IDE, it is relatively lightweight and ideal for learning this book. Atom contains many convenient editing functions, I believe you will love it! More details about the use of Atom can be found on its website.

There are many other editors. There is a subculture group, they are keen to argue which one is better! If you find an editor you prefer, it ’s not difficult to switch to another one. The important thing is that you are looking for a comfortable one.

Shell

If you have not been exposed to programming before, you may not be familiar with Shell (command line window). The history of the shell can be traced back to the early computing era. At that time, operations on the computer were all performed by entering commands, and the computer responded by echoing. All operations are based on text.

Although compared with the current graphical user interface, Shell operation is very primitive. But at the same time, the shell also provides us with many useful features. In the course of studying this book, we will often use the Shell, including the installation of this part, and running Java programs.

Mac: Click the spotlight (the magnifying glass icon in the upper right corner of the screen) and type terminal. Click the application that looks like a small TV screen (you can also click "return"). This starts the shell window under your user.

Windows: First, open the Windows Explorer through the directory:

  • Windows 7: Click the "Start" icon in the lower left corner of the screen, enter "explorer", and press Enter.
  • Windows 8: Press Windows + Q, enter "explorer" and press Enter.
  • Windows 10: Press Windows + E to open the Explorer, navigate to the desired directory, click the "File" tab in the upper left corner of the window, and select "Open Window PowerShell" to start the Shell.

Linux: Open Shell in the home directory.

  • Debian: Press Alt + F2, enter "gnome-terminal" in the pop-up dialog
  • Ubuntu: Right-click on the screen and select "Open Terminal", or press and hold Ctrl + Alt + T
  • Redhat: Right-click on the screen and select "Open Terminal"
  • Fedora: Press Alt + F2 and enter "gnome-terminal" in the pop-up dialog

table of Contents

The directory is one of the basic elements of Shell. The directory is used to save files and other directories. A directory is like a branch of a tree. If the book is a directory on your system, and it has two other directories as branches, such as math and art, then we can say that you have a book directory that contains two subdirectories of math and art. Note: Windows use \instead /to separate path.

Shell basic operation

The Shell operation I show here is roughly the same as in the system. For the reasons of this book, here are some basic operations in Shell:

更改目录: cd <路径> 
          cd .. 移动到上级目录 
          pushd <路径> 记住来源的同时移动到其他目录,popd 返回来源

目录列举: ls 列举出当前目录下所有的文件和子目录名(不包含隐藏文件),
             可以选择使用通配符 * 来缩小搜索范围。
             示例(1): 列举所有以“.java”结尾的文件,输入 ls *.java (Windows: dir *.java)
             示例(2): 列举所有以“F”开头,“.java”结尾的文件,输入ls F*.java (Windows: dir F*.java)

创建目录: 
    Mac/Linux 系统:mkdir  
              示例:mkdir books 
    Windows   系统:md 
              示例:md books

移除文件: 
    Mac/Linux 系统:rm
              示例:rm somefile.java
    Windows   系统:del 
              示例:del somefile.java

移除目录: 
    Mac/Linux 系统:rm -r
              示例:rm -r books
    Windows   系统:deltree 
              示例:deltree books

重复命令: !!  重复上条命令
              示例:!n 重复倒数第n条命令

命令历史:     
    Mac/Linux 系统:history
    Windows   系统:按 F7 键

文件解压:
    Linux/Mac 都有命令行解压程序 unzip,你可以通过互联网为 Windows 安装命令行解压程序 unzip。
    图形界面下(Windows 资源管理器,Mac Finder,Linux Nautilus 或其他等效软件)右键单击该文件,
    在 Mac 上选择“open”,在 Linux 上选择“extract here”,或在 Windows 上选择“extract all…”。
    要了解关于 shell 的更多信息,请在维基百科中搜索 Windows shell,Mac/Linux用户可搜索 bash shell。

Java installation

In order to compile and run the code samples, you must first install the JDK (Java Development Kit, JAVA software development kit). JDK 8 is used in this book.

Windows

  1. The following are the installation instructions of Chocolatey .
  2. Enter the following command at the command line prompt, wait for a while, after the completion of Java installation is complete and automatically complete the setting of environment variables.
 choco install jdk8

Macintosh

The version of Java that comes with the Mac system is too old. In order to ensure that the code examples in this book can be executed correctly, you must first update it to Java 8. We need administrator rights to run the following steps:

  1. The following are the installation instructions for HomeBrew . After the installation is complete, execute the command brew updateto update to the latest version
  2. Run the following command at the command line to install Java.
 brew cask install java

After the above installation is complete, if you need it, you can use the guest account to run the code examples in this book.

Linux

  • Ubuntu/Debian
     sudo apt-get update
     sudo apt-get install default-jdk
  • Fedora/Redhat
    su-c "yum install java-1.8.0-openjdk"(注:执行引号内的内容就可以安装)

Verify installation

Open a new command line input:

java -version

Under normal circumstances, you should see the following similar information (version number information may be different):

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

If the prompt command cannot be found or cannot be recognized, please try again according to the installation instructions; if not, try to find the answer on StackOverflow .

Install and run code samples

When Java is installed, the next step is to install the code examples in this book. The installation steps are the same for all platforms:

  1. Download the code examples for this book from the GitHub repository
  2. Unzip it into the directory of your choice.
  3. Use Windows Explorer, Mac Finder, Nautilus for Linux or other equivalent tools to browse, and open the Shell in this directory.
  4. If you are in the correct directory, you should see the files named gradlew and gradlew.bat in that directory, as well as many other files and directories. The table of contents corresponds to the chapters in the book.
  5. Enter the following command in the shell to run:
     Windows 系统:
          gradlew run

     Mac/Linux 系统:
        ./gradlew run

Gradle needs to install itself and other related packages when installing for the first time, please wait a moment. After the installation is complete, subsequent installations will be much faster.

Note : The first time you run the gradlew command, you must be connected to the Internet.

Gradle basic tasks

A large number of Gradle tasks built in this book can be run automatically. Gradle uses a convention that is greater than the configuration, and simple settings can provide high availability. Some of the tasks of "Go Riding Together" in this book are not suitable for this or cannot be performed successfully. The following is a list of Gradle tasks you would normally use:

    编译本书中的所有 java 文件,除了部分错误示范的
    gradlew compileJava

    编译并执行 java 文件(某些文件是库组件)
    gradlew run

    执行所有的单元测试(在本书第16章会有详细介绍)
    gradlew test

    编译并运行一个具体的示例程序
    gradlew <本书章节>:<示例名称>
    示例:gradlew objects:HelloDate
Published 434 original articles · Like 1308 · Visitors 630,000+

Guess you like

Origin blog.csdn.net/qq_33589510/article/details/105455519