title: Pass variable between class - java
body: <p>I just started with Java recently. I have one variable in one class and I want to use in another class. I know that this is very basic, but if someone can help....</p>
  
  <p>This is the class and the variable is value</p>
  
  <pre><code>public class MainApp {
  .
  .
  .
  
  public static  class AnalogSampleListener implements IIOSampleReceiveListener {
      @Override
      public void ioSampleReceived(RemoteXBeeDevice remoteDevice, IOSample ioSample) {
          for (IOLine line : LINES) {
              if (ioSample.hasAnalogValue(line)) {
                  int ***value*** = ioSample.getAnalogValue(line);
  
                  System.out.println(new Timestamp(System.currentTimeMillis()) + " " + "Analog data from '" + remoteDevice.get64BitAddress() + 
                          "': " + value);
  
       }
    }
  .
  .
  }
  </code></pre>
  
  <p>I want to send the variable value to this class:</p>
  
  <pre><code>public class RandomWave implements Runnable{
  
  .
  .
  .
  
  public void run()
  {
      long currentTime = 0;
      long nextTime = 0;
  
      // Variable to keep track of the timing
      long timer = System.nanoTime();
  
      while (!stopThread)
      {
          // Compute the next data value
          currentTime = (System.nanoTime() - timer) / 1000000;
  
          double p = currentTime / 1000.0 * 4;
          double series0 = ***HERE I NEED THE VARIABLE VALUE***;
          double series1 = 210 + 60 * Math.sin(p / 21.7) * Math.sin(p / 7.8);
  
          // Call the handler
          handler.onData(currentTime / 1000.0, series0, series1);
  
          // Sleep until next walk
          if ((nextTime += interval) &lt;= currentTime)
              nextTime = currentTime + interval;
  
          try { Thread.sleep((int)(nextTime - currentTime)); }
          catch (InterruptedException e) {};
      }
  }
  </code></pre>
  
  <p>Thank you</p>