1. Summary of this week's study
1. Learned the string class;
The use of 2.java arrays;
3. Learned the class name package name.
2. Written assignment Q1. Use eclipse to correlate JDK source code and view the source () of a string object?
Q2. Why should I try to modify the string as frequently as possible, instead of using StringBuilder rather than string?
String each time the string is modified to create a new, and then delete the old string will affect efficiency, and StringBuilder is at the end of the string operation, and string compared to the faster, in. NET string is immutable object, Once a string object is created and assigned a value, it is not possible to change it, so the string type may add more statements to define more variables when it identifier the serial operation of the word frequently.
Q3. Compare the values of two strings for equality? Why can't I use = = to compare directly?
String is a reference type, which is if we create many string pairs of characters of the same value, it should have the same point in memory as the address. That is, when we create a string object m, given a value of M, when we create a String object N of the same value again, it will not allocate a chunk of memory space, but directly point to the address of M in memory.
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);
the output "True" str1 and str2 point to the same object.
Q5. The Integer i = 100;//100 is the base type, I is the reference type, why I can be assigned to 100
Equivalent to an integer i=new integer (100).
Q6. Try to parse the following code output results
127;Integer i2 = 127;i1 == i2;//true of false?Integer i1 = 128;Integer i2 = 128;i1 == i2;//true of false
第一个是true,第二个是false。127在-128~127之间,所以为TRUE,128大于这个范围,比较的是地址。
Q7.package and 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 into the Lib directory of the D drive, and Main.class in the D:\test directory, try to run under the command line.
7.3 Where the source code in Eclipse is placed, and in which directory the class file is placed. Click Ctrl+f11 in the Eclipse project to run main directly and try to analyze the rationale behind the implementation.
Q8. My goal in this course
201521123085 Java Programming 2nd week of study summary