201521123045 Java Programming 2nd week of study summary

Source: Internet
Author: User

---restore content starts---

1. Summary of this week's study

The last experimental topic was explained, and some problems of the subject were solved. Learn the use of Java arrays, and how to use code cloud upload codes have a clearer understanding.

2. Written work

Q1. Use eclipse to correlate JDK source code and view the source () of a string object? What does the parsing string use to store strings? How do you analyze the implementation of the constructor function public String(char value[]) ? The public String replace(char oldChar, char newChar) implementation principle of the analysis, how to answer the immutability of the string in this function how to embody? Focus

For:

String is the character char constant, and cannot be changed once it is defined.

Q2. Why should you try to modify the string as frequently as possible instead of using StringBuilder rather than string

A: String each time the string is modified is new, and then deleting the old string will affect efficiency, and StringBuilder is at the end of the string, and string is faster,
There is no big impact on string and StringBuilder in small databases, but when it comes to large data volumes, StringBuilder is much faster than string.

Q3. Compare the values of two strings for equality? Why can't I use = = to compare directly?

A: = = only compares the address of two strings, if the address of the two equal string is different, the comparison is not the same.

Q4. 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);

答: 会输出ture。str1和str2是指向同一个hi。str3是创建了一个新的对象。这段代码创建了两个字符串对象。

Q5. The Integer i = 100;//100 is the base type, I is the reference type, why I can be assigned to 100

A: The JDK will automatically transfer the integer.valueof (100) function.

Q6. Try to parse the following code output results

Integer i1 = 127;Integer i2 = 127; i1 == i2;//true of false? Integer i1 = 128;Integer i2 = 128; i1 == i2;//true of false
答:第一个是true,第二个是flase,integer value 是-128到127,当超过这个范围时,指向的是两个不同的位置。

Q7.

Package with Javac, Java,-classpath,-D
To com.ibm write the Stringutil class in a package, there is a method inside

public static void foo1(){ System.out.println(StringUtil.class+" method:foo1");}

edu.jmuwrite the main class in the package, where the Foo1 method of Com.ibm.StringUtil is dropped
7.1 Try to compile and run with the command line,
7.2 Put the generated stringutil.class under the correct directory structure under D:\lib, put the main.class into the correct directory structure under D:\test, try to run under the command line, and.
7.3 Where is the source code in Eclipse and which directory is the class file placed in? Just click on the Eclipse project to Ctrl+F11 Run main, what kind of java command was executed in which directory when CTRL+F11 was pressed?

Answer: Still doing


Q8. Your goals and plans for this course

A: I currently have the C language and Java, but are not very proficient, a week in addition to school hours will spend two nights to write homework and read some of the books, encounter problems will first discuss with the roommate or go online to check the information, really can not find a way to the teacher for help.



---restore content ends---

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