java - Why do we use Constants? -


why use constants , initialize them in code?i don't why use them. example here:

  public class utils {       public static final string base_url =      "api.openweathermap.org/data/2.5/weather?q=";      public static final string icon_url =      "api.openweathermap.org/data/2.5/weather?q="; } 

constant use maintain , manage constant value in 1 place. example, if going hit server url multiple time can avoid multiple time declare same url. need set delay runnable on time can create constant value (i.e public static final integer delay = 5000; ). use runnable. see below example.

private static final integer delay_time = 3000; private handler mhanlder = new handler();  mhanlder.postdelayed(manimrunnable, delay_time)// same delay using 1 constant variable. mhanlder.postdelayed(mtextupdaterunnable, delay_time)// same delay using 1 constant variable.  private runnable manimrunnable = new runnable() {         public void run() {          //your animation task           }     };      private runnable mtextupdaterunnable = new runnable() {         public void run() {          //your text update task           }     }; 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -