I was reading an article on TheServerSide on ployglot programming on the Java platform. Some comments in the article refer to metaprogramming as the ability to generate code
Well, metaprogramming is just programming, but it's basically "writing code that writes code".
The ability that you mention, when a program can observe and modify its own structure and behaviour is called reflection and it's a type of metaprogramming.
Dynamically typed languages, have powerful runtime reflection features, made possible by the interpreted nature of these languages...
Static typed languages also have powerful metaprogramming techniques, for example the C++ template metaprogramming...