Day1 install the JDK 8 Environment and the first java program, day1jdk 8

Source: Internet
Author: User

Day1 install the JDK 8 Environment and the first java program, day1jdk 8
Install JDK 8

Step 1: Download the jdk installation package. Here we will download the jdk 8 on the orical official website.

Note: Remember to check accept when downloading.

Decompress the downloaded package:

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

Place 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-versionjava 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, sailing.

The first java program
Class HelloWorld {// This is the main method, it is the program entry public static void main (String [] args) {// This is the program output System. out. print ("Hello World! "); // Print line feed with ln, and System. out. println (" Hello World! ");}}

Compile

javac hello.java 

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

Execution Program

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

There is no line feed in the output.

Java program considerations

The file name is myhello. java.

/** My first java program this is a java-specific document note * @ author jeffd * @ version 1.0 **/public class myhello {// 1. source file. end of java // 2. the source file can have classes declared by multiple classes // 3. the format of the main method (that is, the main method) in the class is fixed. // 4. main method, which is the entry of the program and the execution part of the program in the method // 5. only one public class can be declared for a source file, and the class name must be consistent with the source file name. // 6. each statement ends with a semicolon // 7. execute the program: Compile multiple projects by javac. class bytecode file, java Run // 8. multi-line comments cannot be nested with public static void main (String [] args) {// This is the output System of the program. out. print ("Hello World! "); // Print line feed with ln, and System. out. println (" Hello World! ");}}

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

Java annotations

The single line comment is //.

Multi-line comment /**/. Multi-line comments cannot be nested.

Document Note :/**

@*

*/

Example:

Javadoc generates comments:

jeff@debian:~/java_coding/day001$ javadoc -d mydoc -author -version myhello.javaLoading source file myhello.java...Constructing Javadoc information...Creating destination directory: "mydoc/"Standard Doclet version 1.8.0_162Building 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 mudoc folder

jeff@debian:~/java_coding/day001$ lshello.java  HelloWorld.class  mydoc  myhello.class  myhello.java
jeff@debian:~/java_coding/day001$ cd mydoc/jeff@debian:~/java_coding/day001/mydoc$ lsallclasses-frame.html    help-doc.html   overview-tree.html    package-tree.htmlallclasses-noframe.html  index-all.html  package-frame.html    script.jsconstant-values.html     index.html      package-list          stylesheet.cssdeprecated-list.html     myhello.html    package-summary.html

Open index.html to view the document style.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.