Java Notes - Array Strings and Containers, Expression Flow and Control Flow, Introduction to Getting Started, Data Type Identifiers

  • 1.1
  •  
    • JDK>JRE>JVM
  • 2 Identifiers and data types
    • Process-oriented languages: C, FORTRAN, COBOL, ALGOL, PASCAL, BASIC
      • Object-oriented languages: Simula, Smalltalk, Java, Ruby, etc.
      • Both languages: C++, Python
    • von Neumann structure

    • JAVA keywords - cannot be used as identifiers
    • JAVA uses Unicode (16 bits) instead of ASCII (8 bits)
      • An identifier is a string of letters, numbers, underscores ( _ ) or dollar signs ($$) beginning with a letter, an underscore ( _ ) or a dollar sign ($$), and is case-sensitive
    • JAVA data type

      • boolean: false/true 8th place
      • char: 16 bits
      • Integer type number range
        • All integers in Java are signed numbers. Integer constants are of type int. If you want to represent a long integer constant, you need to write the letter "L" after the number
      • Float type data range
        • Float if the value contains a decimal point, an exponent part (e), or is followed by the letters f/F (single precision) or d/D (double precision)
        • Type conversion: automatic conversion from a type with a small number of digits to a type with a large number of digits, otherwise a mandatory conversion is required
    • classes and objects
      • Storage modifier static: can be shared by all objects of the class
      • final: A class modified with final can no longer derive subclasses, and it has reached the bottom of the class hierarchy
      • abstract: A class or method modified with abstract indicates that the modified component is abstract. The abstract method only needs to give the prototype description, the method body is empty, and the class containing the abstract method must be described as an abstract class
      • Object reference: Create a reference to it in memory, and set the initial value to null, indicating that it does not point to any memory space.
      • Object instantiation: use new to apply for the corresponding memory space, the size of the memory space depends on the definition of the class, and assign the first address of the memory to the reference created just now
  • 3 Expression Flow and Process Control
    • operand
      • final: constant definition, not allowed to be modified after definition
        • Do not use static modification: If you assign a fixed value directly when creating a constant, then the value of this constant is fixed, that is, the values ​​in multiple objects are also the same. If a function or object is used when creating a constant, the initialization value of the constant may be different each time the object is created
        • Use static modification: before creating an object, a storage space will be created for this variable in memory, and if this static variable is needed to create an object later, then the storage space of this variable will be shared
      • Complement code highest sign bit: positive number sign is 0, negative number is 1; operations involving negative numbers use complement code
        • The positive number’s complement code is directly added to the sign bit 0, and the negative number’s complement code is first inverted bit by bit on the basis of the original code, and then one is added to the sign bit
  • 4 Arrays of Strings and Containers
    • array
      • One-dimensional array definition: type arrayName[]; No memory is allocated when defining, and the length is not declared in [], but the reference variable is used to point to an array
        • Type[] arrayName;
      • Create an array: static initialization: define and initialize elements at the same time
        • Dynamically initialize type[] arrayName=new type[arraySize];
          • type arrayName[]=new type[arraySize];
      • Composite type array: type arrayName[]=new type[arraySize];
      • Use toString to traverse the array
      • Two-dimensional array definition: type arrayName[][];
        • type[][] arrayName;
      • Multi-bit array static initialization: int[][] intArray={ {2,3}, {1,5}, {3,4}};
        • Dynamic initialization of multi-bit arrays:

      • Array copy: arraycopy
      •  
        • copyOf
        • copyOfRange
    • enumeration enum enumeration name {constant list}
      • An enumeration type can return a one-dimensional array in the following form: the name of the enumeration type.values();
        • for(Weekday b:Weekday.values()) {System.out.print(b+" ");}
        • switch enumeration using enumeration constants
    • String:
      • String is an immutable character string. When allocating memory, it is allocated in equal amounts according to the actual number of characters contained in the object.
        • The concat(String str) method connects str at the end of the current string, and "+" can realize the string connection operation.
        • Common methods:

        • The comparison methods in the String class are compareTo(), equals(), equalsIgnoreCase(), regionMatches()
        • public boolean regionMatches(int toffset, String other, int ooffset,int len)或 public boolean regionMatches(boolean ignoreCase, int toffset, String other,int ooffset,int len)
      • StringBuffer is a variable string. When allocating memory, a buffer of 16 characters is added in addition to the space occupied by characters.
        • length() to get the length of the string
        • capacity() returns the buffer capacity
        • Use the append() method to implement the connection
    • container
      • Collection
        • set elements are unordered and non-repeatable
        • lisr ordered and repeatable

          • LinkedList: Its data structure uses a linked list. The advantage of this structure is that deletion and addition are very efficient, but the efficiency of random access to elements is lower than that of the ArrayList class.
          • ArrayList: Its data structure uses a linear table. The advantage of this structure is that it is very convenient to access and query, but it is very inefficient when adding and deleting. S
        • queue determines the order according to the rules
        • HashSet: Duplicate elements are not allowed in it, and a duplicate element cannot be added, and the query efficiency is optimized by using the Hash function.
        • HashMap: Provides a key-value key-value pair data storage mechanism, it is very convenient to find the corresponding element through the key value, and through the Hash hash mechanism, the search is very convenient.

        • iteratorfor(Iterator it=courses.iterator();it.hasNext();) {course=(Course)it.next();...}
          • boolean hasnext(); //Check if there are more elements in the sequence
          • Object next(); //Get the next element in the sequence
          • void remove(); //delete the current element in the iterator
        • All classes that can be "sorted" implement the Comparable interface. There is only one method public int compareTo(Object obj) in the Comparable interface

Guess you like

Origin blog.csdn.net/qq_56061892/article/details/126224221