Installing jdk8 environment and the first java program on day1

Keywords: Java JDK Linux

Install jdk8

Step 1: download the JDK installation package. Here we download the jdk8 version of the official website of orical.

Note: please check accept when downloading.

Unpack and decompress after downloading:

tar zxvf jdk-8u162-linux-x64.tar.gz 

Put JDK under / usr/lib/jdk8

mv jdk1.8.0_131/ /usr/lib/jdk8

Modify environment variables

vi ~/.bashrc

conf jdk is our jdk8 configuration

source ~/.bashrc

Check whether the configuration is successful

root@debian:/home/jeff/download# java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

java boat, set sail.

First java program

class HelloWorld{

        //This is main Method, which is the entry of the program
        public static void main(String[] args){
                //This is the output of the program
                System.out.print("Hello World!");
                //Yes ln Of print Line break, no line break
                System.out.println("Hello World!");
        }
}

Compile

javac hello.java 

Generate the HelloWorld.class bytecode file (my defined class name is HelloWorld).

Execution procedure

jeff@debian:~/java_coding/day001$ java HelloWorld 
Hello World!Hello World!

The output here does not wrap

java program considerations

This file is named myhello.java

/**
 My first java program
 This is a java specific document annotation
 *@author jeffd
 *@version 1.0
 * */
public class myhello{
        //1.Source files.java Ending
        //2.There can be multiple source files class Declarative classes
        //3.Class can have a main method (that is main The format is fixed.  
        //4.main Method, which is the entry of the program, and the inside of the method is the execution part of the program
        //5.A source file can only have one declaration public And the class name of this class should be the same as the source file name
        //6.Each statement ends with a semicolon
        //7.Execution procedure: javac Build multiple.class Bytecode file, java Function
        //8.Multiline notes cannot be nested
        public static void main(String[] args){
                //This is the output of the program
                System.out.print("Hello World!");
                //Yes ln Of print Line break, no line break
                System.out.println("Hello World!");
        }
}

Each program can only have one public class, and it must be the same as the file name. javac compiled files may generate multiple bytecode files.

java comments

The single line comment is / /.

Multiline comment / * * /. Multiline comments cannot be nested.

Document notes:/**

                         @*

                        */

Example: above

javadoc generate comments:

jeff@debian:~/java_coding/day001$ javadoc -d mydoc -author -version myhello.java
Loading source file myhello.java...
Constructing Javadoc information...
Creating destination directory: "mydoc/"
Standard Doclet version 1.8.0_162
Building tree for all the packages and classes...
Generating mydoc/myhello.html...
Generating mydoc/package-frame.html...
Generating mydoc/package-summary.html...
Generating mydoc/package-tree.html...
Generating mydoc/constant-values.html...
Building index for all the packages and classes...
Generating mydoc/overview-tree.html...
Generating mydoc/index-all.html...
Generating mydoc/deprecated-list.html...
Building index for all classes...
Generating mydoc/allclasses-frame.html...
Generating mydoc/allclasses-noframe.html...
Generating mydoc/index.html...
Generating mydoc/help-doc.html...

Generate a folder of mudoc

jeff@debian:~/java_coding/day001$ ls
hello.java  HelloWorld.class  mydoc  myhello.class  myhello.java
jeff@debian:~/java_coding/day001$ cd mydoc/
jeff@debian:~/java_coding/day001/mydoc$ ls
allclasses-frame.html    help-doc.html   overview-tree.html    package-tree.html
allclasses-noframe.html  index-all.html  package-frame.html    script.js
constant-values.html     index.html      package-list          stylesheet.css
deprecated-list.html     myhello.html    package-summary.html

Open index.html to see the document style

When the program is large enough, the document can help us better understand the use of each class.

Posted by harris97 on Wed, 01 Apr 2020 17:40:18 -0700