JavaSE getting started Basics

JavaSE getting started Basics

Idea shortcut key

1. delete the code of the cursor line

idea shortcut: Ctrl+X

eclipse shortcut: Ctrl+D

2. copy the code of the cursor line or the code selected with the mouse
idea shortcut: Ctrl+D
eclipse shortcut: Ctrl+Alt+ up and down

3. switch code case
idea: Ctrl+Shift+U
eclipse:Ctrl+Shift+X (upper case) Ctrl+Shift+Y (lower case)

4. close the current code window
idea: Ctrl+F4
eclipse: Ctrl+W

5. quickly navigate to the location of the last edit
idea:Ctrl+Alt+ left and right keys
eclipse: Ctrl+Q

6. quickly search classes and interfaces
idea: Ctrl+Shift+R
eclipse: Ctrl+Shift+R

7. switch the previous browse bar
idea:Alt+ left and right keys
eclipse:Alt+ left and right keys

8. generate get and set methods
idea shortcut: Alt+insert
eclipse shortcut: Shift+Alt+S

9. format code
idea: first select all codes with Ctrl+A and then Ctrl+Alt+L
eclipse: first Ctrl+A select all the code and then Ctrl+I format the code

10. move forward line code down and up
idea:Shift+Ctrl+ up / down
eclipse:Ctrl+Alt+ up and down

11. interface fast entry implementation method
idea: place the mouse over the interface method, and press Ctrl+Alt+B to enter the implementation method
eclipse: place the mouse over the interface method, and then Ctrl+ right click to display the implementation method. Click to enter

annotation

  1. Single-Line Comments
  2. multiline comment
  3. Documentation Comments
	/**① 
	 * This is a document note, where position ① is the beginning of the note, position ② is the end of the note, and all the contents of the note are in the middle,
	 * The annotation content can be defined by the javadoc Exe to generate a web version of the documentation
	 * eclipse Shortcut keys are Alt + Shift + J
	 * 
	 * @param i Formal parameter
	 * @return Return value
	 ②*/

identifier

It is divided into class name, variable name and method name

data type

Eight data types

int byte short long float double char boolean

import java.net.StandardSocketOptions;

public class dataType {
    public static void main(String[] args) {    //psvm

        // Eight data types

//        Integer
        int num1 = 10 ;
        byte num2 = 20 ;
        short num3 = 30 ;
        long num4 =30L ;

        float num5 = 50.1F ;
        double num6 = 3.14 ;

        char name = 'A' ;
//        boolean flag = ture ;
        System.out.println(num1);           //sout
        System.out.println(num2);
        System.out.println(num3);
        System.out.println(num4);
        System.out.println(num5);
        System.out.println(num6);           //sout
        System.out.println(name);
//        System.out.println(flag);

        System.out.println("__________");
        // Integer extension

        // Base
        int i1= 10 ;
        int i2 =010 ;   // Octal
        int i3 =0x10 ; // Hex

        // Floating point number expansion about bank deposit

        //****It is best to completely avoid the use of valley points for data comparison. The reason is limited. The discrete rounding off is about but not equal to

        float f =0.1f  ;
        double d = 1.0/10 ;
        System.out.println(f==d);


       float d1 = 36723712982f ;   // Note the last f
       float d2 = d1 + 1 ;
        System.out.println(d1==d2);

     // Character expansion
        System.out.println("_______");
     char c1 = 'a' ;
     char c2 = 'Hong' ;

        System.out.println(c1);
        // Character cast
        System.out.println((int)c1);

        System.out.println(c2);
        System.out.println((int)c2);
       // Indicates that all characters are essentially numbers
        // Encoding Unicode table (97=a 65=a) 2 bytes 0~65536 2^16 = 65536 (Excel initial maximum capacity)

        // U0000~ UFFFF
        char c3 = '\u0061' ;
        System.out.println(c3);   //a

    }
}

Three coding differences

https://blog.csdn.net/skh2015java/article/details/80500482

Escape character

/t /n

Type conversion

variable

static before class variable

public class variable_04 {
    // Attributes: Variables

    // Class variable static
    static double salary = 35000 ;

    // Real column variable: the default value of this type is 0 if the dependent object is not initialized automatically
    //  The default value for Boolean values is false
    // null except basic type

    String name ;
    int age ;    /* public static void main(String[] args) defined outside the method
                 Belongs to class public class variable{
                  */

    // main method
    public static void main(String[] args) {

        int a=1 , b=2 ,c=3 ;   // Local variables must have a life cycle of declared and initialized values
        String name = "LZH.create" ;
        char x = 'X' ;
        double pi = 3.14 ;


         // Real column variable calling method

        // Variable type variable name = new variable()
        variable_04 variable = new variable_04() ;
        System.out.println(variable.name);
        System.out.println(variable.age);


        // Class variable call
        System.out.println(salary);

        }
    // Other methods
    public void add(){
        System.out.println("");
    }
}

constant

public class Demo {
 // Modifier, no order of precedence
  static final double PI = 3.14 ;
    public static void main(String[] args){
     System.out.println(PI) ;
    }
}

operator

Bitwise Operators

Shift left shift right

public class operator_05 {
    public static void main(String[] args) {

        // ctrl + D copy the current line to the next line
        int a = 10 ;
        int b = 120 ;
        int c = 10 ;
        int d = 20 ;
        short e = 10 ;
        byte f = 8 ;

        System.out.println(a+b);
        System.out.println(c-b);
        System.out.println(c*d);
        System.out.println(c/d);
        System.out.println(c/(double)d);   //Pay attention to the difference between the above

        System.out.println(e+f);  // Output type is int


        System.out.println("______");
        // Self increase and self decrease
        int num = 3 ;
        int num1= num++ ;  //3 / / after executing this code, first assign a value to num1. In auto increment, it is equivalent to the following code
        // num = num + 1
        System.out.println(num);  // 4

        // num = num +1 ;   5
        int num2 = ++num ;   //  5

        System.out.println(num1);   //3
        System.out.println(num2);    //5

        System.out.println("________");
      //Power operation method
        double pow =Math.pow(2,3) ;
        System.out.println(pow);

        System.out.println("logical__________");
        //Logical logical operator
        // &&   ||   !
        //  Short circuit operation
        int x = 5 ;
        boolean y = (c<4)&&(x++<4) ;
        System.out.println(y);
        System.out.println(x);

        //Ternary operator 
        //Enter the big factory? Monthly salary over 10000: one salted fish
        

    }
}

Package mechanism

javaDoc

Function:

Generate help documents

1. using the command line

2. generate using IDEA

Posted by neoboffins on Tue, 31 May 2022 11:02:41 +0530