Arrays and object-oriented

Source: Internet
Author: User
Tags array definition array length

1) Arrays: A container that can store elements of the same type

2) array definition Two ways: data type [] array name;      Data type array name [];(rarely used) For example: int[] A;       An array variable of type int a[] is defined;            Defines an int type variable a array 3) initialization of an array: Dynamic initialization: Given an array length, the array element value is given by the system default data type [] Array name = new data type [length];                                For example: int[] arr = new INT[3]; Left: int[]: Defines an array of type int a                                             RR: Array name to the right: New: Create an Array object (it will exist in heap memory)            Int[]: array of the current int type "3": the length of the current array is 3            Static initialization: The element value of the given array, length by system given format: data type [] Array name = new data type []{element 1, element 2 ...}         For example: int[] arr = new int[]{13,52,81,49} or int [] arr = {13,52,81,49} (right common)!!!                               int[] arr2 = new int[3]{1,2,3}; This is wrong, static and dynamic combinations define an array or Dynamic initialization, specifying the length, or statically initializing the specified array element!4) Java memory allocation: (1) Stack memory: Advanced post---linkedlist: The underlying list structure store: A local variable, either on a method declaration or in a method definition (making Used, freed from memory) (2) heap memory: New comes out, you can store member variables in classes (3) method Area: Class area, static area, String: string (string constant area)! [] (http://i2.51cto.com/images/blog/201804/12/af85a72adb1967375077eb1da280d330.jpg?x-oss-process=image/ watermark,size_16,text_qduxq1rp5y2a5a6i,color_ffffff,t_100,g_se,x_10,y_10,shadow_90,type_zmfuz3pozw5nagvpdgk=) 5) Array of applications (basic applications) (1) to find the most value problem in the array (look for a reference, traverse other elements to compare sequentially) (2) Array traversal problem (define a traversal function) (3) Inverse Problem of arrays (4) Basic lookup of array elements (lookup number The index of the first occurrence of an element in a group in the array (if there are many elements in the array and the number of elements is difficult to count), Java provides the array properties for this case: the Length property x<a Rr.length arr is an array name) 6) An exception that is frequently seen in arrays: (1).                ArrayIndexOutOfBoundsException: The reason why an array angle is out of bounds: accesses an index value that does not exist in the array;  Solution: Observe how many indexed values are in the array; Array Length-1 (2). NullPointerException: null pointer exception (the most common exception in real development) occurs because the object is null, and the developer is going to use the object, there is a problem solution: make a non-null judgment on an object, prevent Null pointer exception for program program 1)Overview of objects: Object-oriented programming language based on process-oriented 2) the characteristics of the thought: (1) conform to our behavioral thinking habits (2) simplifying complex things (3) from executor to conductor 

3) Object-oriented development:
Create objects (provided that there are classes), use objects, and direct objects to do things (with objects.);)
Keyboard entry:
Scanner class
To create an object:
Class Name Object name = new class name ();
Scanner sc = new Scanner (system.in);
4) An overview of classes and objects:
----Real-world Things in code: classes
Properties: member variables
Behavior: Member method (public)
For example:
Mobile phone Things
Property: Brand Price color member variable:
Behavior: Call, send SMS member method:

5)   形式参数的问题:         如果是基本数据类型,形式参的改变对实际参数没有影响;         研究引用类型:形式参数的改变会直接影响实际参数;   

6) Anonymous object:
is when an object is created, an object without a name
Anonymous object in the actual development, use only once, do not use multiple times (may cause a memory overflow phenomenon);
7) Private usage: (privatization, embodied also a package of ideas)
(1) Private modification can only be accessed in this class
(2) can be accessed indirectly through public access

    8) Encapsulation: The standard class of the wording, the member variables are all privatized, the private modified member variable can only be accessed in this class, you can access the member variable by Public access method 9) constructor function: is to initialize the object.      The construction method also belongs to a class of composition: A) member variable B) construction method C) member Method construction method: (1) The method name and the class name are the same;    (2) Construction method, not even void;                        10) The composition of the class has a member: the classification of the member method member method: (1) The form of void as a return value: No specific return value Non-void form: There is a specific return value (2) according to the parameters to divide the null parameter has a parameter) this: represents the current                        Class object, or (a reference to the current class object), to resolve a locally hidden member variable 12) Multiple objects share the same variable, and Java provides a keyword---static: statically (shared)  About the Static keyword: (1) static loads with class loading; (2) static takes precedence over object existence; recall: main public static void Main (..)           {...} (3) Static shared data, can be shared by multiple objects example: Drinking Fountains (staticd: shared); water cups (not shared ...) ; (4) If the data is statically decorated, it can be called directly by the class name; a statically decorated method: Class name. Method name () statically decorated variable: class        Name. variable name;         (5) Static usage: (simple: Static can only access static) A class can have a static variable, or can have a static member method can be non-static, can also be non-static member methods             Static methods can only access static variables, or static methods are non-static methods that can access both static variables and non-static variables ...     13) face question. The difference between a member variable and a local variable (1) in a class where there are different member variables: A class, an out-of-method local variable: A method declaration, or a re-method definition (2) in a different location in memory : member variables: heap memory Local variables: Stack memory (3) different life cycles: member variables: member variables are loaded as the class is loaded, and as the class Missing local variable: As the method is called, it disappears with the method call (4) initializes the value of a different member variable: initialization is initialized by the system default, and for member variables, you can not give              Initializes the value, given by the system, and then displays the initialization; Local variables: Defines a local variable that must be initialized, and cannot be used (initialized before use) if not initialized;

Arrays and object-oriented

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.