Basics of Java 01

Note

Comment species

  • Single-line comments: Only comments a line of text at the beginning of the play //

  • Multi-line comments: Can you comment multiple lines, playing at the beginning of the line / * end of the line with * /

  • Documentation Comments: related JavaDoc command, / ** * beginning / end

 

 

Notes and will not be executed, but to those who write the code to see

Usually write the code must be standardized

 

Identifiers and Key Words

1584809115309

All components of the Java name is required. Class names, variable names and method names have not become identifier.

  • All identifiers should begin with a letter (AZ or az), the dollar sign ($) or an underscore (_);

    Illegal characters example: 123asd, -asdf, # asdf, these are illegal

  • After the first character may be a letter (AZ or az), any characters dollar sign ($) or an underscore (_) or digital composition

  • You can not use keywords as variable or method name

  • Identifiers are case-sensitive, that is to pay attention to case

  • We do not recommend the use of Chinese pinyin or name

 

type of data

Data types fall into two categories

  1. Strongly typed language: the requirements of the variables used to strictly comply with the provisions, all variables must be defined before you can use (java, c ++ is a strongly typed language) safe but slow

  2. Weakly typed language: the definition of a strongly typed language contrast, JavaScript and Visual Basic Script

 

Java data types

String string definitions need to add double quotation marks, he is not a keyword, he is a class, he can be used to define multiple characters

Java only be divided into two types of data

  • Basic types (primitive type)

    1. Numeric types

      1. Integer type

        byte one byte: -128-127

        short two bytes: -32768-32767

        int total of four bytes: -21 one hundred million -21 million in the most commonly used

        long occupies eight bytes: large, will be added with an uppercase when used after the number of such values ​​L type

      2. Floating-point type

        float 4 bytes, followed by one of the capital needed to use this type of F

        double 8 bytes long (common)

      3. Char Character type is two bytes, after the equal sign in single quotes '' enclosed, only the middle of writing a letter or word

    2. boolean types: one bit, only his true and false values ​​of two, usually with flag = true or false flag =, with the flag named

     

  • Reference types (reference type)

    class

    interface

    Array

Spread

Integer

Binary will hexadecimal (zero x) begins with 0x to 0b (zero b) at the beginning of octal to 0 (zero) at the beginning

== represents equal, in his reference to indicate whether the output is determined before and after the equality

Float

The number of floating-point performance is limited, discrete, there is a rounding error, about, close to but not equal, all were relatively easy to make mistakes with float

Best to completely avoid using floating point numbers to compare

Best to completely avoid using floating point numbers to compare

Best to completely avoid using floating point numbers to compare

 

How about banking issues such as representation, with BigDecimal, a mathematical tool class

 

character

Before adding a parenthesis character output, which is a data type bracket, this is called a cast

For example:

char name = 'c';
System.out.println((int)c);
   

Here are the characters into digital, because all of the characters or numbers in nature

 

With the Unicode character encoding, occupies 2 bytes, a length of 65 536, i.e. 2 to the power 16, 97 on behalf of such a, 65 represents A

 

Expressed interval U0000-UFFFF, examples

char NAME1 = '\ u0061'; 
the System. OUT. the println ( NAME1); // this is the output of a
   

 

Escape character

\ T is a tab

\ N represents a newline

System.out.println("Hello\tWorld");

There are many escape character, can be found online

 

Extended Boolean value

Sometimes after the if statement will pick Boolean variables, but did not write anything after the variable ==, which is generally regarded as the == true

Less is more, to streamline the code easy to understand

 

 

Learning from God mad to say the Java https://www.bilibili.com/video/av68373450?p=2 4

Guess you like

Origin www.cnblogs.com/jimmykane/p/12543857.html