java--Learning Java starts here: Java language Basics (1) basic knowledge--Dark horse programmer

Source: Internet
Author: User
Tags custom name

------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------

Java language Basics (1)

Starting with this diary, I'll start with some basic knowledge about Java,

1 Java language Overview

The founder of Java-James Goslin (James Gosling)

He received a BS in computer Science from the University of Calgary in 1977, a PhD in computer science from Carnegie Mellon University in 1983, and worked at IBM after graduating to design IBM's 71st-generation workstation news system, but it was not appreciated. Later transferred to Sun, 1990, and Patrick,naughton and Mike Sheridan and other people to cooperate "Green plan", later developed a set of languages called "Oak", then renamed Java. Photos of everyone under the Baidu, it will not be uploaded.

2 The Java language Cross-platform principle

What is cross-platform?

Applications written in the Java language can be run on different system platforms.

What is the principle?

Just on the operating system that needs to run the Java application,

Install a Java Virtual machine (JVM Java VM) first.

The JVM is responsible for the operation of the Java program in the system.

3 Overview of JDK and JRE

JRE: Includes Java virtual machines (JVM Java) and the core class libraries required by Java programs, and so on, if you want to run a well-developed Java program, you only need to install the JRE on your computer.

JDK:DK is available to Java developers, and includes Java development tools and JRE. So with the JDK installed, you don't have to install the JRE separately.

Development tools: Compilation Tools (Javac.exe) packaging Tools (Jar.exe), etc.

4 Introduction to Development tools and introduction to JDK--JDK directory structure and development tools

There are a number of tools you can use to write Java programs

Notepad (Microsoft OS comes with)

notepad++

Eclipse

MyEclipse

5 writing and running of the first HelloWorld case

First define a class

Class name

Add a pair of curly braces after the class definition

{}

Add a main (main) method/function to the middle of the curly braces

public static void Main (String [] args) {}

Add a row of output statements to the middle of the main method's curly braces

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

1 classHelloWorld2 3 {4 5           Public Static voidmain (String [] args)6 7          {8 9 System.out.println ("Hello World");Ten  One          } A  -}

(1) Procedure explanation:

The most basic unit of a A:java program is a class, so we're going to define a class.

Format: Class name

Example: Class HelloWorld

B: When writing content in a class, enclose it in curly braces.

To execute a c:java program, you must have the main method.

Format: public static void Main (string[] args)

D: To point to those things and enclose them in curly braces.

E: What are you going to do? Today we just made a simple output

Format: System.out.println ("HelloWorld");

Note: The contents of "" can be changed.

(2) Java program development and execution process:

A: Writing Java source program (. java)

B: Build the. class file by compiling the Javac command

C: Run the. class file with the Java command

6 FAQ Summary of development

Common problems (Master)

(1) The extension is hidden

How to find: Tools--Folder Options--View--Remove the check mark for hidden extensions

(2) I ask for the same file name and class name.

In fact, it is possible not to do so.

However, note:

Javac followed by filename + extension

Class name followed by Java without extension

(3) Please note that the Java language is strictly case-sensitive.

There is also the word don't write wrong.

(4) See illegal characters: \65307 is definitely a Chinese problem.

We write procedures that require punctuation marks to be all in English state.

(5) The pairing problem of brackets.

In general, the parentheses are paired up.

(6) encountered

Cannot find the main method in class HelloWorld, define the main method as

Must be a format problem for the main method.

7 Why to configure the PATH environment variable

The execution of the program requires the use of an external instruction Javac, but the javac instruction can only be written to the bin directory under the JDK installation directory.

During the program development process, the source code cannot be written to the JDK's installation directory, so the source program needs to be saved to the specified directory in any location (English directory), so the JAVAC directive needs to be run in any directory

8 How the PATH environment variable is configured

(1) The role of the PATH environment variable

Ensure that the Javac command can run in any directory.

Similarly, you can configure QQ, etc.

(2) path configuration of two scenarios:

A: Scenario 1 (understanding)

B: Scenario 2

Find the location of the environment variable inside the system variable

New:

Variable name: java_home

Variable Value: D:\develop\Java\jdk1.7.0_60

Modify:

Variable name: Path

Variable value:%java_home%\bin; previous content

9 The role of CLASSPATH and its configuration

(1) The role of CLASSPATH environment variables

Guaranteed class files can be run in any directory

(2) configuration of CLASSPATH environment variables

Find the location of the environment variable inside the system variable

New:

Variable name: classpath

Variable Value: E:\JavaSE\day01\code\HelloWorld case

The difference between the ten path and the Classpath

The PATH environment variable is an executable file, such as an. exe file, where the executable file is located in the current path, and if it is not found, go to the path configured in the PATH environment variable to find

The directory where the Java class's running files are recorded in the CLASSPATH environment variable

11 Overview of annotations and their classifications

Types of annotations:

Single-line comment: Starting with "//", the contents of the back will be commented, often used to annotate a single line of code, or to describe a single line of code;

Multiline comment: Start with "/*", End with "*/", the contents of the middle will be commented, often used to comment on multiple lines of code, or a description of multiple lines of code such as "Class", "method", etc.

Document comments: Starting with "/**", ending with "*/", usually used in the description of "class" and "Method" (object-oriented Javadoc tools will be explained)

12 Function of the annotations

The role of annotations:

It is similar to the product specification;

Write your own code, a long time later forget to implement the logic;

Other people will look at your source code;

Many times it is also very effective to use annotations to find errors in the code (exclusion method);

13 Overview and use of keywords

Keywords for Java:

1.Java "keywords" are defined by the Java language;

2. Each keyword represents a different meaning;

3. It is similar to some instructions under "command Prompt", used to tell the Java compiler what we are going to do;

Features of the 4.Java keyword: all letters in each word are lowercase.

5.Java keyword considerations:

1). Goto and const as reserved words are not currently supported in Java syntax.

14 Overview and composition rules for identifiers

Identifiers Overview

Is the sequence of characters to use when naming classes, interfaces, methods, variables, etc.

Composition rules

English uppercase and lowercase letters

numeric characters

$ and _

Precautions

Cannot start with a number

Cannot be a keyword in Java:

Case sensitive

15 common naming conventions in identifiers

Identifier:

1. In the source code, some elements of our programmer's custom name, such as: class name, variable name, method name, etc., are collectively: identifiers

2. These identifiers are used by our programmers in the development and writing of the source code, with a good name that facilitates our development and use.

These identifiers have nothing to do with the end user of our software.

3. Rules for defining identifiers:

1). Can contain letters of uppercase and lowercase in English, as well as any other country's writing. As long as 128 and subsequent characters in the Unicode encoding table are available.

2). Numeric characters: 0--9; For example: Class Test1,class Test01,class Demo10

3). Symbols: $ and _; for example: Class Test_01,class test$01

4). There is no "space" in the middle of the identifier;

5). You cannot have the same name as a keyword in Java, for example: Class Class (Error), class public (error), Class class (OK, Java is case-sensitive)

6). Cannot start with a number, for example: Class 1Test (Error), class 123 (wrong), class T1234 (OK)

Overall remember: identifiers, can only contain: letters, numbers, $ and _; numbers cannot begin

4. Definition Specification for identifiers:

General specification: See the name of the idea, the hump named

1. See the name: You should know what it means to see it;

For example: Variables used to store age:

2. Hump naming: Case combination:

A: Class Name: Capitalize the first letter. Multiple words, the first letter of each word should be capitalized;

Example: HelloWorld

B: Variable name, method name: First letter lowercase, multiple words, start with the second word, capitalize the first letter;

C: Package (folder) Name: All lowercase, even if multiple words, all letters all lowercase;

D: Constant Name: All letters uppercase, multiple words, in the middle with an underscore _ separated;

Example: Student_age

3. Class name and variable name use "noun", method name with "verb"

Identifiers in 5.Java are case-sensitive:

Define variables:

Age and Age:java are considered to be two different variable names;

16 Overview and use of constants

Constants in Java:

1. Literal constants: Allow some "values" to appear in Java source code

2. Custom constants: (later)

Literal constants:

1. integers; 2. decimals; 3. Characters; 4. Boolean value: 5. String: 6.null value

java--Learning Java starts here: Java language Basics (1) basic knowledge--Dark horse programmer

Related Article

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.