How to end a game with ESC button.

How to end a game with ESC button (quit the game and go back to windows after the player have finished playing)

// JS
function Update()
{
    if (Input.GetKey(KeyCode.Escape))
    {
        Application.Quit();
    }
}

// C#
void Update()
{
    if (Input.GetKey(KeyCode.Escape))
    {
        Application.Quit();
    }
}

How exactly does that work? Could you give an example? Do you create this in Java? Just cut and paste this over existing text and save?