Java Programming Ideas

Source: Internet
Author: User
Tags export class

  1. Constructors are not polymorphic, they are actually static methods, and the static is implicitly declared
  2. Objects have state, behavior, and identity. This means that each object can have internal data (which gives the state of the object) and methods (method generation behavior), and each object can be uniquely distinguished from other objects, specifically, each object has a unique address in memory
  3. In Java, everything is treated as an object, so you can use a single fixed syntax. Although everything is considered an object, the manipulated identifier is actually a "reference" to the object
  4. Finalize () Purpose: Garbage collection is only related to memory, that is, the only reason to use the garbage collector is to reclaim memory that is no longer used in the program. So for any behavior related to garbage collection (especially the Finalize () method), they must also be related to memory and its recycling.
  5. Whether it is garbage collection or termination, there is no guarantee that it will happen. If the Java virtual machine is not running out of memory, it will not waste time doing garbage collection to fix the memory.
  6. The building of the base class (parent class) and the derived class (subclass) is diffused from the base class, so the base class has already initialized before the export class accesses it. Even if you do not create a constructor for a subclass, the compiler will synthesize a default constructor for you, and the constructor will call the accumulated constructor.
  7. The combination technique (HAS-A) is typically used in situations where the functionality of an existing class is used in a new class rather than its interface. That is, embedding an object in the new class to implement the required functionality, but the new class's users see only the interface defined for the new class, not the interface of the embedded object. To achieve this effect, you need to embed a private object of an existing class in the new class
  8. Protected keyword: This is private for the class user, but it can be accessed for any derived class (subclass) that inherits from this class, or any other class that is within the same package.
  9. All methods in Java implement polymorphism through dynamic binding. Dynamic binding, also called run-time binding, refers to the type of an object that is bound at run time.
  10. Polymorphism is an important technique that allows programmers to "separate things from change and things that are changed." If a method is static, its behavior is not polymorphic.
  11. Complex objects call the constructor in order: A. Call the base class constructor. This step is repeated recursively, first of all, to construct the root of this hierarchy, then the next layer of the export Class (subclass), and so on, know the lowest layer of the export Class (subclass) B. Initialize method for invoking members in Declaration order c. Calling the body of the Export class Builder
  12. There is a valid guideline when writing a constructor: Make the object into a normal state in as simple a way as possible, and avoid invoking other methods if you can. The only method that can be safely called within the constructor is the final method in the base class (also applicable to private methods, which are automatically part of the final method)
  13. One common rule is to use inheritance to express differences between behaviors and to express state changes with fields. Through inheritance, two different classes are used to express the difference of the Act () method, while the stage changes its state by applying a combination. In this case, the change in this state also produces a change in behavior.
  14. Creating a method that can vary depending on the passed parameter object is called a policy design pattern . Such methods contain fixed components in the algorithm to be executed, and "policy" contains the parts to be changed. A policy is a parameter object that is passed in, which contains the code to be executed.
  15. Adapter Design mode : The code in the adapter will accept the interface you have and produce the interface you need.
  16. The core reason for using the interface is to be able to move up to multiple base types (and the resulting flexibility), to prevent client programmers from creating objects of that class, and to make sure that this is just an interface.
  17. If you want to create an object of an inner class from anywhere other than the non-static method of the outer class, you must specify the type of the object: Outerclassname.innerclassname. An inner class can access all members of an external class object without requiring any special conditions. In addition, the inner class has access to all elements of the external class.
  18. Arraylist,linkedlist,linkedhashset,linkedhashmap Save Collection objects in order of storage
  19. Polymorphism is the basic goal of object-oriented programming. Run-time type information allows you to discover and use type information while the program is running.
  20. The basic idea of Java is that "poorly structured code cannot run"
  21. An exception condition is an issue that prevents the current method or scope from continuing to execute. It is important to differentiate between anomalies and common problems: the common problem is that it is possible to get enough information in the current environment to handle the error, and the exception situation cannot continue because the necessary information is not available to solve the problem in the current environment. All you can do is jump out of the current environment and give the problem to the upper level, which is what happens when you throw an exception.
  22. Regular expression:-?\\d+ indicates that there may be a minus sign followed by one or more digits; "(-|\\+)? \\d+" means that it may start with a plus or minus sign, followed by one or more digits, the \w represents a non-word character, and \w represents a word character, the only difference is w case is different; n \\w = Letter N followed by non-word characters
  23. The class object is loaded only when needed, and static initialization occurs when the class is loaded. When you use the Class.forName (String s) method to get the type object of a class, the parameter must fill in the package name and class name; Java also provides another way to get a reference to a class object, the class name. class literal constant, which is more secure because it is checked at compile time , so you don't need to put it in a try block. Using the. class method to get a reference to a class does not throw an initialization, and using the Class.forName () method throws the initialization.
  24. A class reference always points to a class object, which restrains the creation of an instance of a class and contains all the method code that can be used for those instances. It also contains the static members of the class, so that class represents the exact type of the object it points to, and that object is an object of class, and both of the following are correct: class Intclass=int.class; Class<integer> Genericintclass=int.class;genericintclass=integer.class;
  25. A proxy is one of the basic design patterns that you insert to replace an "actual" object in order to provide additional or different operations. These operations typically involve communication with an "actual" object, so the agent usually acts as a middleman.
  26. Arrays differ from other containers in three ways: efficiency, type, and the ability to preserve basic types. An array is the most efficient way to store and randomly access an object's reference sequence. An array is a simple linear sequence, which makes the element access very fast. But the price paid for this speed is that the size of the array object is fixed and immutable in its life cycle.

27. Generics and polymorphism do not conflict.

Java Programming Ideas

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.