Static methods of java, static variables

Source: Internet
Author: User

static methods and static variables are often used in automated tests. So what are static methods and static variables? and under what circumstances? Here's a Talk.

Static and static variables use public memory space, meaning that all objects can be referenced directly, without the need to create objects and then use the method, which is used to modify the traffic with Static.

They all belong to the class itself and are loaded into memory when the class is loaded, not automatically destroyed, and will persist in memory until the JVM shuts down.

Static variables:

 public class Assertion {        privatestaticnew Log (assertion.  Class);          public Static Boolean true ;          public Static New Arraylist<error> ();

Static method:

     public Static boolean Setflag (boolean  fla) {        flag=fla;         return flag;        }

Because static members do not need new to be used, efficiency is more efficient than non-static methods, so the following scenarios are more appropriate:
1. assertion, fileutil, log, etc. in frequently used tool classes that do not require the generation of Objects.

2. Object-independent methods can be set to static METHODS.

3. Some common methods in common Classes.

4. Many classes require variables that are set to static and used as global variables.

Static methods of java, static variables

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.