My first day of learning Java in Shanghai LeByte

The first day of Java learning


1. First, to develop their own learning plans, including five parts.
2. Start the learning of the first part of Java basic theory today. (To make their own memories, bear in mind that knowledge, it is recommended to record their daily learning) knowledge


1 identifier: the identifier of the Java language is made up of letters, underscores, dollar sign (led letters may be) , and numbers. The first character cannot be a number. The letter means the characters of various countries including Chinese characters. Keywords can not be an identifier, Boolean constants can not identifier ( to true, false ), null is not a constant , identifiers are case-sensitive 2 Keywords: the special significance of the symbol, it means there will be in Java code The fixed phrase. Common: When choosing to judge- if, else, switch, case, while, default , when modifying variables-private, protected, public, static, when modifying constants (the expression may be inaccurate here)-int, short, byte, long, Double, float, char, -this, super, implements (interface), extends (inheritance), throwing exceptions -throw, throws, finally, try, catch in the parent class and subclass ... are common when listed here. The meaning of the keyword is that the developer who made the Java language is regarded as an official special purpose, and ordinary developers cannot define it as their own method. 3 . Pen questions will arise a problem: the basic data types Java language of what? byte short int long double float char boolean 8 basic data types. 4





Basic sizes of data types: the default value (initial value)

  • byte: 1 byte, -128~127 0
  • short: 2 bytes 0
  • int: 4 bytes 0
  • long: 8 bytes 0L
  • float: 4 bytes 0.0f
  • double: 8 bytes 0.0d
  • char: 2 bytes 0
  • boolean: can not determine the size of the false 5 written there will be a question: why long int type can not be converted to type? First, you need to know the byte size of each basic type. Long is 8 bytes, and int is 4 bytes, which will overflow during conversion. This situation also occurs in actual operation. 6 . Packaging: Java is not the type of basic object-oriented, for example: int a = 5; refers to objects User user = new User (); return to the topic, and packaging is that it gives value defaults to null , packaging Except for Integer-int and Character-char, all other classes are capitalized: byte—Byte, double—Double, boolean—Boolean. (Auto-boxing and auto-unboxing-conversion between basic data types and packaging types) When to use packaging types and when to use basic types, it depends on the basic business: this field allows null values, if allowed For null values, wrapper classes must be used, otherwise value types are fine. For example, generics and reflection call functions are used. Packaging classes are needed! 7 constants and variables: Constants: Constants in the Java language has integer constant (common are binary, decimal), floating-point constants (123., 98f, 123e + 3 ), Boolean constants, character constants , String constant ("hello world"), null constant. Variables: Java variables determine their type at compile time. Usually divided into two types: 1. Common data type variables 2. Reference data type variables. Class, an interface, an array of 8












    The variables go into the details:
  • Variable types: (1) Class variables: including class variables and interface variables, the modifier static is used when defining class variables, and the modifier static is not required for interface variables. When a class or interface is created, the variables are initialized according to default values; when the class or interface is unloaded, the variables disappear. (In my own understanding, class variables can also be called static variables. They are variables in the class independent of the method body. They need to be modified with static. Static means global and static. Static code blocks will be executed when the jvm loads the class. each code block is executed only once, and is performed sequentially, static variables do not even need to access the object via a direct "class name variable name" to access ..)
`package JavaTest;
public class LearnStatic {
    
    
    static int i=1;
    static {
    
    
        System.out.println("静态模块被调用");
        i++;
    }
    public LearnStatic(){
    
    
        System.out.println("b的值为");
        i++;
    }
    public static void main(String[] args) {
    
    
            LearnStatic l1=new LearnStatic();//采用了对象名来访问
            System.out.println(l1.i);
            LearnStatic l2=new LearnStatic();
            System.out.println(l2.i);
    }
}
输出结果:
静态模块被调用
b的值为
3
b的值为
4` 
​
*   1
*   2
*   3
*   4
*   5
*   6
*   7
*   8
*   9
*   10
*   11
*   12
*   13
*   14
*   15
*   16
*   17
*   18
*   19
*   20
*   21
*   22
*   23
*   24
​
​

  • Instance variables: class variables that do not use the modifier static.

  • Local variables: Variables declared in constructors, methods, or program blocks are only valid within the scope of their internal declarations.
    --------------------------------------- Java variable type -------- ----------------------------------------
    ! Through this link, there is a misunderstanding. First of all, it is independent of the method. The method is the construction method, but it will exist in the class.

  • Final variable: A variable that uses the modifier final can only be assigned once, and its value will not change during the execution of the program. (It will never change and will not change with the environment)public static final double PI=3.1415926


9 . Operators and expressions

  • Arithmetic operators: The rule is to multiply and divide first and then add and subtract. Parentheses and monocular operations take precedence. You can change the calculation order of expressions through parentheses. Common operators: ++, -, (note the order of increment and decrement, for example: a++, first increment and then increment, ++a first increment and then decrement), do more questions.

  • Relational operator: compares two numeric data, the result of the operation is Boolean. Common relational operators: >,<,>=,<=,==,!=
    (Note that =: is an assignment, and == means an equal sign)

  • Logical operator: The calculation result of a logical expression composed of logical operators is also Boolean. Divided into standard logical operators (&, |,!) and conditional logical operators (&&, ||), there will be interview questions! !

  • Important: Standard logical operators need to evaluate all sub-expressions before they can get results. When using "&", it clearly indicates that multiple conditions are judged. If there are conditions in multiple expressions that return false, the remaining conditions must also be judged; conditional logic operator: && (short-circuit AND): When used "&&", as long as there are conditions to return false, the remaining conditions are no longer judged, and false is returned.

  • Conditional operator: Ternary operator: <Expression1>?<Expression2>:<Expression3>***********x>y?x:y If x is greater than y, it is true, The result is x, otherwise y.

Guess you like

Origin blog.csdn.net/dirft_lez/article/details/109162447