Java EE Basics (vii)

Source: Internet
Author: User

1. Object-Oriented (construction method constructor Overview and format)
    • A: Overview and role of construction methods
      • Initialize the object's data (properties)
    • B: Construction Method Format features
      • A: The method name is the same as the class name (the size should also match the class name)
      • B: No return value type, not even void
      • C: No specific return value returned;
2. Object-oriented (overloading of construction methods and precautions)
    • A: Case Demo
      • Overloading of construction methods
      • Overloading: Method names are the same, regardless of the return value type (construction method has no return value), see only the parameter list
    • B: Construction Method considerations
      • A: If we do not give a construction method, the system will automatically provide a non-parametric construction method.
      • B: If we give a construction method, the system will no longer provide a default parameterless construction method.
        • Note: This time, if we still want to use the parameterless construction method, we have to give it ourselves. It is recommended that you always give the method of non-parametric construction
3. Object-oriented (the difference between two ways to assign a value to a member variable)
    • A:setxxx () method
      • modifying property values
    • B: Construction method
      • To initialize an attribute in an object
4. Object-oriented (code and test of student Class)
    • A: Case Demo
      • Student class:
        • Member variables:
          • Name,age
        • Construction Method:
          • No parameters, with two parameters
        • Member Methods:
          • GetXxx ()/setxxx ()
          • Show (): Outputs all member variable values for this class
    • B: Assign a value to the member variable:

      • A:setxxx () method
      • B: Construction method
    • C: How to Output member variable values:

      • A: Get and then stitch through GetXXX () respectively
      • B: done by calling the show () method
07.05_ Object-oriented (code and test of mobile phone Class) (master)
    • A: Case Demo
      • Imitate the student class, complete the phone class code
6. Object-oriented (steps to create an object)
    • A: Drawing Demo
      • Drawing describes what has been done during the creation of an object?
      • Student s = new Student ();
      • 1,student.class Loading into memory
      • 2, declaring a student type reference s
      • 3, the object is created in heap memory,
      • 4, default initialization value for property in Object
      • 5, the property is displayed for initialization
      • 6, constructs the method into the stack, assigns the value to the attribute in the object, constructs the method the bomb stack
      • 7, assign the object's address value to s
7. Object-oriented (rectangular case practice)
    • A: Case Demo
      • Demand:
        • Defines a rectangle class that defines the method for calculating the circumference and area,
        • Then define a test class to test.
8, Object-oriented (Employee class case practice)
    • A: Case Demo
      • Requirements: Define an employee class employee
      • Analyze several members yourself and then give the member variables
        • Name Name, work number ID, payroll salary
      • Construction method,
        • Null parameter and the argument
      • GetXxx () setxxx () method,
      • And a way to display all of the member information. and tested.
        • Work
9. Object-oriented (static keyword and memory map)
    • A: Case Demo

      • Introduce the static keyword through a case.
      • Human: person. Everyone has a nationality, China.
    • B: Drawing Demo

      • Memory diagram with Static
10. Object-oriented (characteristics of the static keyword)
    • Features of the A:static keyword
      • A: Loaded with the load of the class
      • B: Precedence over object existence
      • C: Shared by all objects of the class
        • Example: Students in our class should share the same class number.
        • In fact, this feature is also telling us when to use static?
          • If a member variable is shared by all objects, it should be defined as static.
        • Example:
          • Water dispenser (with static modification)
          • Water Cup (cannot be modified by static)
          • Common use static, non-static characteristics
      • D: Can be called by the class name
        • In fact, it can also be called by the object name itself.
        • It is recommended to call with the class name.
        • Content that is statically modified is generally referred to as: Class-related, Class-member
    • B: Case Demo
      • Features of the Static keyword
11. Object-oriented (static considerations)
    • A:static precautions
      • A: There is no this keyword in the static method
        • How to understand it?
          • Static is loaded as the class loads, and this is present as the object is created.
          • Static than object exists first.
      • B: Static methods can only access static member variables and static member methods
        • static method:
          • Member variables: Only static variables can be accessed
          • Member method: Only static member methods can be accessed
        • Non-static methods:
          • Member variable: can be static or non-static
          • Member method: However, it is a static member method or a non-static member method.
        • Easy to remember:
          • Static can only be accessed statically.
    • B: Case Demo
      • Considerations for Static
12. Object-oriented (the difference between static variables and member variables)
    • A static variable is also called a class variable member variable also called an object variable
    • A: Belong to different
      • Static variables belong to classes, so they are also referred to as class variables
      • Member variables belong to an object, so also known as instance variables (object variables)
    • B: Different locations in memory
      • Static variables stored in the static area of the method area
      • member variables stored in heap memory
    • C: Memory occurrence time is different
      • Static variables are loaded as the class is loaded and disappear as the class disappears
      • Member variables exist as the object is created and disappear as the object disappears
    • D: Call Different
      • A static variable can be called by a class name, or it can be called by an object
      • Member variables can only be called by object name
13. Object-oriented (the format of the main method is explained in detail)
    • A: Format
      • public static void Main (string[] args) {}
    • B: Explanation of the format
      • Public is called by the JVM, and access permissions are large enough.
      • Static is called by the JVM without creating objects, accessing the class name directly
      • Void is called by the JVM and does not need to return a value to the JVM
      • Main a generic name, although not a keyword, but is recognized by the JVM
      • String[] args was previously used to receive keyboard input
    • C: Demo Case
      • Receiving keyboards via args such as data
14. Object-oriented (use static in tool Class)
    • A: Make a tool class
      • Arraytool
      • 1, gets the maximum value
      • 2, the traversal of the array
      • 3, the inverse of the array
15, object-oriented (the production process of the manual)
    • A: Add A document Comment to the tool class
    • B: Generate instructions by Javadoc command
      • @author (extract author content)
      • @version (extract version content)
      • javadoc-d the specified file directory-author-version Arraytool.java
      • @param parameter name//variable name of formal parameter @return function runs out of returned data
16. Object-oriented (how to use the Help document provided by the JDK)
    • A: Locate the document, open the document
    • B: Click on the display, find the index, the input box appears
    • C: You should know who you're looking for. Example: Scanner
    • D: Look at the structure of this class (requires no guide package)
      • Member Variable fields
      • Constructing methods of construction method
      • Member Method methods
17. Object-Oriented (learn the random number function of math class)
    • Open the help documentation provided by the JDK to learn
    • A:math class overview
      • class contains methods for performing basic mathematical operations
    • B:math class Characteristics
      • Because the math class is under the Java.lang package, there is no need for a guide package.
      • Because its members are all static, private construction methods
    • C: Method of obtaining a random number
      • public static Double Random (): Returns a double with a positive number that is greater than or equal to 0.0 and less than 1.0.
    • D: I'm going to get a random number between 1-100, swollen?
      • int number = (int) (Math.random () *100) +1;
18_ Object-oriented (guess digital mini-game case)
    • A: Case Demo
      • Need: Guess number games (data between 1-100)

Java EE Basics (vii)

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.