Java Language Foundation II

Source: Internet
Author: User

1 Keyword 1.1 keyword overview
    • Words that are given special meaning by the Java language.
1.2 Features of keywords
    • The letters that make up the keywords are all lowercase.
1.3 Keyword Considerations
    • ①goto and const exist as reserved words (which may be promoted to keywords in the new version of the JDK) and do not currently apply.
    • ② classes such as notepad++, a high-level notepad, for the keyword has a distinctive color tag, very intuitive.
    • ③main is not a keyword, but it cannot be used when defining identifiers.

2 Identifier 2.1 Identifier overview
    • A sequence of characters that name a class, interface, method, variable, etc.
2.2 Composition Rules
    • English uppercase and lowercase letters
    • numeric characters
    • $ and _
2.3 Precautions
    • Cannot start with a number
    • Cannot be a keyword in Java
    • Case sensitive
2.4 Common naming conventions in identifiers
    • Package: is actually a folder, used to solve the problem of the same name, named All lowercase.
      • Single-stage: Xuweiwei
      • Multilevel: Com.xuweiwei
    • Class or interface
      • One word: The first letter of the word must be capitalized. such as Hello.
      • Multiple words: The first letter of each word must be capitalized. such as HelloWorld.
    • Methods and variables
      • One word: The first letter of the word is lowercase. such as show.
      • Multiple words: Starting with the second word, capitalize the first letter of each word. such as Showallnames.
    • Constant
      • One word: all uppercase. such as Pi.
      • Multiple words: Each letter is capitalized, separated by _. such as Student_max_age.

3 Notes 3.1 Comments Overview
    • The text used to interpret the description program.
3.2 The classification format of annotations in Java
    • Single-line Comment
// Comment Text
    • Multi-line comments
/* * Comment Text */
    • Document comments
/** * Documentation Comments */
3.3 Annotated version of HelloWorld
 PackageCom.xuweiwei;/*** Requirements: Write a Java program, the "HelloWorld" This sentence output to the console * Analysis: *① Write a Java program, you must first define a class *② the data can be output, indicating that our program can run independently, and the program to run independently, you must define the M Ain method *③ Data output to the console, you must use the OUTPUT statement * implementation: The *①java language provides a keyword: class, used to define classes, followed by the class name *②main method format is fixed: * Public s The format of the tatic void Main (string[] args) {} *③ output statement is fixed: * SYSTEM.OUT.PRINTLN ("Hello world!!"); *//*** This is my HelloWorld case*/ Public classHelloWorld {/*** In order for the program to run independently, the main method must be defined * The Main method is the program's entry * is automatically recognized and invoked by the JVM *@paramargs*/     Public Static voidMain (string[] args) {//in order to display the data in the console, we used the output statementSystem.out.println ("Hello world!!"); }}

4 Constants and Variables 4.1 constants 4.1.1 Overview of constants
    • Its value cannot be changed during program execution
4.1.2 Classification of constants in Java
    • Literal constants
    • Custom Constants
4.1.3 Literal constants
    • String constants
      • Content enclosed in double quotation marks
      • such as: "Hello ah"
    • Integer constants
      • All integers
      • such as: 1, 2, 3 ...
    • Decimal constants
      • All decimals
      • Example: 13.15
    • Character constants
      • Content enclosed in single quotation marks
      • such as: ' A '
    • Boolean Constants
      • More special, only true and false
    • Empty constants
      • Null

    • Example:
 PackageCom.xuweiwei;/*** Constant: The amount of value that cannot be changed during the execution of a program.  * Categories of constants: * Literal Constants * Custom Constants * Literal constants: *① string constants are enclosed in double quotes * such as: "Helloworld" *② integer constant all integers * such as: 100,200 *③ decimal constant All decimals * such as: 10.23 *④ character constants are enclosed in single quotes * For example: ' A ' *⑤ Boolean constant is more special * such as: TRUE or false *⑥ NULL constant * such as: null * * 
    */ Public classConstantdemo { Public Static voidMain (string[] args) {//output of string constantsSystem.out.println ("Who Are You?")); //output of integer constantsSYSTEM.OUT.PRINTLN (12); //Decimal ConstantsSystem.out.println (12.3); //Character ConstantsSystem.out.println (' 1 '); //Boolean ConstantsSystem.out.println (true); //Empty ConstantsString str =NULL;    System.out.println (str); }}
4.2 An overview of variable 4.2.1 variables
    • The amount at which the value can change within a range during program execution.
4.2.2 The definition format of a variable
Variable name of data type = initialization value;

    • In essence, a variable is actually a small area of memory, using variable names to access the area, so each variable must be declared before it is used, and then assigned before it can be used.
    • Why do you define variables, which are mainly used to store constant constants that hold uniform types, and can be reused.
4.2.3 Data types
    • The Java language is a strongly typed language that defines specific data types for each data and allocates different sizes of memory space in memory.

    • Data type
      • Basic data types
        • Numeric type
          • Integer type (byte, short, int, long)
          • Floating-point type (float, double)
        • Boolean Type (Boolean)
        • Character type (char)
      • Reference data type
        • Class
        • Array
        • Interface
4.2.4 issues to be aware of using variables
    • ① Scope
      • The variable is defined within the curly brace, which is valid within the curly brace.
      • Also, you cannot define two identical variables within the same curly brace.
    • ② Initialization value
      • No initialization values can be used directly.
    • ③ on a single line, it is recommended to define only one variable
      • You can define multiple, but not recommended.
4.2.5 Data type Conversions
    • The Boolean type cannot be converted to another data type
    • Automatic type conversion
      • Byte, short, char-->int-->long-->float-->double
      • Byte, short, and Char are converted to the int type at the time of calculation.
    • Forcing type conversions
      • Target type variable name = (target type) (data to be converted);

    • Example:
 PackageCom.xuweiwei; Public classDataType { Public Static voidMain (string[] args) {/*** Default type conversion*/        intA = 3; byteb = 4; intc = A +b;        System.out.println (c); /*** Forced type conversion*/        byteD = (byte) (A +b);    System.out.println (d); }}

Java Language Foundation II

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.