Java EE Basics (vi)

Source: Internet
Author: User

1. Object oriented (Overview of Object oriented thinking)
    • A: Overview of process-oriented thinking
      • The first step
      • Step Two
    • B: An overview of object-oriented thinking
      • Find objects (first step, second step)
    • C: Example
      • Buy Pancake Fruit
      • Washing clothes
    • D: Object-oriented thinking features
      • A: It's a thought that's more in line with our thinking habits.
      • B: Complex things can be simplified
      • C: Turning us from the executor to the conductor
        • The role has been transformed
    • E: Object-oriented development
      • is to constantly create objects, use objects, and command objects to do things.
    • F: Object-oriented design
      • is to manage and maintain the relationship between objects.
    • G: Object-oriented features
      • Package (encapsulation)
      • Inheritance (inheritance)
      • Polymorphic (polymorphism)
2. Object-Oriented (class and Object overview)
    • A: What are we learning to program for?
      • In order to describe our daily life in the language of learning
    • B: How do we describe real world things
      • A property is a descriptive message of the thing (a noun on a thing).
      • Behavior is what the thing can do (verbs in things)
    • The most basic unit in C:java is the class, and the same is true in Java, which describes things in class.
      • A member variable is a property of a thing
      • A member method is the act of something.
    • D: Defining a class is actually a member of the definition class (member variables and member methods)
      • A: The member variable is the same as the previously defined variable, except that the position has changed. In the class, outside of the method.
      • B: The member method is the same as the previously defined method, except that static is removed and the function of static is explained in detail later.
    • E: Concepts of classes and objects
      • A: Class: is a set of related properties and behaviors
      • B: Object: Is the concrete embodiment of this kind of thing
      • C: for example:
        • Class students
        • An object specific to a student is an object
3. Object-oriented (definition of student Class)
    • A: Student Affairs
    • B: Student Class
    • C: Case Demo
      • Properties: Name, age, gender
      • Behavior: study, sleep
4, Object-oriented (definition of mobile phone class)
    • Imitate the student class and let the students do it themselves
      • Property: Brand Price
      • Behavior: Call, Send Message (sendMessage) play games (PlayGame)
5. Object-oriented (use of student Class)
    • A: File name problem
      • Write two classes in a Java file: A basic class, a test class.
      • Recommendation: The file name matches the test class name.
    • B: How do I use objects?
      • Create an object and use
      • Format: Class Name Object name = new class name ();
    • D: How do I use member variables?
      • Object name. Variable Name
    • E: How to use the Member method?
      • Object name. Method Name (...)
6. Object-oriented (use of mobile phone class)
    • A: Students complete their own
      • Imitate the student class and let the students do it themselves
7. Object-oriented (memory graph of an object)
    • A: Drawing Demo
      • An object
8. Object-oriented (memory graph of two objects)
    • A: Drawing Demo
      • Two different objects
9. Object-oriented (three memory graphs referencing two objects)
    • A: Drawing Demo
      • Three references, two object references to the same address
10. Object-oriented (the difference between a member variable and a local variable)
    • A: The position in the class is different
      • Member variables: Outside the method in the class
      • Local variables: In a method definition or on a method declaration
    • B: The location in memory is different
      • Member variables: In heap memory (member variables belong to object, object into heap memory)
      • Local variables: In-stack memory (local variables belong to method, method into stack memory)
    • C: Different life cycle
      • Member variables: As objects are created, they disappear as the object disappears
      • Local variables: As the method is called, it disappears as the method's call is complete
    • D: Different initialization values

      • Member variable: has default initialization value
      • Local variables: There is no default initialization value, which must be defined and assigned before it can be used.
    • Precautions:

      • The local variable name can be the same as the member variable name, when used in the method, using the nearest principle.
      • Basic data type variables include which: Byte,short,int,long,float,double,boolean,char
      • Reference data type variables include: arrays, classes, interfaces, enumerations
11, Object-oriented (the formal parameter of the method is the name of the class, how to call)
    • A: The parameter of the method is the class name public void print (Student s) {}//print (New Student ());
      • If you see a method in which the formal parameter is a class type (reference type), the object of that class is actually required.
12. Object-oriented (overview and application of anonymous objects)
    • A: What is an anonymous object
      • An object without a name
    • B: Anonymous Object Application Scenario
      • A: Call the method, just call it once.
        • So what is the benefit of this anonymous invocation?
          • Save Code
        • Note: It is not appropriate to call multiple times. The anonymous object call is complete garbage. Can be reclaimed by the garbage collector.
      • B: Anonymous objects can be passed as actual parameters
    • C: Case Demo
      • Anonymous Object Application Scenario
13. Object-oriented (overview of encapsulation)
    • A: Encapsulation Overview

      • Refers to the properties and implementation details of hidden objects, and provides public access only to the outside.
    • B: Package Benefits

      • Hide implementation details and provide public access
      • Improved reusability of the code
      • Improve security.
    • C: Encapsulation principle
      • Hide content that you don't need to provide externally.
      • Hides the property and provides a public way to access it.
14. Object-oriented (overview and features of private keywords)
    • A: The question of the age of human assignment
    • b:private keyword Features
      • A: is a permission modifier
      • B: You can modify member variables and member methods
      • C: Members modified by them can only be accessed in this class
    • C: Case Demo
      • Applications for encapsulation and private:
      • A: Modify the member variable with private
      • B: Provide the corresponding getxxx () and setxxx () methods
      • Private is only a form of encapsulation, not that encapsulation is private
15. Object-oriented (overview and application of the This keyword)
    • A:This keyword Features
      • Represents a reference to the current object
    • B: Case Demo
      • The application scenario for this
      • Used to differentiate between member variables and local variable names
16, Object-oriented (mobile phone class code and test)
  • A: Student Practice

    • Please write the phone class as a standard class and then create the object test function.

      Class Demo2_phone {public static void main (string[] args) {phone P1 = new Phone ();        P1.setbrand ("Samsung");        P1.setprice (5288);        System.out.println (P1.getbrand () + "..." + p1.getprice ());        P1.call ();        P1.sendmessage ();    P1.playgame (); }}/* Phone class properties: Brand brands, price prices behavior: Call calls, send SMS SendMessage, play games, Playgame*/class phone {//jav                   A bean private String brand;                      brand private int price;    Price public void Setbrand (String brand) {//Set branding This.brand = brand;                  } public String Getbrand () {//Get brand return this.brand;    This. can be omitted, you do not add the system will default to you add} public void Setprice (int prices) {//Set price This.price = value;    } public int GetPrice () {//Get price return value;    public void Call () {//Phone System.out.println ("Phone call"); } public void SendMessage () {//Texting SYSTEM.OUT.PRINTLN ("texting");    } public void PlayGame () {//Play game System.out.println ("Play the Game"); }}

Java EE Basics (vi)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.