1. Summary of this week's study
(1) Be able to use the code cloud more skillfully
(2) Learn the usage and use of Arrys and string
(3) Know how to query the source code of the function, by looking at the source code, can be more in-depth understanding of function applicability and pros and cons
2. Written work
1. Use eclipse to correlate the JDK source code and view the source () of the string object? What does the parsing string use to store strings? Analyze the implementation principle of its constructor public String (char value[])? Parses the implementation principle of public string replace (char OldChar, char Newchar), and answers how the immutability of a string is reflected in the function?
(1)
You can press and hold Crtl Addend the left click to view the source code directly.
(2) string as an array of characters, after initialization can not be modified, to use string to change its contents, will create a new array, and then point to the new array, the original array is unchanged and will not disappear, so it may reduce the efficiency of the Code.
2. Why should I try to modify the string as frequently as possible by using StringBuilder instead of string?
The difference between string and StringBuilder is that each time a string is modified to be new and then deleted from the original string, it affects efficiency, and StringBuilder is manipulated at the end of the string, so it is faster.
3. Compare the values of two strings for equality? Why can't I use = = to compare directly?
In a string object defined with the new string ("a"), even if the content is the same, it is false to use "= =" to compare equality, because "= =" compares an in-memory address.
4. Try using 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);
Run by step, first in the string pool to find whether there is "hi", and then build str1, the next str2 is the same, but can find the "HI" established, str2 point to it, to str3 new content and str1 the same new string "HI", The last line is to compare the str1 and str2 addresses for equality and output "ture".
5.Integer i = 100;//100 is the base type, I is the reference type, why I can be assigned to 100
The Integer i is actually integer.valueof (i), and when the value is between 128 and 127, the integer.valueof () is called directly.
6. Try to analyze 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
The first is ture, because 127 is between 128 and 127, I1, I2 point to the same address, and the second is false because 128 is over range, I1, I2 does not point to the same address. the "= =" comparison is the address.
7.package with Javac, Java,-classpath,-D
To write the Stringutil class in the COM.IBM package, there is a method inside
public static void Foo1 () {
System.out.println (stringutil.class+ "method:foo1");
}
Write the main class in the EDU.JMU package, where the Com.ibm.StringUtil Foo1 method 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? Click Ctrl+f11 in the Eclipse project to run main directly, what kind of java command is executed in which directory when CTRL+F11 is pressed?
Not quite understand the topic: (
8. Your goals and plans for this course
Currently C language, C + +, the code is not much written.
Decided to spend more time to learn Java, every week to complete all the PTA work, encountered difficulties first Baidu, can not get answers to ask classmates teacher.
3. Using the code cloud to manage Java code
4. PTA Experiment
Still in progress ...
The combination of a call to a function in 1.java, a switch, and an enumeration type
2. Mastering the use of the StringBuilder class
3. Storing the ID number with an ArrayList array
201521123031 Java Programming 2nd week of study summary