title: Why is init() method required when I can initialise variables in paint() when writing a Applet
body: <p>I am new to programming and to Applets as well. 
  Its mentioned in my book that init() method should be used to initialise variables and that paint is called each time output needs to be redrawn on the screen. </p>
  
  <p>But the following code works just fine. Why is init() needed then? </p>
  
  <pre><code>import java.applet.*;
  import java.awt.*;
  
  /*
  &lt;applet code = "demo" width = 500 height = 600&gt;
  &lt;/applet&gt;
  */
  
  public class demo extends Applet{
      String msg;
      public void paint(Graphics g){
          int x = 45;
  
          msg = "Inside paint-----" + x;
          g.drawString(msg, 20, 20);
      }
  }
  </code></pre>