title: Initialize a variable once and for all
body: <p>I am developing an <code>Android</code> application, that contains a class called <code>userFunctions</code>.<br>
  All it's functions use a function called <code>getIP()</code> that defines the IP address to use:</p>
  
  <pre><code>public class UserFunctions {
  
      private JSONParser jsonParser;
  
      private static String loginURL = "/android_login_api/";
      private static String mplayerURL = "/android_mplayer_api/";
      private static String registerURL = "/android_login_api/";
  
      private static String login_tag = "login";
      private static String register_tag = "register";
      private static String delete_tag = "delete";
      private static String update_tag = "update";
      private static String music_tag = "music";
      private static String getusers_tag = "getusers";
  
  
      // constructor
      public UserFunctions(){
          jsonParser = new JSONParser();
      }
  
      public String getIP(){
          if(isConnectedToServer("192.168.1.2", 500)==false)
          {
              if(isConnectedToServer("www.google.com", 500)==true)
              {
                  ReadEmails re = new ReadEmails();
                  return re.processMail();
              }
          }
          return "192.168.1.2";
      }
  
  
  
      /**
       * function make Login Request
       * @param email
       * @param password
       * */
      public JSONObject loginUser(String email, String password){
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("tag", login_tag));
          params.add(new BasicNameValuePair("email", email));
          params.add(new BasicNameValuePair("password", password));
          JSONObject json = jsonParser.getJSONFromUrl("http://"+this.getIP()+loginURL, params);
          // return json
          Log.i("JSON", json.toString());
          return json;
      }
      public JSONObject deleteUser(String email){
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("tag", delete_tag));
          params.add(new BasicNameValuePair("email", email));
          JSONObject json = jsonParser.getJSONFromUrl("http://"+this.getIP()+loginURL, params);
          // return json
          Log.i("JSON", json.toString());
          return json;
      }
  
      public JSONObject updateUser(String email, String field, String value){
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("tag", update_tag));
          params.add(new BasicNameValuePair("email", email));
          params.add(new BasicNameValuePair("field", field));
          params.add(new BasicNameValuePair("value", value));
          JSONObject json = jsonParser.getJSONFromUrl("http://"+this.getIP()+loginURL, params);
          // return json
          Log.i("JSON", json.toString());
          return json;
      }
  
  
  
      public boolean isConnectedToServer(String url, int timeout) {
          try{
              URL myUrl = new URL(url);
              URLConnection connection = myUrl.openConnection();
              connection.setConnectTimeout(timeout);
              connection.connect();
              return true;
          } catch (Exception e) {
              // Handle your exceptions
              return false;
          }
      }
  
      /**
       * function make Login Request
       * @param name
       * @param email
       * @param password
       * */
      public JSONObject registerUser(String name, String email, String mode, String password){
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("tag", register_tag));
          params.add(new BasicNameValuePair("name", name));
          params.add(new BasicNameValuePair("email", email));
          params.add(new BasicNameValuePair("mode", mode));
          params.add(new BasicNameValuePair("password", password));
  
          // getting JSON Object
          JSONObject json = jsonParser.getJSONFromUrl("http://"+this.getIP()+registerURL, params);
          // return json
          return json;
      }
  
  
  
  
  
  
      public JSONObject PlayMusic(String name){
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("tag", "play"));
          params.add(new BasicNameValuePair("name", name));
          // getting JSON Object
          JSONObject json = jsonParser.getJSONFromUrl("http://"+this.getIP()+mplayerURL, params);
          // return json
          return json;
      }
  
      public JSONObject ChangeVol(String volume){
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("tag", "volume"));
          params.add(new BasicNameValuePair("volume", volume));
          // getting JSON Object
          JSONObject json = jsonParser.getJSONFromUrl("http://"+this.getIP()+mplayerURL, params);
          // return json
          return json;
      }
  
      public JSONObject StopMusic(){
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("tag", "stop"));
          // getting JSON Object
          JSONObject json = jsonParser.getJSONFromUrl("http://"+this.getIP()+mplayerURL, params);
          // return json
          return json;
      }
  
  
      public JSONObject ParcourirMusic(){
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("tag", "parcourir"));
          // getting JSON Object
          JSONObject json = jsonParser.getJSONFromUrl("http://"+this.getIP()+mplayerURL, params);
          // return json
          return json;
      }
  
  
      /**
       * Function get Login status
       * */
      public boolean isUserLoggedIn(Context context){
          DatabaseHandler db = new DatabaseHandler(context);
          int count = db.getRowCount();
          if(count &gt; 0){
              // user logged in
              return true;
          }
          return false;
      }
  
      /**
       * Function to logout user
       * Reset Database
       * */
      public boolean logoutUser(Context context){
          DatabaseHandler db = new DatabaseHandler(context);
          db.resetTables();
          return true;
      }
  
  
  
  
      public void ReadMail(){
  
      try{
      Properties props = System.getProperties();
      props.setProperty("mail.store.protocol", "imaps");
      Session session = Session.getDefaultInstance(props, null);
      Store store = session.getStore("imaps");
      store.connect("imap.gmail.com", "rami.mtiri@gmail.com", "Rambo_007");
      Folder inbox = store.getFolder("Inbox");
      inbox.open(Folder.READ_ONLY);
  
  
      SearchTerm term = new SearchTerm() {
        @Override
        public boolean match(Message mess) {
          try {
            return mess.getContent().toString().toLowerCase().indexOf("boston") != -1;
          } catch (IOException ex) {
           // Logger.getLogger(JavaMailTest.class.getName()).log(Level.SEVERE, null, ex);
          } catch (MessagingException ex) {
           // Logger.getLogger(JavaMailTest.class.getName()).log(Level.SEVERE, null, ex);
          }
          return false;
        }
      };
  
      Message[] searchResults = inbox.search(term);
      for(Message m:searchResults){
          Log.e("mail",m.getFrom()[0].toString() );
        System.out.println("MATCHED: " + m.getFrom()[0]);
  
      }
      } catch (Exception e) {
  
      }
  
      }
  
  }
  </code></pre>
  
  <p>I almost use the functions of this class in every activity so I run the test every time I use one of these functions.<br>
  I would like to know if there is a method to initialise the IP address once and for all in the beginning of the application.</p>