TestNG Dependency test method

package seleniumTestNG;

import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;

public class TestNG_G_dependsOnMethods {
    WebDriver driver;

    @Test(dependsOnMethods={"method2"})
    public void method1() {
        driver.findElement(By.name("q")).sendKeys("seleniumtool.com");
        System.out.println("This is method 1");
    }

@Test
    public void method2() throws Exception{
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        driver.get("http://www.google.com");
        System.out.println("This is method 2");
        Thread.sleep(3000);
    }

    @BeforeTest
    public void beforeTest() {
        driver = new FirefoxDriver();
        // System.setProperty("webdriver.chrome.driver","D:\\lib\\chromedriver.exe"); //---> Chromedriver path
        // driver = new ChromeDriver();
        driver.manage().window().maximize();

    }

}

What is dependency Test?

Dependency is a feature in TestNG that allows a test method to depend on a single or a group of test methods.
This will help in executing a set of tests to be executed before a test method.

How it can be done in testNG?

TestNG allows you to specify dependencies either with: 
Using attribute dependsOnMethods in @Test annotations
Using attribute dependsOnGroups in @Test annotations.