The Java self-study road-DAY06

Source: Internet
Author: User
Tags rounds

JAVA06 Reference data types
    1. Array
    2. Class
    3. Interface
    4. is also a reference type
    5. Used to define properties and functions to describe things in the real world such as the definition of a student class
    6. Format
Custom data types

Public CALSS class Name {

Properties and Methods

Property Definition

Modifier data type variable name = value

Method definition

Modifier returns the type method name (parameter list) {

}

}

    1. Create a format for a reference type variable

Data type variable name =new data type ();

Steps to implement a reference type

A) importing packages in the same folder does not require a guide package

b) Create a variable of reference type

c) variables. Variables in the type

d) variable. Property =

e) variable. function

Memory diagram

L A Reference type variable

    1. Method Stack Heap Method area
    2. The test class first enters the method area to execute the Main method
    3. Custom class enters method area to execute Create property
    4. The main method enters the method stack to create a custom class object
    5. JVM creates a space in heap memory to store custom objects
    6. The custom property follows the container into the heap memory and is given the default value of NULL or 0.0 ...
    7. The JVM passes the memory address to the reference variable
    8. The Mian method then substitutes the default value for the variable assignment based on the memory address
    9. Then the main method ends and the stack is returned.
    10. The whole process is over.

L Two Reference type variables

    1. Method Stack Heap Method area
    2. The test class first enters the method area to execute the Main method
    3. Custom class enters method area to execute Create property
    4. The main method enters the method stack to create a custom class object
    5. JVM creates a memory space in heap memory to store custom objects
    6. The custom property follows the container into the heap memory and is given the default value of NULL or 0.0 ...
    7. The JVM passes the memory address to the reference variable
    8. The JVM opens up a memory space in heap memory to store custom objects
    9. The custom property follows the container into the heap memory and is given the default value of NULL or 0.0 ...
    10. The JVM passes the memory address to the reference variable
    11. The Mian method then substitutes the default value for variable assignment based on two different memory addresses
    12. Then the main method ends and the stack is returned.
    13. The whole process is over.

Practice

Car brand Color outputvolume (displacement)

Student name num Sex

ArrayList Collection Class
    1. A container
    2. Reference data type
    3. Use steps

A) Import Package

b) Create a reference type variable

Data type < collection stored data type > variable name =new data type < collection stored data type > ();

arraylist< data Types > Array=new arraylist< data Types >

Variable name. method

Data types for collection storage
    1. Do not store base types
    2. Only reference types are stored
    3. You can store reference types corresponding to the base type

Collection method
    1. . Add (data type); Adding a collection element
    2. . get (int index); Remove elements from the collection based on index (starting at 0)
    3. . Size (); Returns the length of the collection
Traverse ArrayList

The For loop traverses the output. Get ();

Supplemental methods
    1. Set (int index, modified element); modifying elements
    2. Add (int index, added element); adding elements
    3. Remove (int index); Delete Element
    4. Clear (); empty all elements of the collection
    5. Any specific object is represented by a class package.
    6. collection to store commodity objects
    7. Iterate through a collection to display commodity attributes
    8. Set method of the collection to implement the modification information
    9. The memory address can be repeated to the same variable name, but not at the same time, two new object heap memory opens up two parts of memory space for two custom class reference type variables, resulting in two different memory addresses added to the collection, so the information will be different
Practice Random Raffle Exercise Inventory Manager Collection Edition odd sum exercise

Calculate 1-100 between all the odd and

    1. First, define the variables according to the problem data.

A) Define a variable to hold the sum

Int sum=0;

    1. Use loops to change variables from 0 to 100

for (i=0;i<=100;i++) {

}

    1. Determine if the variable is odd

for (i=0;i<=100;i++) {

if (i%2==1) {

Sum+=i;

}

}

    1. If it's odd, sum it up with the predefined variables.

Sop (sum);

    1. Extended

for (i=1;i<=100;i+=2) {

Sum+=i;

}

Number of daffodils calculated

ask for three-digit 100-999 number of daffodils in the

    1. Single-digit cubic + 10-digit cubic + hundred-digit cubic = itself
    2. Steps

A) define a variable to store integers on three digits

b) using loops, variables from 100 lane 999

c) The use of modulo division to find out the loop of the three-digit number of each digit

D) A cubic summation of three digits

E) Judging and whether it is equal to this three-digit number

f) If the number of daffodils is equal

ASCII encoding
    1. The computer is running binary
    2. For the computer to directly recognize the human word
    3. The Americans put forward: the human word and an integer one by one correspond
    4. Man-made letter a corresponds to 97 uppercase a corresponds to decimal 65 machine turns 97 to 2 binary to be able to identify
    5. AA ZZ 0-9 [email protected]#$%^* each to form a table
    6. This table is called the ASCII table.

    1. China also wants computer to recognize Chinese characters
    2. Decimal number corresponds to a Chinese character
    3. Then there is the first Chinese encoding table GB2312
    4. It's too small to upgrade to GBK.
    5. Each country has its own coding tables.
    6. So ISO unifies the encoding table Unicode Universal Code table stores all the languages in the world
    7. All coded tables are compatible with ASCII
    8. Character Java data type Char
    9. Integer Java data type int
    10. The char type and int type are added, int4 bytes Char 2 bytes char automatically promoted to int, find an integer in the encoded table, and add the int
Storage of type Char

int I = ' a ' +1

The result is 98 a for the

Char h= (char) 90;

    1. 4. character and integer operations will query the ASCII encoding table
    2. 5. char storage kanji is queried Unicode table a kanji two bytes
    3. 6. char type value range 0-65535

a) short-32768 32767 Char 0-65535

b) short type binary highest bit sign bit 1 negative 0 positive followed by value bit

c) char type binary All is numeric unsigned bits 0 and 1 both represent positive numbers

D

e) char cannot store negative numbers , unsigned data types

Practice output All English letters include case 99 multiplication table special format traversing array array in reverse order principle
    1. The elements in the array are exchanged at position
    2. Not equal to introspection traversal
    3. Array Farthest position Exchange
    4. Index of the pointer thought array
    5. Pointers can point to any index at any time
    6. Requires two pointers one pointing to the small one pointing to the large
    7. Then small + + large-Move the transform point to change the position
    8. Array transposition with third-party variables for temporary storage

Sort

L Select Sort

Each element in the array is compared

Nested loops

    1. Looking for a regular comparison of the number of rounds per round of comparison in the reduction for (int i=0;i<arr.length-1;i++) {
    2. Therefore, using a nested for loop outer loop to determine the number of rounds, that is, the array length minus one memory loop is used to determine the number of from Samsara per round, plus 1 to the array length of time for (int j=i+1;j<arr.length;j++) because it needs to compare J and I, starting with 0 elements. 0 and 0 do not have to compare and each decrement so need from i+1

L Bubble Sort

The adjacent elements in the array are compared

0 1 1 2 2 3

0 1 1 2

0 1

A) Find patterns

b) Total array length minus one round for (int i=0;i<name.length-1;i++) 0 1 2 Just a tricycle

c) The array length per round is reduced by several times for (int j=0;j<arr.length-i-1;j++) (1. 3=4-0-1 2. 2=4-1-1 3.1=4-2-1) J=0: Because of the need to compare J and j+1 j<arr.length-i-1 from 0 elements: The number of comparisons that need to be decremented each time and the first time the element starts from the 0 element is equal to no reduction.

d) Compare J and J+1 comparisons

Binary find (binary lookup) principle
    1. Binary formula

(max+min)/2

    1. Pointer ideas point to index

Max pointer

Min pointer

Mid pointer

    1. Cyclic binary
    2. Small pointer index is less than the large pointer index for the loop condition
    3. Comparison element is greater than intermediate index min=mid+1
    4. Comparison element is less than intermediate index max=mid-1
    5. Compare element equals Intermediate index return mid
    6. First you need to understand the pointer thought requires three pointers a pointer to the smallest index a pointer to the largest index a pointer to the middle of the index
    7. And then you compare the elements that you're looking for with the middle index.
    8. If equal to return this index mid description found this number
    9. If the element is larger than the middle index points to, the smallest index points to the right of the number pointed to by the intermediate index, that is, the minimum index equals the intermediate index plus 1, and the maximum index is unchanged.
    10. If the element is less than the middle index point, the maximum index points to the left of the number that the intermediate index points to, that is, the maximum index is equal to the intermediate index minus 1, and the minimum index is unchanged.
    11. A new comparative arrangement formed after judgment
    12. And then in the comparison of 2,3 and 4
    13. Until the minimum index is the same as the maximum index, which is the same as pointing to a number, which leaves only one possible min Max and Mid are a number if this is not equal to this number, it means you can't find it.
    14. But the computer will continue to compare
    15. Continue the comparison of 2,3 and 4
    16. If this number is greater than this number, it will be +1 max unchanged.
    17. If this number is greater than this number, Max will be-1 min unchanged.
    18. At this point in either case, the Min>max will not be compared, indicating that the number can not be found
Summarize

The Java self-study road-DAY06

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.