_java object-oriented collation of notes

Source: Internet
Author: User
Tags modifier variable scope

In real life, there are classes that first define classes in the program and then generate objects based on the class. What is the object reality of all entities that are seen to be called objects what is a class class is a set of objects with the same characteristics, similar behavior of the collection class is a mold, the object is generated by the model instance: memory is saved Reality:1. Find the object 2. Extraction characteristics Get Class Program:1. Create class files based on real-world classes 2. Create a variable directly defined in the Class object class: Describe the feature1. Variable scope to extreme (global variable)2. Member Variables3. Attribute class: Equivalent to a template space as long as there is a new occurrence is instantiated object, forcing the space access modifier a) Public common access level is highest protected level B)default(only classes and members can be decorated and not explicitly written out) in the current package accessible cross-package cannot access C)Private(modifier member, which cannot be decorated with class) private access level minimum protection level can only be accessed by other members of this class D) Protected: Protected, can only access members of a class in this class and in subclasses of this class: properties and Methods in a class: [] Represents an array, () represents a method static modifier static: static member, dependent on class, unique, cannot be invoked on an instance object, called with class name+call instance members directly: dependent on the object, how many objects there are, how many copies of the member, and the static object that can be used to invoke the Statics declaration6. Encapsulation encapsulation is one of the three main characteristics of object-oriented (encapsulation inheritance polymorphism) a) Concept: Hide specific implementations provide an external user interface to the user called Package B) Encapsulation benefits: Ensures data accuracy (attributes), improved reusability (method) c) Package Properties step I    .    Property Privatization Ii. Setting the getter (accessor) and setter (evaluator) classes for each property can be seen as encapsulation of properties and methods: The method is a encapsulation, encapsulating code blocks, improving reusability, and reducing coupling (decoupling) the code in the main method is an exposed construction method (no parameter, Full parameter: In a class, the method name is the same as the class name, and the method instantiation process without the return value type is the display invocation class for the construction method: Test class feature Class entity class: Property, encapsulation, construction method composition: Access modifier return value type: Unrestricted type, no return value with void method Name parameter list method body stack: Storage object name and object address heap: Storage object Method Pool: Storage class Method: Definition period: The existence of formal parameters (formal parameter), only the space has no value, equivalent to the local variable use period: The existence of the argument, the parameter assignment, the number of arguments, type, order must be consistent with the formal parameters, Equivalent to the global variable entity class: A vector of data that is used to host data function classes: Contains a large array of action method objects: Objects with multiple food types, food[] food (used to save food[] address)=Newfood[200] (Save object address); Default value type is NULL variable according to the nearest principle This: Refers to this class, access to global variables commonly used in English: increase: Add, insert Delete: Remove, delete: Modify, Update: Find, select Object array declared variables: The number of elements in the current array, the next time to add the subscript of the element Position full Query No parameter This class one method calls another method, calling the method overload directly (overload): In the same class, there are two or more methods with the same name, parameter type or number or order, Improved method name Usability method override (override): In the parent-child class that forms the inheritance relationship, the subclass has the same method name and parameter list as the parent class, and the method of the subclass overrides the parent class's methods called overriding the system determination method, looking at the method name and parameter type and number and order, initialization, reset Delete (All-in-one) of the return value type final Decorated property: This property is a constant, once initialized it can no longer be assigned, once there is only one time to assign the opportunity final decoration method: cannot be overridden by the final decorated class: Cannot be inherited, Must not be an abstract class without inheriting the class diagram: No content, set aside space. + Represents public,-On behalf of private, #代表protect具有继承的子类用, Protected,? Represents the inheritance class name for a parent-child class: attribute: First name, type in Post method: Inheritance: Transitive, single (one subclass only one parent) concept: One class inherits from another class, gets the inherited class all property, and the process of all methods except the constructor method, is called Inheritance polymorphism: in the parent-child class that forms the inheritance relationship, the subclass declares the same name method to the parent class, takes a different approach to the implementation process, and the method overload is also a polymorphic abstract class: Interface (Interface): The interface keyword is implements, cannot have attributes, is completely non-implemented method, solves the single root problem of inheritance (a class can inherit multiple interfaces, an interface is a special class that represents a description of the ability) to extract the class from the characteristics of the class: To solve the redundancy, Inheriting a class that is not shown in type generalization Java, inherits the object class by defaultextends: The inherited keyword Private member can be inherited and cannot be accessed (Privatethe subclass full parameter constructs the parent class to pass in its own property and the parent class full parameter constructs the property assigned to the parent class:1. This. Refer to this class2.Super. Refers to all the parent classes of this class3.Super(name,sex,age); The constructor method that calls the parent class is the child class and the parent class is the-A relationship: is a parent class type variable to be called in the process of object instantiation of the subclass type is the writing of the non-parametric construction or the structure of the argument, depending on the instantiation of the time there is no argument read-only and write-only property only provide a setter or getterabstract modification method if there is no {}, to; Must exist, representing an abstract method, which exists in an abstract class, the subclass must override the parent class method, and the abstract method has no method body fanal and static does not conflict with the parent class to preserve the method because the parent class variable stores the child class object. It is easier to call a subclass method when the instanceof operator determines the type (coercion type conversion) an abstract class can contain an implemented method, a reference variable that can be called by a class that does not appear in the General class Final Declaration, the spatial address is unchanged, and the spatial content can change the object-oriented design step:1. Draw the object out into a class2. To extract a class from a parent-child class that is an inheritance relationship3. Using the Override implementation method4. Create an object to assign a value to a property, call the method reflection: Gets an object of the corresponding class name through a string substring (0,23): Intercepting a string directly subclasses can not directly implement the abstract method, this direct subclass is also an abstract class, there is a subclass, so that its subclass implementation abstract class cannot be instantiated, you can find and replace array objects: Ctrl+The f Construction method can import the array data string method: Length: Long () comparison: equals () comparison case Equalsignorecase () comparison is case-insensitive compareTo () compare ASCLL code case-sensitive , Comparetoignorecase () compare ASCLL code case-insensitive toUpperCase () English to uppercase toLowerCase (); English to lowercase connection:+: There is one side for the character, which represents the connection, the connection once independently opens up a space concat (): Connected, connected one time independently open Space Stringbuffer.append (): Open a space to do the connection with a null character start, after the connection,            Use Stringbuffer.tostring () to String lookup: IndexOf (): Find from left to right, return subscript lastIndexOf (): Right-to-left lookup, return subscript extract: substring (start): Take the head not to take the tail SUBSTRING (start, end): Take head without tail trim (): Remove space on both sides of the string math method: ABS (): Take the absolute value of random (): randomly,0-between 1 sqrt (): Radical Floor (): Rounding Down Ceil (): Rounding up the POW (2,2): N-th square round (): Rounding use method has return value to save StringBuffer class: String operation class, thread safe, low efficiency, save memory Space append (): Trailing Append method, append without generating new memory space T Ostring (): Converts the type to string replace (START,END,STR): Takes out the replacement, the head does not take the tail insert (offset, ""): Insert the string, insert it before offsetNULL: Variable No address cannot invoke method null character: Have address no content, can call method None, Undefind: Type ambiguous array: type explicit, fixed length (waste, subscript out of bounds) set: type explicit, length variable interface: Represents a capability, is a special class Collection : Stores a set of not unique, unordered objects List: Stores a set of not unique, ordered objects Arraylist: Suitable for full search LinkedList: Suitable for inserting and deleting1. First element: Storing data, opening up an element address space2. Other elements: storing data, giving its own address to the previous element to save, opening an element address space set: stores a unique, unordered set of objects TreeSet:HashSet:Map: Store key                    A value object, which is a mapping of key (understood to be auto-sorted) to value, suitable for single-direction mapping of unordered but unique, key pairs of values, and key uniqueness TreeMap:HashMap:containsKey () keyword to determine whether a collection contains a key                        Method: Put (): New, unordered (ordered with add), when the key repeats to modify get (): The collection element is evaluated from the collection by key Remove (): Delete element set () by key: Modify element by key<>: Represents generics, only with reference data types, a type placeholder interface type can only be changed in real time with its subclass instantiation collection elements, the number of allocated spaces is set by a certain proportion of the method: size (): Returns the set length, created at the beginning of 0 get (): Remove the Label Method set (): Assign to the collection element Value, modify to find existing Subscript location Add (): Insert Clear (): Only empty element does not reset space remover (): The element to be deleted is the subscript position of an anonymous object: An object that is only instantiated using a non-variable persisted foreach Loop: Best for iterating through an array or collection element loop; , no subscript for(Type iteration variable: array or collection) {} for(Games g:games) {}: Remove each element from an array or collection and send it to the iteration variable to participate in the loop LinkedList method: AddFirst (): Header add Element addlast (): Trailing add Element GetFirst (): Fetch First element GetLast (): Remove trailing element Removefirst (): Delete header element Removelast (): Delete trailing element iterator: Traversing collection element1. Instantiate iterator<game> it=games.iterator ();2. Judge: Hasnext (), determine whether the next element in the iterator, HashMap with Test.keySet.iterator (); Test.values.iterator ();3. Use: It.next (); The content of the body of an element method is called the logical code, and the logic code must be in the method body variable declaration and assignment can be placed in the method body type generalization when int cannot use integer, Do not use double thread security to avoid the thread concurrency construction method in the super call must be placed in the method body first line vector and ArrayList the similarities and differences to achieve the same principle, the same function, in many cases can be interoperable, class array set difference: vector thread safety, Ar Raylist heavy speed and light security, when the thread non-security length needs to grow, the vector grows by one times, ArrayList%LinkedList linked list Hashtable and hashmap the similarities and differences to achieve the same principle, the same function, in many cases can be mutually different: Hashtable inherit dictionary class, HashMap implement Map interface Hashta BLE thread-safe, hashmap thread-unsafe hashtable does not allow null values, HASHMAP allows null-value construction methods to set full parameters, notice that the collection of encapsulated static declarations is called directly with the class. When you call synchronized to restrict the static method with an object without instantiating it, at some point, only one thread of the same virtual machine is executing the static method, and both Wait,notify and Notifyall can only invoke on one lock object notify (): Wakes one of the threads waiting on this object monitor. Which one can be considered as uncertain. Notifyall (): Wakes up all the threads waiting on this object monitor.    Wait (): Causes the current thread to wait until other threads call the Notify () method of this object or the Notifyall () method. Wait releases the lock that is occupied, notify and Notifyall do not release the lock warning Warning: does not affect compilation and run        Variable declaration assignment, not used when the guide package is not used error errors: Compile-time error Exception exception: Run-time error, all exceptions are exception of the subclass direct processing: The exception code can be estimated to use a try statement block package monitoring Catching exceptions by using catch exception thrown: Throws+exception type, which is placed after the () of this method {} before the method call continues to throw the method call at the exception handlingTry{}: As an exception to the monitoring code block, must appear and only occur onceCatch() {}: Catch and handle exceptions, can occur, can occur multiple times, exceptions are not duplicated, subclass exceptions are in frontfinally{}: Contains any exceptions that must be performed, Can occur only once in a program only integer operation divisor cannot be 0InputMismatchException type mismatch exception arrayindexofboundsexception subscript out of Bounds exception abstract method cannot have method body iterator: Traverse collection element StringBuffer: Line Process safety Efficiency low StringBuilder: thread unsafe efficiency High ReplaceAll: (\\s+, ""): Regular expression, \s represents space

_java object-oriented collation of notes

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.