First day of Java special practice

Source: Internet
Author: User


  1. String,stringbuffer,stringbuilder: A thread-safe situation: When a thread needs to overwrite this data, it will give the data a synchronous lock, such as a thread to get the data, and a synchronous lock on the data, when the B thread comes in, However, when the data is locked, the B thread waits for the a thread to release the lock before manipulating the data, preventing dirty data from being generated.

    Strings in Java are stored in the string constant area and will not change, creating a new object when the change occurs

    StringBuffer: String variable (Synchronized, thread safe). If you want to modify the string content frequently, it is best to use stringbuffer for efficiency reasons, and if you want to turn to string type, you can call the ToString () method of StringBuffer.

    Java.lang.StringBuffer A variable sequence of characters for thread safety. It contains a specific sequence of characters at any point in time, but some method calls can change the length and content of the sequence. String buffers can be safely used with multiple threads.

    The main operations on StringBuffer are the Append and insert methods, which can be overloaded to accept arbitrary types of data. Each method effectively converts the given data into a string, and then appends or inserts the character of the string into the string buffer. The Append method always adds these characters to the end of the buffer, while the Insert method adds characters at the specified point. For example, if z refers to a string buffer object where the current content is "start", this method call Z.append ("le") causes the string buffer to contain "startle", and Z.insert (4, "le") will change the string buffer to contain " Starlet ".

    StringBuilder: String variable (non-thread safe). Internally, the StringBuilder object is treated as a variable-length array that contains a sequence of characters.

    Java.lang.StringBuilder is a variable sequence of characters that is JDK5.0 new. This class provides an API that is compatible with StringBuffer, but does not guarantee synchronization. This class is designed to be used as a simple replacement for StringBuffer, when a string buffer is used by a single thread

  2. Java keyword list (alphabetical order of 50 groups):

    Abstract, Assert, Boolean, break, Byte, case, catch, char, class, const (reserved keyword), cont Inue, default, do, double, else, enum, extends, final, finally, float, for, goto (reserved keyword), if, implements, import, Instanceo f, int, interface, long, native, new, package, private, protected, public, return, short, static, STRICTFP, super, switch, Synchronized, this, throw, throws, transient, try, void, volatile, and while

    reserved word list (alphabetical order of 14 groups), Java reserved word refers to the existing Java version has not been used, Later versions may be used as keywords:

    Byvalue, cast, false, future, generic, inner, operator, outer, rest, True, Var, goto (reserved keyword), cons T (reserved keyword), null

    True false is a Boolean variable value that the compiler assigns to a specific meaning, but is not a keyword.

  3. The similarities and differences between the
  4. Abstrat class and interface

    The class that contains the abstract modifier is an abstract class, an instance object that the abstract class cannot create. A class containing an abstract method must be defined as an abstract Class,abstract class in which the method does not have to be abstracted. Abstract class definitions must be implemented in a specific (concrete) subclass, so there can be no abstract constructor or abstract static method. If the subclass does not implement all the abstract methods in the abstract parent class, then the subclass must also be defined as an abstract type.   the

    Interface (interface) can be described as a special case of an abstract class, and all methods in an interface must be abstract. The method definition in the interface defaults to the public abstract type, and the member variable type in the interface defaults to public static final.  

    Compare the syntax differences between the two:  

    1. Abstract classes can have a constructor method, and the interface cannot have a constructor method.  

    2. There can be ordinary member variables in the abstract class, there is no ordinary member variable   in the interface,

    3. Abstract classes can contain non-abstract ordinary methods, all the methods in an interface must be abstract and cannot have non-abstract ordinary methods.  

    4. The access type of an abstract method in an abstract class can be public,protected and (the default type, although  

    Does not make an error under eclipse, but it should not), However, the abstract method in an interface can only be of the public type, and the default is the public abstract type.  

    5. The abstract class can contain static methods, the interface cannot contain static methods  

    6. Abstract classes and interfaces can contain static member variables, and the access type of static member variables in an abstract class can be arbitrary, However, the variables defined in the interface can only be public static final types, and the public static final type is the default.  

    7. A class can implement multiple interfaces, but only one abstract class is inherited

  5. The difference between arraylists and LinkedList:

    ArrayList is the realization of the data structure based on dynamic array, LinkedList data structure based on the linked list.

    For random access get and set,arraylist better than LinkedList, because linkedlist to move the pointer.

    Add and remove,linkedlist are the dominant for new and deleted operations because ArrayList is moving the data.

    ArrayList space waste is mainly reflected in the end of the list to reserve a certain amount of space, while the linkedlist of the space cost is reflected in its every element needs to consume considerable space.

    ArrayList is based on an array implementation.

    LinkedList is based on a linked list implementation.

This article is from the "Superhakce" blog, make sure to keep this source http://superhakce.blog.51cto.com/6671637/1898769

First day of Java special practice

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.