20165220 Java Sixth Week study summary

Source: Internet
Author: User
Tags stringbuffer

Summary of learning contents of textbook
    • Regular expression: a regular expression is a sequence of characters of a string object that contains characters that have special meanings, which are called meta-characters of regular expressions.
    • List: A data structure consisting of several objects called nodes that are used to dynamically reduce or increase data items.
    • The string class is the final class, meaning that the string class cannot be inherited, and its member methods default to the final method. In Java, a class that is final decorated is not allowed to be inherited, and the member methods in the class default to the final method.
  • String object: You can use the string class to declare an object and create an object, for example: string s = new String ("We are students");
    String t = new String ("We are students");
  • Stack object creation and compaction, stack operation, etc.
  • List: A data structure consisting of several objects called nodes that are used to dynamically reduce or increase data items.
  • Gets the data at the top of the stack, but does not delete the data: public int search (Object data);
  • Use the string class to format a number by calling the Format method;
  • Use date and calendar to process dates and time-related data;
  • Generics (generics), whose main purpose is to establish a type-safe collection framework, such as linked lists, hash maps, and other data structures.
    You can use class name < generic list > To declare a class, so that the declared class is called a generic class, in order to be different from a normal class, such as:
    Class people where people is the name of the generic class, E is the generic, which means that we do not specify what type of data e is, it can be any object or interface, but it cannot be a basic type of data.
  • The Java.lang.String class uses the final decoration and cannot be inherited. All literals in a Java program, that is, strings enclosed in double quotes, such as "ABC", are implemented as instances of the string class. A string is a constant whose object can no longer be changed once it is constructed. In other words, the string object is immutable, and each method that looks to modify the string value actually creates a completely new string object that contains the modified string content. The original string object is not moved at all. A string object has a read-only attribute, and any reference to it cannot change its value, so there is no effect on other references. But a string reference can be re-assigned. Java strings are Unicode encoded in memory, and any one character corresponds to a two-byte fixed-length encoding, that is, any one character, whether Chinese or English, is a character length and occupies two bytes.
  • Constant Pool (constant pool) refers to some data that is determined at compile time and is saved in the compiled. class file. It includes constants in classes, methods, interfaces, and so on, and also includes string constants. Java in order to improve performance, static strings (the result of literal/constant/constant connections) are created in a constant pool and use the same object as much as possible, reusing static strings. For recurring string literals, the JVM will first look in the constant pool and return the object if it exists in the constant pool.
  • The difference between String, StringBuffer, and StringBuilder

    1. Variable and non-volatile objects

      The string class uses a character array to hold the data because there is a "final" modifier, so the string object is immutable. As follows:

    Private final char value[];

      Both StringBuilder and StringBuffer inherit from the Abstractstringbuilder class, which is also used to store data in Abstractstringbuilder, both of which are mutable. As follows:

    Char[] value;

    2. Whether it is thread-safe

    The object in string is immutable and can be understood as a constant, so it is thread safe .

    Abstractstringbuilder is the common parent of StringBuilder and StringBuffer, and defines some basic operations for strings, such as expandcapacity, append, insert, indexof, and other public methods.

    StringBuffer is thread-safe because it adds a synchronous lock to a method or a synchronous lock on a method that is called.

    3.StringBuilder and StringBuffer in common

    StringBuilder and StringBuffer have a public abstract parent class Abstractstringbuilder.

    One difference between an abstract class and an interface is that the public methods of some subclasses can be defined in an abstract class, and subclasses simply need to add new functionality and do not need to repeat the existing methods, whereas interfaces are simply definitions of the declarations and constants of the methods.

    StringBuilder, StringBuffer methods will call public methods in Abstractstringbuilder, such as Super.append (...). Just stringbuffer will add synchronized keywords to the method and synchronize.

    If the program is not multithreaded, then using StringBuilder is more efficient than stringbuffer.

Problems in code debugging and the resolution process

This error message appears at compile time;

answer : Check the code without any problems, refer to the previous errors, I first analyzed the reasons, this should be required to co-compile multiple files caused. Then I looked up the information and asked my classmates, and found a way, that is, the relevant files to the same prefix, and then unified compilation, run. Just like E9_1 e9_2 e9_3, then use the command Javac E9*.java to compile and run. Although it makes the class name meaningless, it solves the problem. On this basis, we can find a better solution.

Code Hosting

Last week's summary of the wrong quiz

Wrong Title 1:

There is a public void fight () in the parent class, and there is a public void fight (weapon W) in the subclass, and the relationship of the two methods is override.

A.true
B.false
Parsing: Subclasses override methods that have exactly the same method name, number of arguments, parameter type, and parent class. Here is the overload.

Wrong Title 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 permissible 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, overriding this abstract method by subclasses.
Parsing: 5.9 knots. Item A: The abstract keyword cannot be applied to static, private, or final methods. Item E: Cannot have method body.

Sentiment:

This week's content is significantly more than the previous two weeks, and is a new knowledge and new concepts that have not been contacted in the past, it will take time to understand, and the code will have to be improved step-by-step. I am still not proficient in these new knowledge, I hope to spend more time on the code after the proficiency of the application. I think pre-class preview is very necessary, if not in time to master so will be left a lot of, follow the large troop together to advance is the best, knot to learn also first experience the fun, I believe that will be more and more good!

Resources

Java Learning Note (8th Edition) Learning Guide

20165220 Java Sixth Week study summary

Related Article

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.