Differences between common and static methods in Java

Source: Internet
Author: User
Static methods can be called directly by class names, while common methods can be called only after class objects are created!
Static methods and variables are called to generate a unique identifier in the memory. You can think of it as giving a static location in the physical memory, which can be directly found during the call, it also saves memory, but if you declare too many static resources, then every one will have a seat in the memory, then you will not have the resources to run anything else, and will report a memory overflow!
The general method is controlled by the GC mechanism of Java. during the use of the same object or variable, the time occupies a seat in the memory, the last time has not been deleted from the memory, so there may be two identical items in the memory. These two items are only the same content value, but the memory value is different, you can use "=" and "equals" (this applies only to objects and string types ). java's GC mechanism will automatically clear some unused variables or objects based on the memory status at runtime, even if you manually call GC!

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.