Summary of java programming exercises

---Restore content begins---

  1. The parameter names of the main() method can be changed; the number of parameters of the main() method cannot be changed.
  2. When a program does not have a main() method, it can be compiled, but cannot be run because a main function entry cannot be found.
  3. Identifiers consist of letters, numbers, underscores, and dollar signs; they cannot start with numbers, and are case-sensitive.
  4. boolean (boolean type) has only two values, true and false, without 0 and 1.
  5. Java data types are divided into simple data types (8) and complex data types (class interface Array, etc., no interface type)
  6. In the same priority, it is calculated according to the combined order. Most operations are evaluated from left to right, and only three precedences are associative from right to left, they are the unary operator, the conditional operator, and the assignment operator.
  7. x=5;y=x--;z=--x; the result is: 4, 4 priority problem
  8. The new operator is used to instantiate objects and arrays: create an array int[] a = new int[6] or int a[] = new int[6]
  9. The length of the array in java is to use the variable length; such as: a.length;
  10. Java variables are divided into three categories: member variables, local variables, static variables;

    The scopes are: current object, method inside, class;

   Local variables: variables defined in the method body, local variables are only valid in the method in which it is defined.

   Member variables: are valid in the entire class (global variables are called in the C language, there is no concept of global variables in Java).
     Member variables are further divided into instance variables (non-static variables) and class variables (static variables).
       Instance variables: variables that are not modified with the static keyword are also called properties. For different objects of the class, properties are different of.
      Class variable: a variable modified with the static keyword, there is only one variable in a class, and different objects of the class share the same static member variable.

   11. Object memory allocation: JVM memory is divided into 5 areas: method area, heap, stack, PC register and local method stack;

   Method area: a logical memory area used to store loaded type information and class variables;

   Heap: All instances or arrays created at runtime are placed in the same heap. There is only one heap space for a jvm instance, and all threads will share this heap;

   Stack: Every time a new thread jvm is started, a java stack is allocated to it, and the java stack saves the running state of the thread in frame units;

   Stack frame: consists of local variable area, operand stack and frame data area;

   Native method stack: Java programs often call native methods, and native methods can access the data area of ​​the jvm at runtime through the native method interface, so a running java program may use some data areas related to native methods, namely: local method stack;

  12. transient: declare a variable as a temporary variable. When the object is no longer used, jvm needs to save all member variables and methods of the object. If you want jvm to ignore the saving of variables, you can use transient to define temporary variables; transient int id ;

  13. volatile: Declare synchronous variables and protect variables from being asynchronous. In a multi-threaded operating environment, a member variable may be modified by multiple threads. Use volatile to declare variables and maintain the consistency of variables between concurrent threads;

  14.native: Define local methods for Java cross-language system bottom-level operations;

---End of recovery content---

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325115115&siteId=291194637