Java Knowledge Point---Part Two

Source: Internet
Author: User
Tags wrapper

  • Object-oriented features:
    • Encapsulation: The object's properties and behavior as a whole; Information masking: You can protect the properties and behavior of an object from being known or modified
    • Inheritance: You can inherit some known classes, greatly reducing the amount of code
    • Polymorphism: Overloading of methods, object polymorphism.
    • Span class= "content Mubu-node" categories and objects: Automotive design drawings are classes, specifically produced by a car is the object. The properties in the
    • construction method
      • As long as there is a class there must be a constructor, if a class does not declare the construction method, then at compile time, will automatically generate a non-parametric construction method. If a construction method has been explicitly declared in a class, then no parameter construction method is automatically generated, and at least one construction method should be guaranteed in a class.
  • objects
    • Span class= "Content mubu-node" > To use an object, you must instantiate the object
  • String class
    • A string is an anonymous object of the string class that has opened up heap memory space.
    • The instantiation of the string class suggests using a method of direct assignment, if instantiated with the New keyword, regardless of whether the object already exists, but rather opens up new space, which can result in garbage.
    • Instantiate method using Direct assignment: String str= "HDSODN"; this produces objects in an object pool that are no longer redefined if the object being instantiated is found to already exist. This pooled operation is a shared pattern.
    • The contents of a string cannot be changed once it is declared.
  • this keyword
    • Calling methods in this class
    • Represents a property in a class
    • You can use this to call the constructor of this class, which must be placed in the first row of the constructor method
    • This indicates the current object
  • Static keyword
    • Properties defined by the Static keyword can be shared by all objects and can be defined directly using the class name, which is called a global property (static property)
    • Class is defined by the static keyword, the method can be called directly by the class
    • A method of a non-static declaration can invoke a property or method of a static declaration, but the method of static declaration cannot invoke properties and methods declared by a non-static type. The reason is that static-defined methods can be called by the class name when the object is not instantiated, and the method not defined by the static must be instantiated before it can be called.
  • Common memory areas in Java
    • Stack memory space: Saves all object names (addresses where the referenced heap memory space is saved)
    • Heap memory space: Saves the specific property content of each object
    • Global Data area: Saving properties of static type
    • Global Code Area: Save All method definitions
  • Final keyword
    • A class that uses final declaration cannot have child classes
    • Methods that use Final declaration cannot be overridden by subclasses
    • A variable that uses final declaration is both a constant, which cannot be modified, and all the letters are capitalized
  • Abstract class
    • An abstract class is like a "template" whose purpose is to modify and create new classes based on his format, but abstract classes cannot directly create objects, but can only derive new classes from abstract classes and then create objects from new derived classes.
    • A subclass can inherit only one abstract class
    • A class that contains an abstract method must be an abstract class
    • Both abstract and abstract methods use the abstract keyword declaration
    • Abstract methods only need to declare that no implementation is required
    • Abstract classes must be inherited by subclasses, and subclasses (if not abstract classes) must overwrite all abstract methods in the abstract class.
  • Interface (interface)
    • Interfaces are made up of global variables and public abstract methods. The abstract method in the interface must be defined as public access, even if omitted, and is also public access, not the default permission
    • A subclass can implement multiple interfaces (implements) at the same time, and the subclass must overwrite the abstract method of all interfaces at the same time
  • The polymorphism of the object (not quite understood)
    • The parent object of the parent class object = Child class instance
    • Sub-Class Subclass Object = (subclass) Parent class instance
    • You must first move up before a downward transition occurs, or an object conversion exception will occur.
  • instanceof Keywords:
    • Determine which class an object is an instance of
    • Object Instanceof Class
  • Object class
    • All classes have a common parent class object. All objects can be converted to object, and all reference data types can be received using object.
    • Common methods of the object class:
      • ToString (): Get Object Content
      • Equals (): Object for comparison
      • Hashcode (): Get hash code
    • Packing class
      • Wrap basic data into classes so that the base data type can be an object
      • Object wrapper class (direct subclass of Object): Boolean (Boolean), Character (char)
      • Numeric wrapper class (direct subclass of Number): Interger (int), short (short), long (long), float (float), double (double), Byte (byte)
      • Packing and unpacking (automatic packing and unpacking operations are provided after JDK1.5)
        • Boxing: Converts the base data type into a wrapper class: int X=30;integer i =new Integer (x);
        • Unpacking: Changes the wrapper class to the basic data type: int Temp=i.intvalue ();
      • Converting a base data type to a string
        • There is a valueof () method in the string type that can convert the base data type to a string type
        • You can also use "+" this way, but this way will produce garbage, it is not recommended to use
    • Access control permissions
      • Private access, which can be used in the declaration of a property's definition and method, and once the Private keyword declaration is used, it can only be accessed in this class
      • Default: Defaults access, which can be accessed by other classes in this package, but not by classes of other packages
      • Protected: Protected Access, accessible only to subclasses of this package or different packages
      • Public: Common access: can be accessed in all classes, regardless of whether they are in the same package.

Java Knowledge Point---Part Two

Related Article

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.