Java Basics 02

A, Java array

1. Array
(1) an array of: storing a plurality of container elements of the same data type.
(2) Characteristics: Each element has index starting from 0, the maximum length of index is -1.
(3) Definition Format
  A: Data Type [] array name; (this)
  B: Data type array name [];
initialization (4) of the array
  A: Dynamic initialization
    is given only to the length, the default value
    Example: int [] = ARR new new int [. 3];
  B: the static initialization
    values given, the system determines the length of
    example: int [] arr = new int [] {1,2,3};
    Starter: int [] arr = {1 , 2,3};
(. 5) of the Java memory allocation
  a: the local variable stack storage
  B: stack store all out new
  C: method region (object-oriented portions of the detailed explanation)
  D: native method area (system related)
  E: register (CPU usage)

  Note:
    a: variables local variables are defined in the method definition statement or a method.
    b: stack memory and heap memory of the difference between
      the stack: data used up, it disappeared.
      Heap: Each new things have come out of the address
        of each variable has a default value
          byte, Short, int, 0 Long
          a float, 0.0 Double
          char '\ u0000'
          Boolean to false
          reference type null
        data after use, recycling the garbage collector is idle.

2. The two-dimensional array
(1) element array is one-dimensional array.
(2) Format:
  A: Data Type [] [] array name = new data type [m] [n-];
  B: Data Type [] [] array name = new data type [m] [];
  C: Data Type [] [] = new array name data type [] [] {{...}, {...}, {...}};
  D: data type [] [] array name = {{... }, {...}, {...}};

3. Questions
(1) Java parameter passing problem in
  Java only passed by value.
    Basic types: the formal parameter change does not affect the actual parameter
    reference type: change form parameters directly affect the actual parameters

 

Two, Java object-oriented
Object-oriented 1.
(1) object-oriented
  object-oriented programming is based on process-oriented thinking
(2) object-oriented thinking characteristic
  A: is a more in line with our thinking habits of thought
  B: the complex things simple of
  C: let us become a commander from the executor
(3) example: the elephant put into the refrigerator

  A: What kind of it?
    Elephants, refrigerator, Demo
  B: Each class has what things?
    Elephant: go in
    the refrigerator: opening, closing
    Demo: main method
  C:? What Classes are directly related to what
    the Demo use features like elephants and refrigerator.

  Note:? How to make our operations more in line with the object-oriented thinking it
    A: What class
    B: What are the members of each class
    C: the relationship between class and class
(4) Classes and Objects
  A: things in the real world
    properties of things basic describe
    the functional behavior of things
  B: Java language, the basic unit is the class. So, we use the class to reflect the things in
  C: class
    member variable properties of things
    member method thing behavior
  D: Class: is a collection of related attributes and behavior of a group. It is an abstract concept.
    Object: a concrete existence of such things, it is a concrete example. (Object)
  Example:
    Student: Class
    Object: monitor
the definition and use of (5) Class
  A: Class definition
    member variables define the format the same as before, that is, different positions in the class, method outside.
    Member methods define the format as before, it is to get rid of the static.
  B: A class of content
    a: create an object format?
      Class name object name = new class name ();
    b: how to use the member variables and member methods do
      object name member variables.
      Object members method ().
(6) the Java program development, design and features
  A: Development: is to constantly create an object, the object by calling the function
  B: Design: is the relationship between the management and maintenance of the object
  C: features
    a: Package
    b: to inherit
    c: polymorphism

2. The difference between the member variables and local variables (understanding)
(1) in a position different from the class
  member variables: the outer class methods
  local variables: the method definition or method declaration
(2) different positions in memory
  member variables: in the heap
  of local variables: the stack
(3) the life cycle of different
  member variables: with the creation of the object exists, the object disappear with the disappearance of
  local variables: with call a method exists, along with the method call is completed disappear
(4) the initialization value of the different
  member variable: there are defaults
  local variables: no default, you must define, assign, and then you can use
3 kind of problem as a form of argument
  if you see the parameters of a method is needed is a class name , you should know where you really need is a specific object.

4. anonymous object
(1) is not the name of the object
(2) application scenario
  A: method is called only when called only once.
  B: can be passed as actual parameters.
The package
(1) hide implementation details, providing a common access method
(2) Benefits:
  A: hide implementation details, providing a common access method
  B: to improve the reusability of code
  C: increased security code
(3) Design the principle of
  the outside world do not want to know the implementation details hidden, providing a common access method
(4) private is a reflection of the package.
  Packaging: Class, Method, private member variables modified

6. private key
(1) private significance, member variables and member methods can be modified
: (2) the characteristics of
  the members after being modified private can only be accessed in this category
(3) private applications:
    member variables general the declared private, and provides a corresponding getXxx () / setXxx () method

7. this key
(1) on behalf of the current class object reference
  which object method call inside the method this represents that object
(2) this application scenarios:
  to solve the local variables hidden member variables of the problem

8. The method of construction
(1) effect: to initialize the data object
(2) Format:
  A: same as the class name and method name
  B: No return type, can not have even the void
  C: no return value
9. Questions :? could have constructor return statement it
  can. But we write like this on OK: return. In fact, in the last method of any of void type you can write: return;
Note (3) construction method
  A: If we did not write the constructor, the system will provide a default constructor with no arguments
  B: if we gives the construction method, the system will no longer provide a default constructor
    if this time, we have to use the constructor with no arguments, it must be given its own.
    Recommended: always give yourself manually non-constructor parameters.
(4) to a member variable assignments of
  A: setXxx ()
  B: parameterized constructor

10. Code:? Student s = new Student ( ); What do something
  (1) loads the file into memory Student.class
  (2) s open space in memory for the stack
  (3) in the target application heap memory space for students
  ( 4) to students of member variables default initialization. null, 0
  (5) for display to students initialize member variables. Xiaoming, 17
  (6) to the member variables are initialized by the constructor. Xiaogang, 18
  (7) object construction is completed, the address is assigned to the variable s
11. static key
(1) static meaning. Member variables and member methods can be modified.
(2) static characteristics:
  A: With the load and load class
  B: Priority object exists in
  C: All classes of objects are shared
    Actually, this is our judgment should or should not use a static basis. For example: Problem drinking cups and reflection
  D: by class name calling
    either by object name calling, or by calling the class name recommended by the class name calling.
(3) static memory map
  static content in the region of the static area method
(4) static considerations;
  A: this is not the object in a static method
  Static Static can only access: B
difference (5) of the member variables and static variables
  A: different ordinary
    static variables: belong to the class, class variables
    member variables: belong to the object, the object variables, instance variables
  B: different memory locations
    Static variables: Static methods zone area
    member variables: heap
  C: different life cycle
    Static variables: Static variables are loaded with class and loaded disappear with the disappearance of class
    member variables: member variables are with the creation of the object exists, the object disappear with the disappearance of
  D: call different
    static variables: You can call by object name, or by calling the name of the class
    member variables: only through the object name calling
(6) main method is static the
  public: permissions maximum
  static: do not create an object invocation
  void: the return value does not make sense to jvm
  main: is a common name.
  Flexibility may receive data, the program providing: String [] args
    format: java MainDemo hello world java / java MainDemo 10 20 30

Guess you like

Origin www.cnblogs.com/nomad1c/p/11605509.html