201621123021 Java Programming 2nd week of study summary

Source: Internet
Author: User

201621123021 Java Programming The second week of study summary 1. Summary of this week's study
    • This week we learned about the basic data types of Java and their differences from the C language data types.
    • Know how Java is created and applied to arrays.
    • Learn about the wrapper classes in Java, such as auto-boxing and automatic unpacking.
    • Learn about Java as an object-oriented language with reference objects as constant pools.
    • Know some of the uses of the string class.
2. Written assignment 1. string-using eclipse-associated JDK source code 1.1 to view the source () of a string object, parsing what string uses to store strings?

public final class String implements java.io.Serializable, Comparable<String>, CharSequence { private final char value[]; private int hash; private static final long serialVersionUID = -6849794470754667710L; private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0]; public String() { this.value = "".value; }This paragraph of the Java source code shows that the string class uses a character array to store strings.

1.2 Analyzing its constructors public String(char value[])The role?
    • Char value[] is the declaration of an array, and the function of this constructor is to convert the char array into a string class.
1.3 Read public String replace(char oldChar, char newChar)The code of the method that answers how the immutability of a string is reflected in the function? Focus
    • The character of Oldchar and Newchar itself in the function has not changed, but the new string reference has changed.
1.4 Briefly describe the relationship between string and character array, use character array to handle string, why do you need string?
    • The string class is an extension of the character array, and the Java source converts the character array into a string to implement the new data type string.
    • String is the encapsulation of character arrays, which makes it easier and easier to use Java in strings, and it can use the encapsulated function directly.
2.stringbuilder2.1 combined with PTA-2 (StringBuilder), explain why you should use StringBuilder instead of string when you frequently modify strings?
    • String if you need to modify the string, you will create a new string in the string constant pool to reach the reference, and StringBuilder can modify a string object so that there is no need to waste extra memory space to hold the new string when modifying the string frequently.
    • In PTA-2, we want to implement string concatenation, we need to modify the string frequently, and we need to use StringBuilder instead of string.
2.2 Read the JDK documentation and query the StringBuilder append(char[] str)What is the method function? What is the internal use of StringBuilder to store characters? Call StringBuilder的append(char[] str)method, how do you implement the add character operation?
    • The function is to insert the specified content after the string array.
    • StringBuilder a string array to hold the character.
    • The string appends the specified content to add characters.
3. String and string pool 3.1 attempts to use the concept of a string pool to interpret the output of the following program segment and to answer this code to create several string objects:

String str1 ="hi", str2="hi"; String str3 = new String(str1) System.out.println(str1==str2);

    • The final output is "true" because the str1 and str2 references are the same object "HI" in the string constant pool.
    • This code creates 2 string objects, respectively, "HI", and Str3 declares that creating a new string object is referenced by STR3.
3.2 Focus: For basic types we can use = = to compare two values for equality, for reference types (such as String, Integer, array, etc.) why can't I use = = comparison? How do you compare their values for equality?
    • Because the base type uses "= =" to compare whether their objects are equal, and if the reference type is compared with "= =", the referenced address is equal, the object of the comparison is different.
    • Compare the values of referenced objects in reference types, and you can use the equal function to compare them.
3.Wrapper (Packaging Class) 4.1 Integer i = 100;100 is the base type, I is the reference type, why can I assign 100 to I? Integer x = 100; int y = x+1;x++;What is included in this sequence of commands?
    • Assigning a value of 100 to I allows automatic boxing of reference types to make the code structure simpler.
    • Includes automatic boxing and automatic unpacking of data types.
4.2 Why does Java have a basic data type and need its wrapper class? What are the benefits of packing class?
    • The wrapper type can be used to make the data easier to use when the basic data type is implemented with more cumbersome operations.
    • The benefit of the wrapper type is that you can implement a conversion of the base type with it, or that data that is difficult to implement in the basic data type is quickly implemented in the wrapper class.
5. Experimental summary 5.1 pair programming Practice: the use of pairing programming to complete the programming problem this week, that is, two people at the same time to work together to complete the experimental topic (1 questions can also be many questions, but it is best to two people have not done the topic). Recommended implementation steps: 1. Two people sit in front of the same computer screen to question, discuss, decide who should write first. 2.1 People make 5 minutes (to discuss how many minutes themselves), while another person observes each other's programming or check related information. 3. After 5 minutes, after a brief discussion, for another person to continue the compilation (please be sure to change, if the other person can not accept should be the first person to explain the approximate idea to facilitate their acceptance). and complete the following assignments: A. Describe the pair-mate name, pairing process, and provide a pair of photos that the non-pendulum two people are discussing, refining, and programming. B. Can pair programming really bring 1+1>2 effect? Through this pair programming, please talk about your feelings and experience (such as whether it is conducive to the improvement of their own programming level, is conducive to the development of programming ideas). 5.2 PTA-1 Comprehensive Quiz
    • This experiment allowed me to use StringBuilder to a certain extent in the string class, Stringbuiider was able to change the reference object in a string reference type, avoiding the awkward situation of constantly creating new strings.
5.3 PTA-3 ID card sort. and answer: Use sort2method to sort the date of birth, if it is necessary to sort it in descending order, or according to the month of birth in which to sort, how to solve it?
    • In this experiment, I use the function substring in Java to compare the number of numbers, and then use the function CompareTo to compare, using the bubble sort method to sort.
    • To sort the values in descending order, you can change the value of the bubble sort by comparing the values of the number of births to the month of birth. The value range of the ID card is changed by using the function substring.
5.4 PTA-4 Dynamic Array
    • In order to implement dynamic arrays, we need to create a two-dimensional array, use NULL for unused space in the array, to indicate that this location is empty, and to implement output for non-empty locations.
5.5 (Focus: Quiz topic) PTA-8 ArrayList get started. and answer: Why do I have an array to use ArrayList?
    • This experiment gave me a preliminary understanding of the use of ArrayList, to be able to use a dynamic array on a certain Chengdu.
    • The use of ArrayList in the array can realize the free allocation of memory space and realize the reasonable allocation of space.
3. Code cloud and PTA3.1. Codes Cloud Code submission record

3.2 Question Set "Java Basic Syntax" PTA Submission List

3.3 Use the teacher-issued jar program to count the weekly code volume
Number of rows number of new rows Number of files number of new files
324 324 46 46

201621123021 Java Programming 2nd week of study summary

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.