20165320 Graduation second weekly summary

20165320 Graduation second weekly summary

And task completion

on Monday on Tuesday on Wednesday Thursday Friday on Saturday Zhou
Java Basics Review
Java Basics Review
Java Basics Review
Opening report writing
Opening report writing
Document translation
to sum up
completed
completed
completed
completed
completed
completed
completed

Content summary

First, the memory is divided into five parts of Java

  • Stack: local variable storage method (parameters of the method, the method of internal variables), the method needs to be run in the stack.
  • Heap: new out of something (variables, objects) are placed in the heap, the heap data has a hexadecimal address value, and has a default value.

    • Int Default 0
    • Float Default 0.0
    • The default character is '\ u0000'
    • The default is false boolean
    • The default reference type is null
  • Method Area: storing .class information includes method information.
  • Native method stacks: the operating system.
  • Register: CPU-specific.

  • A simple array instance:

  • A simple object instance:

Second, encapsulation

  • Hide some details, invisible to the outside world, reflects: Methods and keyword private, while some properties are reasonable protection.

  • Private member variables for modification, should define a couple of Get Set method of access. Wherein for Boolean type, get isXxx method should be written in the form

  • Simple examples are as follows:

      class person{
          private int age;
          public void Setage(int age){
              this.age = age;
          }
          public void Getage(){
              return age;
          }
      }

Third, a standard class

  • Private modified to use all of the member variables.
  • Get and Set methods for the preparation of each member variable.
  • Write a no-arg constructor.
  • Write a full-arg constructor.

  • Simple examples are as follows:

      class person{
          private int age;
          public person(){}
          public person(int age){
              this.age = age;
          }
      }

Four, Arrylist <> easy to use

  • Arrylist <> is a variable-sized array, <> is represented in the generic, only a reference type, it can not be the basic type (byte, short, int, long, float, double, char, boolean), if necessary , you can use a wrapper class (Byte, Short, Integer, Long, Float, Double, Character, Boolean). JDK1.5 from the start, auto boxing and unboxing.

  • Common methods:

    • Gets the element from the collection: public E get (int dex) //参数是索引编号
    • Add elements from the collection: public boolean add (E e) //参数是泛型
    • Remove elements from the collection: public E remove (int dex) //参数是泛型
    • Gets the collection length: public int size ()
  • A simple example:

      public class Main {
          public static void main(String[] args) {
      ArrayList<String > qhb1653 = new ArrayList<>();
    
      //向全华班中添加人员
    
      boolean success = qhb1653.add("曹大学姐");
      qhb1653.add("李门头");
      qhb1653.add("孙WJ");
      qhb1653.add("勺王申");
    
      //打印集合中的数据
      System.out.println("组成人员:"+qhb1653);
    
      //获取集合数据
      String leader = qhb1653.get(1);
      System.out.println("头头是"+leader);
    
      //删除GK No.1
      String nb =qhb1653.remove(2);
      System.out.println("被删了的人是:"+nb);
    
      //获取集合长度
      int num = qhb1653.size();
      System.out.println("全华班的人数为:"+(num+1));
          }
      }

Five String String

  • Contents of the string never change, can be shared, the effect is equivalent char [] array of type characters, but the underlying principle is the byte [] array of bytes.

  • Four Structures common method:

    • Create a blank array is empty: public String ()
    • According to the contents of an array of characters, create the corresponding string:public String (char[] array)
    • The content byte array, creates a corresponding string: public String (byte[] array)
    • Direct String: String str = " "PS: direct string of double quotation marks in a string constant pool.
    • Simple example:
  • For this type of reference string, the address value is compared == Comparison needed content equals.

      String str1 = "ABC";
      char [] charArray = {'A','B,'C'};
      String str2 = new String (charArray);
      System.out.println(str1.equals(str2);
  • Common methods:

    • Get string length: public int length()
    • The current string parameter string concatenation:public String concat (String str)
    • Gets the index position of a single character:public char charAt (int index)
    • Find the index position of the first occurrence of the string parameter in this string:
      public int indexOf(String str)
    • Taken from a position to the end of the string parameter and returns the new string:public String substring(int index)
    • Taken from the start to begin the end of the string end:public String substring(int begin,int end)
    • String replaces:public String replace(old String , new String)
  • A simple example:

Sixth, keyword

  • Static keyword: if a member variable / method uses static keyword, the variable / method no longer belong to the object, but belong to the class, sharing multiple objects, static methods can directly use the class name called.

    • Note: Static can not access non-static, can not use this keyword, regardless of when the object based on the class name to access static member variables.
  • Simple example:

Seven: inheritance

  • Inherit the main solution is to extract the common subclasses can have the contents of the parent class, you can also have their own proprietary content.

  • format:public class A extends B {}

  • Features member variable access the same name:

    • Access to member variables directly by subclass object, priority sub-category, if not looking up.
    • Indirect access to member variables by members of the method, the method in which class inside, priority class member variables which are used, there is no looking up.
  • When you create a subclass object, access method members, who object is a priority with anyone, not looking up.

  • Rewrite: The name of the parameter list @Overri methods are the same.

    • The return value must be less than the subclass method equal the parent class method returns the value range.
    • Permissions subclass method must be greater than the parent class method permission modifier.
  • Subclass constructors have a default super () call, first call the parent class constructor, and then perform the subclass constructor.

  • FIG memory of this super

  • Java inheritance of characteristics:

    • A subclass of the direct parent can have only one.

    • Parent class can inherit a multi-stage, multiple sub-categories.

Eight: abstract classes and abstract methods

  • Abstract methods: abstract plus keywords, remove the braces, the method body content uncertain.
  • Abstract class: abstract class where the method must be abstract class.

  • Instructions:

    • Can not directly create an abstract class object must inherit the abstract parent class with subclasses.
    • Subclasses must override abstract parent class abstract method override keyword, an abstract method to remove.
    • Create a subclass object to use.
  • Simple example:

      public abstract class LaoBa{
          public abstract void eat();
      }
    
      public class sxz extends LaoBa{
          public void eat(){
              System.out.println("奥利给,干了兄弟们");
          }
      }

IX Interface

  • Interface specification is common to a plurality of classes, a data type, the most important element is the abstract methods wherein a reference. Implementation class must override all the abstract methods overridden.

  • Format is as follows:

      public interface 接口名称 {
          //接口内容
      }
    
      public class 实现类名 implements 接口名{
         // 实现接口内容
      }
  • Among abstract methods interface, default modifiers are two fixed keyword: [public] [abstract] 返回值 方法名 (参数列表) {方法体}.

  • The default method can solve the problem of the interface upgrade:[public] [default] 返回值 方法名 (参数列表) {方法体}

  • Static methods:public static 方法名 (参数列表) {方法体}

  • Private Method: extracting a common method, solution between the two duplicated code default method / static methods problem. private [static] 返回值 方法名 (参数列表) {方法体}After jdk9 to use only the interface itself, it can not be invoked implementation class.

  • Among constant interface must be explicit assignment, and constant name by default capitalized fully [public] [static] [final] 返回值 方法名 (参数列表) {方法体}modified.

  • The method of construction can not have an interface, not a static block.

X. polymorphism (this part of the current contact less)

  • Polymorphic compiled into polymorphic polymorphic running, a heavy load is achieved by the first method, covered by a second method.

  • By the time the class name to access member variables, see the left side of the equal sign.

  • Access to member variables by members of the method, see the method belongs to whom.

  • Formulas: access variables look left, look to the right method at runtime.

Problem to be solved next week & plan

  • The problem to be solved: a low learning efficiency, lack of concentration, in urgent need of improvement, previously learned a lot of knowledge, not a long time, forget ....
  • Next week's plan: to complete the defense opening report and review the basics of Java, began to enter the Android application development-based learning.

Guess you like

Origin www.cnblogs.com/Gst-Paul/p/12445918.html