directory

  • Learning materials
  • annotation
  • The keyword
  • identifier
  • The data type

Learning materials

B station crazy god said: www.bilibili.com/video/BV12J…

annotation

public class HelloWorld {
    public static void main(String[] args) {
        // Single-line comment
        System.out.println("Hello,World");
        
        /* Multi-line comments */
        
        /** Documentation */  
        /* * Document comments, which can be generated using Javadoc * * * */}}Copy the code

The keyword

abstract assert boolean break byte
case catch char class const
continue default do double else
enum extends final finally float
for goto if implements import
instanceof int interface long native
new package private protected public
return strictfp short static super
switch synchronized this throw throws
transient try void volatile while

identifier

  1. All identifiers should start with A letter (a-z or a-z), 💲, or underscore (_)
  2. Class name (noun) uppercase: Users, TestDemo
  3. Method name (verb)/ variable name (noun) lowercase: getUsername, age
  4. Constants in all uppercase, multiple words connected with _ : USER_NAME
  5. Package name all in lowercase: com. company name. Project name module name

The data type

Java is a strongly typed language and variables need to be defined before they can be used

Graph LR Java data type –> 8 basic data types –> Numeric type –> Integer type Integer type –> byte — 1 byte range :-128 to 127, default :0 Integer type –> Short Two bytes range :-32768 to 32767, default value :0 Integer type –> int Four bytes range :-2147483648 to 2147483647, default value :0 Integer type –> Long Long integer length 8 bytes Range :-9223372036854775808 to 9223372036854775807, default value :0 Numeric type floating point type floating point type float 4 bytes, default value: 0.0 Floating point type –>double 8 bytes, default value 0.0 Numeric type –> character type char 2 bytes, default value eight basic data types –> Boolean Boolean Boolean –> 1 byte, value range :true and false, default value false Java data type –> reference data type Reference data type –> class, default value is null reference data type –> interface, default value is null reference data type –> array, default value is NULL

public class DataType {

    public static void main(String[] args) {
        // Eight basic data types

        / / integer
        // Define an integer of type int by default
        int intValue = 10;
        byte byteValue = 20;
        short shortValue = 30;
        long longValue = 5000000000000L;

        / / octal
        int intValue8 = 010;
        System.out.println(intValue8);

        / / decimal
        int intValue10 = 0x10;
        System.out.println(intValue10);

        / / floating point number
        float floatValue = 5.25 F;
        // Float numbers defined by default are of type double
        double doubleValue = 5.235;

        // The character, which is also a number in nature, can be strong with (int)
        char charValue = 'a';
        System.out.println((int)charValue);
        char charValueUnicode = '\u0061'; // a
        System.out.println(charValueUnicode);

        / / a Boolean value
        boolean trueValue = true;
        boolean falseValue = false; }}Copy the code