20,182,301 2019-2020-1 "data structures and object-oriented programming," the first four weeks learning summary

20,182,301 2019-2020-1 "data structures and object-oriented programming," the first four weeks learning summary

Learning content summary

  • Define the core is the class of object-oriented programming, which represents defines the state and behavior of objects
    • toString method when the object passed to print and println method, and a method toString connected to a string object, the object will automatically call
public String toString()
{
    String result = Integer.toString(faceValue);
    return result;
}
  • Scope of a variable dependent variable declarations, scope determines where you can use variables
  • Package
    • Code does not allow direct access to the variable object, can only be called
    • Visibility modifiers access control class members. public, private and protected
    • Access Method: getX; setting method: setX; through which customers can manage data
  • return
    • The method specified Return Value Type header may be: basic type, class name, a reserved word void
    • The method should return type of the same type of return value and a predetermined method head
    • Only one method should return statement as the last line of the method body
  • parameter
    • When calling the method, the argument is copied into the parameter
    • Method, and parameter arguments alias each
  • Construction method
    • The method of construction can not have any return value, nor even the void
    • It used to initialize the newly created object
  • Static variables
    • eg:private static int count = 0;
    • Static variables are shared by all instances of the class
    • Local variables declared within a method can not be static
  • Static method
    • eg: Math class methods used are static
    • public static void main (String [] args) the use of static, so, main program run by an interpreter, without the need to instantiate.
    • Static method does not operate on specific objects
    • Static methods can only access static variables or local variables
  • polymerization
    • Other objects of the aggregate object formed has-a relationship
    • The polymerization is a special type of dependence
  • this reference
    • eg:if(this.positise==pieces.positise) result = fault;
    • this reference is used to indicate a location
    • Used to distinguish the constructor parameter corresponding instance variable of the same name (see the book P128)
  • Method overloading: allow multiple methods use the same method name but different parameter lists
    • When a method is invoked, control flow will be transferred by the method defined in the code
    • Overloaded methods versions distinguished by the number of parameters, and the order type
    • eg: type of the parameter, like the number of different
  • test
    • Audit: a technique used to evaluate the design or code
    • Defect testing: error can be found, black box testing
    • Unit Testing: create a test case for each test
    • Integration testing: test as a whole
    • System testing: observation needs
    • Test-driven development: first to write test cases, then the source code

Textbook learning and problem-solving process

  • Question 1: abstract classes and interfaces What is the difference
  • Question 1 solution: the abstract methods without specific written. Or to the abstract, or to instantiate
    • Abstract class non-abstract methods can exist; interface methods are abstract becomes the default method, as long as the definition of interfaces, interface methods will all become abstract class method is abstract it even if you do not write the abstract
    • The interface is an abstract class, it can be said interface is an abstract class that extends
    • An abstract class can have a private member variables and member methods; interface methods have all been modified to default: public abstract type of method
    • A class can inherit an abstract class A class can implement multiple interfaces, interfaces can achieve multiple inheritance example: interface display extends aa, bb, cc ... and so on, and then let the class to implement display interface can be achieved display aa bb cc Interface
    • Non-abstract methods abstract class may choose to inherit; interface methods must all be rewritten, is public and all public methods.
  • Question 2: There are several ways to create a new variable
  • Problem 2 Solution:
    • Keyword new. Packaging factory pattern is in this manner;
    • Class implements interfaces cloning, a clone instance. Prototype model is an application example;
    • With the class loader, newinstance. Reflection, reflection of Example java: Spring dependency injection, dynamic programming section Agent
    • Sun.misc.Unsafe create an instance of the class, allocateInstance method. (Java classes directly Unsafe official does not recommend the use of said Oracle is planning to remove Unsafe class from Java9)
    • Interface implementation class serialization, deserialization flow through the IO to read a class, instance obtained.
    • If the direct use of static variables
  • Question 3: Local and instance data What is the difference?
  • Figure 3 solution to the problem :( :)

  • Question 4: What is interaction?
  • Question 4 Solution:
    • Constructors transfer
    • By methods getX and setX
    • interface

Code debugging and problem solving in the process

  • Question 1: Coin (see below), why we need this, since there isHead why not write into?

  • Problem 1 Solution: flip method, random coins to the initial state;
  • Question 2: Account is free, why use?

  • Problem 2 Solution: I think this should be the initial credit limit, may advance expenses

Code hosting

Last week exam wrong question summary

  • In order to preserve encapsulation(封装) of an object, we would do all of the following except for which one?
    • A .Make the instance data private
    • B .Define the methods in the class to access and manipulate the instance data (the definition of the class methods to access and manipulate data instance)
    • C .Make the methods of the class public
    • D .Make the class final
    • E .All of the above preserve encapsulation
    • Right: D
    • Cause: a package means that class contains data and methods needed to manipulate the data. In order to properly retain the package, instance data should not be accessed directly from outside the class, instance data is private, and define methods to access and manipulate data instance. Further, access data instance and method of operation are disclosed, so that other classes can use the object. Reserved word "final" for controlling inheritance, regardless of the package.
  • Consider a sequence of method invocations as follows:. Main calls m1, m1 calls m2, m2 calls m3 and then m2 calls m4, m3 calls m5 If m4 has just terminated, what method will resume execution (Consider the following sequence of method calls:? Lord call m1, m1 m2 calling, call m2 m3, m2 and then call the m4, m3 calls m5. If m4 has just terminated, what methods will resume execution)
    • m2
  • A variable whose scope is restricted to the method where it was declared is known as a (n) (A variable's scope is limited to its declaration of a method, called A (n))
    • A .parameter (parameters, coefficients)
    • B .global variable (global variable)
    • C .local variable (local variable)
    • D .public instance data (data common examples)
    • E .private instance data (private instance data)
    • Correct: C
  • A class' constructor usually defines
    • A .how an object is initialized
    • B .how an object is interfaced
    • C .the number of instance data in the class
    • D .the number of methods in the class
    • E .if the instance data are accessible outside of the object directly
    • Right: A
    • Reason: The constructor should be used to "structure" objects, i.e., set the initial value of the data instance. This is not required, but usually do so. Visibility modifier used by the interface object instance data and the determined method.
  • The following method header definition will result in a syntax error: public void aMethod( );
    • Right: true
    • The reason: The reason is that it syntax error ";" the end of the symbol. Instead, it requires zero or more in brackets {} followed by the instruction. Abstract method will be ";" end, but the head does not define abstract methods.
  • While multiple objects of the same class can exist, in a given program there can be only one version of each class
    • Right: true
    • Reason: is an abstract class, that is, it exists as a defined, rather than as a physical instance exists. Create a physical example of the use of new instantiate an object. Therefore, there are many objects of type String, but only a String class.
  • An object should be encapsulated in order to guard its data and methods from inappropriate access.
    • Right: true
    • Reason: this package is a concept: it should be protected from accidental (or object) misuse.
  • Accessors and mutators provide mechanisms for controlled access to a well-encapsulated class.
    • Right: true
    • Reason: Access provides read access to variables, these variables are otherwise inaccessible. mutator provide write access to a variable otherwise inaccessible of
  • Java does not support multiple inheritance, but some of the abilities of multiple inheritance are available by
    • correct:
    • A .importing classes
    • B .implementing interfaces
    • C .overriding parent class methods
    • D .creating aliases
    • E .using public rather than protected or private modifiers
    • Correct: B
    • The reason: because a class can implement any number of interfaces, so use interface class on the class nature, as if these interfaces are the same as defined in this class. This class inherits the methods and constants interface. Further, the class may extend another class, thereby inherited more classes directly or indirectly. This is not exactly the same as multiple inheritance, but it is very close to the concept of Java

      Pair peer review and

  • Worth learning problems or blog:
    • Classes and packages what is the relationship? public class modified specifically what, why, when it is present and it modifies the file name to the same class? (2330)
    • Enum type seems to be quite tasteless, dim in the end? (2311)
  • Code is worth learning or problem:
    • Math random number which is not random Random, case sensitive.
    • When character input method using nextChar (2303)
  • Based on score, I give this blog scoring: 14 points. Scores are as follows:
    • Proper use Markdown syntax for 1 minute
    • The complete feature templates 1 minute
    • Textbook learning and problem solving process 4 points
    • Code debugging and problem solving process in 2 minutes
    • Feelings, experience does not leave large empty 1 minute
    • Exquisite typography 1 minute
    • Progress bar records the learning time and improved 1 point
    • Comments seriously, I can point out problems and blog code of 1 minute
    • 1 minute in-depth learning the wrong questions
    • Pair learning authentic 1 minute

Comments had students blog and code

  • Pair this week learning
    • 20182326
    • Pair Photo
    • Pair learning content
      • idea to use plug-ins
      • Cloud Links to upload code
  • Last week blog peer assessment case

Other (perception, thinking, etc., optional)

Now gradually increase the difficulty of learning, I think I need to go their own learning, their own perception, their understanding and progress.

Learning progress bar

The number of lines of code (add / accumulate) Blog amount (add / accumulate) Learning time (add / accumulate) Important growth
aims 5000 rows 30 400 hours
the first week 69/69 2/2 30/30
The second three weeks 529/598 3/5 25/55
the fourth week 443/1041 2/7 25/80

Try recording "planned learning time" and "actual learning time" to the end see if you can improve their ability to plan. This study is very important work, is also useful.
Consuming an estimated equation: Y = X + X / N , Y = XX / N, training more often, X, Y will close.

Reference: Why is estimated that software engineering software so hard , software engineering estimation method

Guess you like

Origin www.cnblogs.com/zhaopeining/p/11614558.html