Where does the word 'dude' come from?

The King of the Dudes (1888)
dude, now perhaps most familiar as a slang term with a wide range of uses (including use as an all-purpose interjection for expressing approval: "Dude!")
Read more: 

The use of 'dude' to describe a male person is becoming increasingly universal amongst young English speakers. Its origins are disputed but certainly date
 back a little further than Dude, Where's my Car? (2000).  According to the American Heritage Dictionary:
Originally it was applied to fancy-dressed city folk who went out west on vacation. In this usage it first appears in the 1870s. 
Dude makes an appearance in and in Mark Twain's A Connecticut Yankee in King Arthur's Court (1889) and pops up in the letters of that unlikely hipster P.G Woodhouse  ('the only English characters the American public would read about were exaggerated dudes' ) 

The word maintained its cult status, appearing in two classic rock songs 'All the Young Dudes' (1972) Mott the Hoople/David Bowie and Steely Dan's Every Major Dude (1974)