title: Java reverse string method
body: <p>I'm tying to learn Java. I need to make a method called reverse that gets a string and return a string (but in reverse order). Here is what i tried. Can you fix the code and explain what I'm doing wrong? Please also give me some advice about a good start in Java. Thank you!</p>
  
  <pre><code>public class Test{
      public static String reverse(String a){  
          int j = a.length();
          char[] newWord = new char[j];
          for(int i=0;i&lt;a.length();i++)
          {
              newWord[j] = a.charAt(i);
              j--;
          }
          return new String(newWord);
      }
  
      public static void main(String a[]){
  
          String word = "abcdefgh";
          System.out.println(reverse(word));
      }
  }
  </code></pre>