201621123069 Java Programming 2nd week of study summary

Source: Internet
Author: User

1. Summary of this week's study
This week learned how to master various data types such as Byte,short,int,long,double,float,char,boolean, the application of enumeration classes and string classes, and the use of various operations to match expressions. and auto-boxing refers to the type of converting some basic types into integers, and automatically unpacking is converting an integer type to a basic type.
2. Written work
1.string-using eclipse to correlate JDK source code
1.1 View the source code () of a string object and analyze what string is used to store strings?
String uses a pointer called _ptr, which points to the first address of the stored string.
1.2 Analyze the function of its constructor public String (char value[])?
public string (char value[]) is the function of copying the input string into value.
1.3 Read the Code of the public string replace (char OldChar, char Newchar) method, and answer how the immutability of the string is reflected in the function? Focus
Because using the public string replace (char OldChar, char newchar), this function generates a new string with the same length as the original string, returning the original string, thus embodying the immutability of the string.
1.4 Briefly describe the relationship between string and character array, use character array to handle string, why do you need string?
The last element of a character array must be NULL, and string provides more ways to manipulate the string.
2.StringBuilder
2.1 In conjunction with PTA-2 (StringBuilder), why should I use StringBuilder instead of string when I frequently modify strings?
The StringBuilder is executed more quickly.
2.2 Read the JDK document, query StringBuilder's append (char[] str) method function? What is the internal use of StringBuilder to store characters? How do I implement an operation to add characters when I call StringBuilder's append (char[] str) method?
The function is to append the parameters of char to the sequence. StringBuilder internally uses the char[] array to hold characters.
3. String and String pool
3.1 Attempt to use the concept of a string pool to interpret the output of the following program segment and answer this code to create several string objects: string str1 = "Hi", str2= "HI"; String str3 = new String (str1) System.out.println (STR1==STR2);
The output is true, this code creates two string objects, str1 and str2 point to the same object, and STR3 is a new one.
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?
The main reason is that the address is different, with = = error, if the reference type is generally used equals (), ptastringbulider the problem is useful.
4. Packing class
4.1 Integer i = 100;//100 is the base type, I is a reference type, why can I be assigned to 100? Integer x = 100; int y = x+1;x++; What is included in this string of commands?
This is the automatic boxing operation, which converts the generic type to a reference type.
4.2 Why does Java have a basic data type and need its wrapper class? What are the benefits of packing class?
Java is a programming language for a face object, and the basic data type is not object-oriented, so you need to wrap the class. The advantage is that the conversion between types is convenient.
5. Experimental summary
5.1 Pair Programming Practice: the use of pairing programming to complete this week's programming problem, that is, two people at the same time to work together to complete the experimental topic (can be more than 1 questions, but preferably 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).
Teacher because I am a network alone and three of the students in the four classes to live together, so seldom to the classmate dormitory discussion, but roommates in Java and I also have communication, do PTA will share ideas. It might really be more than 2, because I learned more about the functions that I didn't know before during the discussion.
5.2 PTA-1 Comprehensive Quiz
FIB I defined pre,now,next to perform calculations, and at first pre=0,now=next=0;sort I accepted it with nextline (), processed each character, and saved it to the list, Call the Sort method of collection to sort the list, define an int array and then assign the number in the list, and finally output with ToString (). Seach directly calls the BinarySearch function in list to pass in the value to be looked up, and when found, the subscript is output. Get to the input ID card with substring for stitching.
5.3 PTA-3 ID card sort. and answer: Using the Sort2 method to sort the date of birth can be sorted in ascending order, if it is necessary to sort it in descending order, or according to the month of birth in the order, how to solve it?
Defines a class that defines a class method in a class that assigns two variables to the class when the string is passed in, an ID of YMD (month and day), the ID input is completed, the YMD in the array of classes, and a custom comparison function CMP to compare the YMD strings in the two ID objects , when the accepted string is Sort1, the YMD is output with the for each, and the same method is used to output the ID when Sort2 is accepted.
5.4 PTA-4 Dynamic Array
Only two loops and arrays.deeptostring () are required to print the multiplication table.
5.5 (Focus: Quiz topic) PTA-8 ArrayList get started. and answer: Why do I have an array to use ArrayList?

3. Code Cloud and PTA
3.1. Code Cloud codes 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

201621123069 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.