Beginner java foundation learning the second day

The second day of Xiaobai's basic java study

1, Notes

As the saying goes: if the foundation is not strong, the earth will shake and the mountains will shake.

1. Comment, identifier, keyword

notes

  • When the amount of code is small, we can still understand the code we write, but once the project structure is complex, we need comments.
  • Comments are not implemented. They are written for people to see.
  • Writing notes is a very good habit.
  • You must pay attention to norms when writing code.

Three annotations in java

  1. Single-Line Comments

    //Single-Line Comments 
    
  2. multiline comment

     /*
            I'm a multiline comment
            I'm a multiline comment
     */
    
  3. Documentation Comments

     /**
         * @Description HelloWorld
         * @Author Xiaobai is learning Java
         */
    
    
  • /***                                                                          
     *          .,:,,,                                        .::,,,::.          
     *        .::::,,;;,                                  .,;;:,,....:i:         
     *        :i,.::::,;i:.      ....,,:::::::::,....   .;i:,.  ......;i.        
     *        :;..:::;::::i;,,:::;:,,,,,,,,,,..,.,,:::iri:. .,:irsr:,.;i.        
     *        ;;..,::::;;;;ri,,,.                    ..,,:;s1s1ssrr;,.;r,        
     *        :;. ,::;ii;:,     . ...................     .;iirri;;;,,;i,        
     *        ,i. .;ri:.   ... ............................  .,,:;:,,,;i:        
     *        :s,.;r:... ....................................... .::;::s;        
     *        ,1r::. .............,,,.,,:,,........................,;iir;        
     *        ,s;...........     ..::.,;:,,.          ...............,;1s        
     *       :i,..,.              .,:,,::,.          .......... .......;1,       
     *      ir,....:rrssr;:,       ,,.,::.     .r5S9989398G95hr;. ....,.:s,      
     *     ;r,..,s9855513XHAG3i   .,,,,,,,.  ,S931,.,,.;s;s&BHHA8s.,..,..:r:     
     *    :r;..rGGh,  :SAG;;G@BS:.,,,,,,,,,.r83:      hHH1sXMBHHHM3..,,,,.ir.    
     *   ,si,.1GS,   sBMAAX&MBMB5,,,,,,:,,.:&8       3@HXHBMBHBBH#X,.,,,,,,rr    
     *   ;1:,,SH:   .A@&&B#&8H#BS,,,,,,,,,.,5XS,     3@MHABM&59M#As..,,,,:,is,   
     *  .rr,,,;9&1   hBHHBB&8AMGr,,,,,,,,,,,:h&&9s;   r9&BMHBHMB9:  . .,,,,;ri.  
     *  :1:....:5&XSi;r8BMBHHA9r:,......,,,,:ii19GG88899XHHH&GSr.      ...,:rs.  
     *  ;s.     .:sS8G8GG889hi.        ....,,:;:,.:irssrriii:,.        ...,,i1,  
     *  ;1,         ..,....,,isssi;,        .,,.                      ....,.i1,  
     *  ;h:               i9HHBMBBHAX9:         .                     ...,,,rs,  
     *  ,1i..            :A#MBBBBMHB##s                             ....,,,;si.  
     *  .r1,..        ,..;3BMBBBHBB#Bh.     ..                    ....,,,,,i1;   
     *   :h;..       .,..;,1XBMMMMBXs,.,, .. :: ,.               ....,,,,,,ss.   
     *    ih: ..    .;;;, ;;:s58A3i,..    ,. ,.:,,.             ...,,,,,:,s1,    
     *    .s1,....   .,;sh,  ,iSAXs;.    ,.  ,,.i85            ...,,,,,,:i1;     
     *     .rh: ...     rXG9XBBM#M#MHAX3hss13&&HHXr         .....,,,,,,,ih;      
     *      .s5: .....    i598X&&A&AAAAAA&XG851r:       ........,,,,:,,sh;       
     *      . ihr, ...  .         ..                    ........,,,,,;11:.       
     *         ,s1i. ...  ..,,,..,,,.,,.,,.,..       ........,,.,,.;s5i.         
     *          .:s1r,......................       ..............;shs,           
     *          . .:shr:.  ....                 ..............,ishs.             
     *              .,issr;,... ...........................,is1s;.               
     *                 .,is1si;:,....................,:;ir1sr;,                  
     *                    ..:isssssrrii;::::::;;iirsssssr;:..                    
     *                         .,::iiirsssssssssrri;;:.                      
     */		
    --------
    Original link: https://blog.csdn.net/ydk888888/article/details/81563608
     Is this the ghost guy???
    

identifier

keyword

The above are the commonly used keywords in java. Follow the crazy God to keep learning and slowly master all of them.

  • All components of java need names. Class name, variable name and method name are all called identifiers.

Identifier considerations

  • All identifiers should be in letters (a-z or a-z), dollar sign ($), or underscore () Start.

  • The first letter can be followed by letters (A-Z or A-Z), dollar sign ($), underscore () Any combination of characters or numbers.

  • Keywords cannot be used as variable or method names.

  • Identifiers are case sensitive.

  • Examples of legal identifiers:

    age,$salary,_value,__1_value
    
  • Example of illegal identifier:

    12abc,-salary,#abc
    
  • Note: Chinese names can be used, but generally it is not recommended to use them or Pinyin, because it is very low.

2. Data type

  • Strongly typed language

    • Strongly typed languages require that the use of variables should strictly comply with the regulations, and all variables must be defined before use. (if the safety is high, the speed will be slow)
  • Weakly typed language (vice versa)

The data types of java are divided into two categories

  • primitive type

    1. value type
    • Integer type (int, short, long, byte)
    • float, double
    • Character type (char)
    1. boolean type: only true and false
       // Eight basic data types
            //integer
            int num = 10;   //Most commonly used
            byte num2= 20;
            short num3 =30;
            long num4 = 20000L;// The long type should be L after the number
            
            // Decimal: floating point
            float num5 = 100.2F;// For float type, add F after the number
            double num6 = 3.141592654;
            
            // Character type
            char name ='a';
            // String, string is not a keyword, class
            String namea ="Gourd baby";
            
            // Yes or No: Boolean
            boolean flag = true;
            // boolean flag = false;
    
  • reference type

    • class
    • Interface
    • array

    Lecture notes

    public class Demo3 {
        public static void main(String[] args) {
            //Integer extended binary binary system starts with 0b, decimal octal system starts with 0, and hexadecimal system starts with 0x
            int i= 10;
            int i1 = 0b10;
            int i3 = 010;
            int i4 = 0x10;
            System.out.println(i);
            System.out.println(i1);
            System.out.println(i3);
            System.out.println(i4);
    
            //Floating point extension
            // float finite discrete rounding error is approximately but not equal to
            // double
            // It is best to completely avoid using floating-point numbers for comparison
            // It is best to completely avoid using floating-point numbers for comparison
            // It is best to completely avoid using floating-point numbers for comparison
    
    
            //==========================================================//
            // Character extension
            char c1 = 'a';
            char c2 = 'in';
            System.out.println(c1);
    
            System.out.println((int)c1);// Force conversion
    
            System.out.println(c2);
    
            System.out.println((int)c2);
    
            // All characters are still numbers in nature
            // Unicode 2 bytes
    
            char c3='\u0061';
            System.out.println(c3);//a
    
            //Escape character
            //  \t tab
            //   \n line feed
            //......
            System.out.println("Hello\nWorld");
    
            //========================================
            System.out.println("==========================================");
            String sa = new String("HelloWorld");
            String sb = new String("HelloWorld");
            System.out.println(sa==sb);
    
    
            String sc = "HelloWorld";
            String sd = "HelloWorld";
            System.out.println(sc==sd);
            // Object from memory analysis
    
            System.out.println("===============================");
            // Boolean extension
    
            boolean flag = true;
            // if(flag = = true {}) has the same meaning as if(flag {})
            // Less is More!!!
    
    
        }
    }
    
    

Keywords: Java

Added by peri on Mon, 07 Mar 2022 21:18:23 +0200