First knowledge of Java

Source: Internet
Author: User

# I. Tasks of this chapter

Writing HelloWorld Programs

Print console Information

# II. Objectives of this chapter

Installation and configuration of JDK

will use Notepad to develop a simple Java program

Outputs the information in the console using the output statement

Familiar with MyEclipse development environment

# Iii. Installationof JDK

# # (i) download of JDK

: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

# # (ii ) Installing the JDK

Slightly

# # (iii ) Configuring the JDK

-Path

-Java_home


# # (iv ) verifying JDK

! [Paste_image.png] (http://upload-images.jianshu.io/upload_images/5818381-80cb59c173e17f03.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# Iv. Development of the first Java program

# # (I ) steps

-Source Code

-Compile

-Run


# # (ii ) Preparation of HelloWorld procedures

# # 1. Writing source code

Command line: Notepad

"' Java

public class helloworld{

public static void Main (string[] args) {

System.out.print ("Hello World");

}

}

```

Attention:

-The file name must be: HelloWorld

-Suffix name of file:. java

# # 2. Compiling

Javac

! [Paste_image.png] (http://upload-images.jianshu.io/upload_images/5818381-3a444f1f0481ffdb.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

Note: The file name after Javac must include the suffix name (. java)

Successful identification:

! [Paste_image.png] (http://upload-images.jianshu.io/upload_images/5818381-259d2ab40ae2a8f4.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

# # 3. Run

Java

! [Paste_image.png] (http://upload-images.jianshu.io/upload_images/5818381-bfdd3f8135aebac4.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

* * Note: The file suffix name is not required after Java * *

# # (iii ) Understanding the structure of Java programs

# # 1. Structure

! [Paste_image.png] (http://upload-images.jianshu.io/upload_images/5818381-42b7852be5ae350b.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

# # 2. Output Statement

-System.out.print () No Line break


```

public class helloworld{

public static void Main (string[] args) {

System.out.print ("Hello World");

System.out.print ("Very hot Today");

}

}

```

* * Operation Effect: * *

! [] (http://upload-images.jianshu.io/upload_images/5818381-9a665541c1ac4a1f.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

-System.out.println () line break


```

public class helloworld{

public static void Main (string[] args) {

System.out.println ("Hello World");

System.out.println ("Very hot Today");

}

}

```

* * Operation Effect: * *

! [] (http://upload-images.jianshu.io/upload_images/5818381-b842753ec89057eb.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # (iv ) escape characters: \ t and \ n

# # 1. Meaning

! [] (http://upload-images.jianshu.io/upload_images/5818381-c10589c00bf64a75.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 2. Example

-\ n


```

public class helloworld{

public static void Main (string[] args) {

System.out.print ("Hello world\n");

System.out.println ("Very hot Today");

}

}

```

* * Operation Effect * *

! [] (http://upload-images.jianshu.io/upload_images/5818381-028ab536edce944d.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

-\ t

```

public class helloworld{

public static void Main (string[] args) {

System.out.print ("Hello world\t");

System.out.println ("Very hot Today");

}

}

```

* * Operation Effect * *

! [] (http://upload-images.jianshu.io/upload_images/5818381-984a6794e9a7b650.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # (v ) Small examples of printed output

# # 1. Demand

! [] (http://upload-images.jianshu.io/upload_images/5818381-f3a0e5af8f7e7474.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


! [] (http://upload-images.jianshu.io/upload_images/5818381-70d9e009bb697986.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 2. Reference Code

```

public class showinfo{

public static void Main (string[] args) {

System.out.println ("Name: Zhang San");

System.out.println ("Age: 18");

}

}

```

* * Program Run Effect * *

! [] (http://upload-images.jianshu.io/upload_images/5818381-2758a0489711066a.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

```

public class showinfo{

public static void Main (string[] args) {

System.out.print ("Zhang San \ t");

System.out.print ("18");

}

}

```

* * Operation Effect: * *

! [] (http://upload-images.jianshu.io/upload_images/5818381-2a030bd94594d045.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # (vi) Comments for Java

For the convenience of others to read the program

Comments are not executed

# # 1. Single-line comment

# # # syntax

```

//

```

# # # example

```

public class helloworld{

public static void Main (string[] args) {

This is the newline output.

System.out.println ("Hello World");

System.out.println ("Very hot Today");

}

}

```

Program Run Results

! [] (http://upload-images.jianshu.io/upload_images/5818381-5c33bbebf50926e2.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


* * Note: Comments will not be executed * *

# # 2. Multi-line comments

# # # syntax

```

/*

Comment Content

*/

```

# # # example

```

public class helloworld{

/*

This is the entrance to the program.

This is a test multi-line Comment

*/

public static void Main (string[] args) {

This is the newline output.

System.out.println ("Hello World");

System.out.println ("Very hot Today");

}

}

```

# # 3. Document Comments

# # # syntax

```

/**


*/

```

# # (vii) Java Coding Specification

! [] (http://upload-images.jianshu.io/upload_images/5818381-44b406900b91e8fb.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


! [] (http://upload-images.jianshu.io/upload_images/5818381-1928d72a77a2e3ac.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

# v. Development of Java programs using MyEclipse

# # (i ) download

Baidu

# # (ii ) crack

Reference Tutorials

# # (iii) MyEclipse steps to create a Java project

! [] (http://upload-images.jianshu.io/upload_images/5818381-f7fd91d36f0229ea.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 1. Create a Java project

! [] (http://upload-images.jianshu.io/upload_images/5818381-efff771442e9f842.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


Create a successful style

! [] (http://upload-images.jianshu.io/upload_images/5818381-a89d31b6d92777b7.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 2. Creating and writing Java source programs

! [] (http://upload-images.jianshu.io/upload_images/5818381-64190bf6ff593884.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


! [] (http://upload-images.jianshu.io/upload_images/5818381-5341aa98181b932d.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 3. Compiling and running

Compile auto-complete

Run


! [] (http://upload-images.jianshu.io/upload_images/5818381-49bb8a4eb9d3c760.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)

# # (iv) Java Project organizational structure

# # 1. Navigation view

! [Paste_image.png] (http://upload-images.jianshu.io/upload_images/5818381-d3cc24c79754e530.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # # Directory Description

! [] (http://upload-images.jianshu.io/upload_images/5818381-4e299ab27dda9555.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


-Bin: Store the compiled file

-SRC: Storage source program


# # 2. Package View

Package: Equivalent to a folder, in a different package, can have the same name code file

# # (v ) Several common errors in writing Javat programs

# # 1. The public decorated class name must be the same as the file name

! [] (http://upload-images.jianshu.io/upload_images/5818381-beb6ef044fc3e5e7.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 2. Main method as the entry of the program, Void is necessary

! [] (http://upload-images.jianshu.io/upload_images/5818381-1b6bb6ef3d03ecd3.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 3. Java is case sensitive

! [] (http://upload-images.jianshu.io/upload_images/5818381-0a4bba84255c6b8a.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 4. Each Java statement must end with a semicolon

! [] (http://upload-images.jianshu.io/upload_images/5818381-7ca6e8653e3a5853.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 5. quotation marks necessary

! [] (http://upload-images.jianshu.io/upload_images/5818381-de7a4052ff76caee.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # (vi ) case

# # 1. Demand

! [] (http://upload-images.jianshu.io/upload_images/5818381-4ef35ff1eaee3bd9.png?imageMogr2/auto-orient/strip% 7cimageview2/2/w/1240)


# # 2. Reference Code

```

public class Showuserinfo {

public static void Main (string[] args) {

System.out.println ("Hello, I am a bluebird student");

System.out.println ("Name: Harry");

System.out.println ("Age: 18");

System.out.println ("Hobby: Playing basketball");

}

}

```




This article is from the "Master" blog, please keep this source http://imentors.blog.51cto.com/10946447/1952944

First knowledge of Java

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.