20165202 2017-2018-2 "Java Programming" 6th Week study Summary

Source: Internet
Author: User
Tags stringbuffer

Summary of learning contents of textbookCh8
  • String class:

    The program can be used directly, the string class cannot have subclasses
      • Constructs a String object

    Declaring and creating objects using the String class
    String s = new String("we are students"); String t = new String("we are students");
    S and T entities are the same, but their references are different (emphasis)

      • String collocated

    Participating in a collocated operand as long as there is a variable, the entity and reference of the new string object will be stored in the dynamic zone . If two constants are calculated, they are still constant.

      • Common methods of the string class

    (1) public int length () is used to get the lengths of the character sequences;

    (2) Public boolean equals (String s) compares whether the character sequence of the current string object is the same as the character sequence of the string object specified by the parameter S, and the string object holds a reference ;

    (3) Public boolean startsWith (String s), public boolean endsWith (Sting s)

    Start determines whether the character sequence prefix of the current string object is the character sequence of the string object s specified by the parameter;

    End determines whether the character sequence suffix of the current string object is the character sequence of the string object s specified by the parameter;

    (4) public int compareTo (String s) compares the size of the character sequence of the object s specified by the dictionary order with the parameter

    (5) Public boolean contains (string s) determines whether the character sequence of the current String object contains the character sequence of the parameter s;

    (6)

    The public int indexOf (string s) retrieves the first occurrence of the character sequence position of s from the 0 index position of the current string object's character sequence and returns the position, and if not retrieved, the return value of the method is-1;

    The public int lastIndexOf (string s) retrieves the position of the last occurrence of the character sequence of s from the 0 index position of the character sequence of the current String object, returns the position, and returns 1 if it is not retrieved;

    (7) Public String substring (int start,int end) copies the sequence of characters from the start position in the character sequence of the current object to the character in the end-1 position

    (8) public string trim () gets a new string object that is a sequence of characters after the character sequence of the current string object is stripped of the trailing space.

      • The string representation of the object

    ToString () method invocation form:创建对象的类的名字@对象的引用的字符串表示

      • strings and character arrays, byte arrays

    Public byte[] The GetBytes () method uses the default character encoding, stores the current object character sequence into a byte array, and returns a reference to the array. (Note: The default character encoding is GB2312, a kanji account is two bytes )

  • StringTokenizer class

    The two common construction methods of this class are:
    • StringTokenizer (string s): Constructs a parser for the string object s, using the default delimited tag, which is the space character, line feed, carriage return, tab character, and paper feed character to make a split mark
    • StringTokenizer (strings,string Delim): Constructs a parser for String object s, and any permutation of characters in the character sequence of a parameter delim is delimited
  • Scannner class
    • The Sanner object calls the next () method to return the word in the parsed sequence of characters, and if the last word has been returned by the next () method, the Scanner object call Hasnext () returns false, otherwise ture
    • For a numeric word in a parsed sequence of characters, the scanner object can replace the next () method with the Nextint () or nextdouble () method
    • If the word is not a numeric word, the scanner object calls the Nextint () or nextdouble () method to convert a numeric word to int or double data to return
    • If the word is not a numeric word, the scanner object calls the Nextint () or nextdouble () method to have a inputmismatchexception exception, and the next () method can be called to return a non-digitized word when handling an exception.

    difference : The StringTokenizer class and the scanner class can be used to break down words in a sequence of characters, stringtokenizer the words into the entities of the scanner object, and get the words faster, However, scanner only stores delimited tags and saves memory space.

  • StringBuffer class

    • StringBuffer Object
    • Commonly used methods of StringBuffer class: Append,charat,sercharat,insert,reverse,delete,replace
  • Date class and Calendar class
  • Date formatting
  • Math class, BigInteger class, and Random class
  • Digital formatting
  • Class and Console classes (more difficult)
  • Pattern class vs. Match Class (more difficult)

ch15
    • Generic type
      • Generic-class declarations
      • Declaring an object using a generic class
    • Linked list
      • LinkedList
      • Common methods
      • Traversing a linked list
      • Sorting and finding
      • Shuffle and rotate
    • Stack
      • Stack
      • Use to public E push(E item) implement a push stack operation.
      • Use to public E pop() implement a stack operation.
      • Use public boolean empty() to determine if the stack has data, return false, or true.
      • Use public E peek() to get the data at the top of the stack, but not delete the data.
      • Use public int search(Object data) to get the data in the PVP position.
    • Hash map
      • HashMap
      • Common methods
      • Traverse Hash Map
      • Hash-map-based queries
    • Tree Set
      • TreeSet
      • The relationship of the size of the node
      • Common methods of TreeSet class
problems in teaching materials learning and the solving process
    • Question 1:p180 Example8_3 After writing sortstring, there's a line "System.out.println("") I don't really understand.
    • Problem 1 Solution: Refer to System.out.println () and System.out.println (""); the difference? "And the code to run the results, I guess it should be to output a space and wrap, canonical output format.
Problems in code debugging and the resolution process
    • Issue 1:example15_11 Some input files are using unchecked or unsafe operations

    • Issue 1 Solution: Compile again no more error, I checked the related errors have the following categories
      • Note: Some of the input files use or overwrite outdated APIs.
      • Note: For more information, please recompile using-xlint:deprecation.
      • Note: Some input files use an unchecked or unsafe operation.
      • Note: For more information, please recompile using-xlint:unchecked.
      Refer to the Java compile Times error: Using unchecked or unsafe operations, there are two ways to solve the problem:
      • 1. The use of annotations in front of the main method @SuppressWarnings("unchecked") tells the compiler not to check, and this can be avoided during compile time security checks.
      • 2. Use generics.ArrayList<String> list = new ArrayList<String>();
        Because generics are not used in Java, it is necessary to use "<>" for generics after Java1.5, with generics you're going to write a vector.
Code Hosting

last week's summary of the wrong quiz

1. The following statement about the Super keyword is correct

A. If you want to use a member variable or method that is hidden by the quilt class in a subclass, you need to use the keyword super.

B. Textbook P123 Code Example5_7.java, the average class G () method called "C=super.f ()" is the average class of float f ().

C. How a subclass is constructed if it does not clearly indicate which construction method to use the parent class, the subclass calls the parent class's constructor without arguments.

d.p124 program Example5_8, if Super is omitted from the Universtudent subclass constructor method, the program defaults to the super () of the student class.

Correct answer: A C D

2. The following statement about the abstract keyword is correct

A. You can use static to modify the abstract method.

B. The abstract method cannot be used in a non-abstract class.

C. You cannot use new to create an abstract class object.

D. It is not allowed to use final and abstract to modify a method at the same time.

E. You can use public abstract void Eat () {} to declare an abstract method eat ().

F. Abstract methods only retain the functionality of the method, and the specific execution is given to subclasses of the inherited abstract class, which is overridden by subclasses.

Correct answer: B C D F

Parsing: 5.9 knots. Item A: The abstract keyword cannot be applied to static, private, or final methods. Item E: Cannot have method body.

3. The following statements are correct

A. Subclasses inherit the construction method of the parent class.

B. The subclass of the abstract class must be a non-abstract class.

C. A method inherited by a subclass can only manipulate member variables that are inherited and hidden by subclasses.

D. Subclass overrides or new methods can also manipulate the member variables hidden by the quilt class directly.

Correct answer: C

4. The following statements are correct

A. UML uses a solid line connection class and its interfaces.

B. An import statement allows you to introduce an interface in a package.

C. The interface can call other non-interface methods in the class.

D. The interface belongs to a reference variable.

Correct answer: B D

5. Does replacing the following (a,b,c,d) code with "code" in the following program cause compilation errors?

interface Com {   int M = 200;   int f();}class ImpCom implements Com {    【代码】}

A. public int F () {return 100+m;}

B. int F () {return 100;}

C. Public double F () {return 2.6;}

D. public abstract int f ();

Correct answer: B

6. If you have the following program fragments

interface Some{int x = 10;}public class Main{public static void main (String [] args) { System.out.println(Some.x);     }}

The following description is correct

A. Compilation failed

B. Showing 10

C. You must create an some instance to access X

D. Showing 0

Correct answer: B

Impressions

This week's focus is on the eighth chapter of the study, before just mechanically using such as String and scanner classes, through this chapter on the "Class" has a new understanding, some of the previous "Why use this?" "The confusion was gradually solved. Through the test feedback out of a lot of problems, read the textbook feel that they will, but the shallow memory will soon disappear, in the process of doing some concept definition or ambiguous. The next step is to continue to implement the content of the textbook, more to understand the memory and even learn to apply.

Learning progress bar
lines of code (new/cumulative) Blog Volume (Add/accumulate) Learning Time (new/cumulative)
target 5000 Line 30 400 hours
first week 24/24 1/4 15/15
second week 423/423 2/ 6 14/29
third week 702/1109 1/7 16/45
fourth week 918/20 2/9 16/61
fifth week 1208/3235 2/11 15/76
sixth week 1137/4372 2/13 14/90

20165202 2017-2018-2 Java programming 6th 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.