First day of Java learning

1. First of all, I made a study plan for myself, including five parts. 2. Today I will start the first part of the basic theory of Java. (It is recommended to record your daily learning in order to keep deep memory and knowledge in mind.)

knowledge

1. Identifiers: Java language identifiers are composed of letters, underscores, dollar signs (which can start with an initial letter), and numbers. The first character cannot be a number, but the characters of each country include Chinese characters. Keywords cannot be identifiers, Boolean constants cannot be identifiers (true, false), null cannot be constants, and identifiers are case sensitive

2. Keywords: symbols of special meaning, to put it bluntly, are fixed phrases that will appear in Java code. Common: — if, else, switch, case, while, default — private, protected, public, static, constant — int, short, byte, long – This, super, implements (interface), extends (extends), throws an exception -throw, throws, finally, finally, try, catch… The ones listed here are common. Keywords are meant to be officially used by developers who write the Java language, but not by ordinary developers who define their own methods.

3. What are the basic data types of the Java language? Byte Short int Long Double float CHAR Boolean Eight basic data types.

4. Size of base data type: default (initial)

  • Byte: 1 byte, the value ranges from -128 to 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: two bytes 0
  • Boolean: Size cannot be determined false

5. Why can’t long be converted to int? The first thing you need to know is the byte size of each base type. Long is 8 bytes and int is 4 bytes, which will overflow when converted. This also happens in practice.

6. Wrapper classes: Primitive types in Java are not object-oriented, for example: int a=5; Object is User User =new User (); The default value of a wrapper class can be null. The default value of a wrapper class can be null. The default value of a wrapper class can be Integer — int and Character — char. When to use packing classes and when to use basic types depends on the basic business: This field does not allow null values. If null values are allowed, then the wrapper class must be used. Otherwise, the value type can be used.

7. Constants and variables: Constants: Constants in the Java language include integer constants (common base 2, base 10), floating point constants (123., 98F, 123E +3), Boolean constants, character constants, string constants (” hello world “), null constants. Variables: Java variables are typed at compile time. Commonly divided into two types: 1. Common data type variables 2. Reference data type variables. Classes, interfaces, arrays

8. Variables:

  • Variable types: (1) Class variables: include class variables and interface variables. Use the modifier static when defining class variables, but do not use the modifier static for interface variables. When creating a class or interface, variables are initialized with default values; When you unload a class or interface, its variables disappear. Static code blocks are executed when the JVM loads a class. Each code block is executed only once, and in sequence. Static variables don’t even need to be accessed through an object, just the class name. Variable name “to access…)
`package JavaTest;
public class LearnStatic {
    static int i=1;
    static {
        System.out.println("Static module called");
        i++;
    }
    public LearnStatic(a){
        System.out.println("The value of B is");
        i++;
    }
    public static void main(String[] args) {
            LearnStatic l1=new LearnStatic();// Use the object name to access
            System.out.println(l1.i);
            LearnStatic l2=newLearnStatic(); System.out.println(l2.i); }} The static module is called b with the value of3A value of b4` 

*   1
*   2
*   3
*   4
*   5
*   6
*   7
*   8
*   9
*   10
*   11
*   12
*   13
*   14
*   15
*   16
*   17
*   18
*   19
*   20
*   21
*   22
*   23
*   24


Copy the code
  • Instance variables: Class variables that do not use the modifier static.

  • Local variable: A variable declared in a constructor, method, or block that is only valid within its internal declaration scope. — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — Java variable type — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — –! One of the pitfalls with this link is that methods are independent of methods, which are constructors and so on, but exist in classes.

  • Final variables: Variables that use the modifier final can be assigned only once, and their value does not change during program execution. Public static final double PI=3.1415926 public static final double PI=3.1415926

Operators and expressions

  • Arithmetic operators: the rule is to multiply and divide before adding and subtracting. Parentheses and unary operations take precedence. Parentheses can be used to change the order in which expressions are evaluated. Common operators: ++, -, (note the order of the increment and the subtraction, for example: a++, the first operation after the increment, ++a first increment after the operation), do more questions.

  • Relational operator: Compares two numeric types of data, resulting in a Boolean operation. Common relational operators: >,<,>=,<=,==,! = (it is important to note that = : is an assignment, == denotes the equals sign)

  • Logical operators: The result of a logical expression consisting of logical operators is also Boolean. Divided into standard logical operators (&, |! The condition and logical operators, &&, | |), there will be an interview question!!!!!

  • Important: Standard logical operators need to evaluate all subexpressions to get a result. When “&” is used, it explicitly indicates that multiple conditions are evaluated. If a condition returns false in multiple expressions, the remaining conditions are evaluated as well. Conditional operators: && (short-circuited and) : When using “&&”, return false if there are any conditions, and return false if there are any remaining conditions.

  • Conditional operator: trinary operator: < expression 1>? < expression 2>:< expression 3>***********x>y? X :y if x is greater than y, the result is x, and vice versa.