Java basic knowledge note (1: modifier, vector, hash table), java

Source: Internet
Author: User
Tags define abstract

Java basic knowledge note (1: modifier, vector, hash table), java
I. Features of the Java language (develop the habit of frequently viewing Java online help documentation)

(1) Simplicity: Java is a new type of computer language simplified and improved on the basis of C and C ++ computer languages. It removes the pointers that are most difficult to correctly apply C and C ++ and the multi-inheritance technology that is most difficult to understand, and simplifies program memory management through the garbage collection mechanism, the memory occupied by various data types on different operating system platforms is unified.

(2) network features: Java is currently one of the most comprehensive network-related computer languages.

(3) Object-oriented: Because Java is a new computer language, it is not compatible with procedural computer languages, therefore, Java is more thorough in terms of object-oriented features than C ++.

(4) platform independence/Portability: the Java language is designed to allow programs to run on any computer platform without modification.

(5) Stability: Java performs strict checks during compilation and execution to reduce errors. Java's automatic garbage collection and Exception Handling Mechanism greatly improve the stability of the program. In addition, the simplicity of the Java language also improves the stability of the program to a certain extent.

(6) Security: Java programs running on the network comply with the network security protocol. During Java program execution, the Java Virtual Machine checks program security.

(7) multithreading: This is mainly used to process complex transactions or transactions that require parallel processing. The programs that constitute the Java Virtual Machine generally adopt the multithreading mechanism. Multithreading is a way to improve program running efficiency, but it also increases the difficulty of program design.

(8) Explanatory: Java is an explanatory language. This is a disadvantage of the Java language, because the interpreted Execution Language is generally less efficient than the compiled Execution Language (for example, C or C ++.

 

Ii. Roles of environment variables path and classpath

The path variable records the path of each running program. The system looks for the running program based on the value of this variable.

Classpath is usually used to record the current path and the path of the J2SE class library. This is an environment variable required by J2SE.

The J2SE class library contains various software packages provided by the J2SE system, including various classes and interfaces. After setting the classpath environment variables, you can directly use the classes or interfaces of various Java software packages in the current path and the path of the J2SE class library in the program.

 

Iii. Introduction to modifier abstract, static, and final

(1) abstract: Java allows classes, interfaces, or member methods to have abstract attributes, but does not allow member domains or constructor methods to have abstract attributes. If the definition class modifier list contains the abstract keyword, the class has the abstract attribute. This class is called an abstract class. An instance object of an abstract class cannot be generated through the constructor of the abstract class. An interface always has abstract attributes. Therefore, the interface has abstract attributes regardless of whether the interface modifier list contains abstract keywords. If the keyword abstract is contained in the method modifier list that defines the member method, the member method has abstract attributes. Abstract member methods are generally defined in class bodies that define abstract classes or interface bodies that define interfaces.

The difference between the definition format of an abstract member method and the Definition Format of a member method that does not have an abstract attribute: Apart from whether a method modifier abstract exists, the definition of an abstract member method ends with a good ending, the method body is not included. The definition of member methods without abstract attributes cannot contain semicolons immediately after the member methods are declared, and the method body must be included.

(2) static (static): Except for internal classes, classes generally cannot have static attributes. The class constructor cannot have static attributes. The member fields and member methods of a class can have static attributes. If the modifier static is added to the domain modifier list that defines a member domain, the member domain has a static attribute. If the modifier static is added to the method modifier list that defines the member method, the member method has a static attribute called the static member method.

In Java, a class is a template of its instance object, and the class itself can also be seen as an object, referred to as a class object. The static member of the class belongs to this object. You can directly call the static member method of the class name or the static member method of the class. The specific form is as follows: Class Name. static member domain, class name. static member method name (member method call parameter list ).

(3) final (final): keyword final (final) it can be used to modify the member domains of classes, classes, interfaces, and classes that do not have abstract attributes. If the modifier list of the defined class contains the class modifier final, the class has the final attribute.

If the modifier final is added to the modifier list that defines a member domain, the member domain has a final attribute. If the member domain has both final and static attributes, the value of the member domain can only be assigned at the time of definition, and the value of the member domain cannot be modified afterwards. If a member domain has a final attribute but does not have a static attribute, the member domain can only be assigned a value at the time of definition or in the constructor, and can only be assigned a value once.

If the modifier final is added to the method modifier list that defines the member method, the member method has the final attribute. In this case, the member method must not have abstract attributes. If a member method of a class has a final attribute, the member method cannot be overwritten by the member method of the subclass of the current class.

 

Iv. Introduction to Vectors

The function of a vector is similar to an array, but the number of elements can be changed. The data type of a vector element must be a reference type. The basic principle of a vector is to allocate a certain amount of storage space to the vector object in advance, and then add elements or set element values to the vector object. The storage space of a vector object is called the capacity of a vector object. The unit is the number of elements. The actual number of elements of a vector object is called the length of a vector object. If the length of the vector object changes, when the new length exceeds the old capacity of the vector object before the length change, the capacity of the vector object will automatically expand. A vector object also defines a volume called capacity increment.

The Declaration format of Vector variables is: Vector <data type of Vector elements> variable name;

Vector Instance Object creation method: Usually through java. util. vector constructor creates a Vector object -- public Vector (). The initial capacity of a Vector object is 10 by default, and the capacity increment is 0 by default.

Operations on vector object instance objects include adding elements (member methods include add, addElement, insertElement, etc.) and modifying elements (member methods include set and setElement), delete elements (member methods include clear, remove, removeElement, removeElement, etc.), and query information (member methods include contains, equals, capacity, etc ).

 

V, Hash Table introduction

The array and vector store the elements in order, so you can easily obtain the element through the subscript of the element. However, if you know the element and want to obtain the subscript of the element, it is relatively difficult. Generally, You need to search in sequence. If arrays or vectors have been sorted in a certain way, you can use the binary method to perform a semi-query to accelerate the search process. It is generally considered that the fastest way to find the storage location corresponding to this element from an element is to use a hash table. A hash table is also called a hash table.

Hash Table detailed description link: http://www.cnblogs.com/vamei/archive/2013/03/24/2970339.html#undefined

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.