Adding to the Compiler
Macros find some particular pattern in your code and replacing it with other (usually longer and less comprehensible) code at compile time. This can be as simple as changing the more readable
max(a, b)
to the less readable (a > b ? a : b)
, to building a whole set of functions with one command, to changing the syntax of the programming language. In effect, macros are user-defined extensions to the compiler. In theory, you could build a complete compiler out of macros that expand your code into simpler code, more macros that expand that to assembly language, and more to turn that into machine language.Lisp is particularly well suited to macros because it has a very simple syntax, which makes it easy to parse, rearrange, and reassemble code. On the other hand, you lose the benefits of having a more complex syntax.
C and its closest relatives have a preprocessor with its own mini-language, including such commands as #define. Although powerful, you have to learn them and their pitfalls separately from the rest of the language.
Perl 5 doesn't have an easy way to make macros yet, although it can be done with Filter::Simple, and someone (inspired by On Lisp) has begun work on a Macro module. This is partly because Perl has a complex syntax, and partly because macros are hard to implement in a module if you aren't intimately familiar with the language and its compiler.
However, Perl 6 is going to have macros built right into the core language, so that macros are just special subroutines. (Down the page a bit.) From what I've read, this is going to be the least dangerous, most powerful implementation of macros since Lisp, which is a big achievement considering Perl's complex syntax. As an aside, Perl 6 is going to come with a built in grammar (collection of regexps) that parses Perl 6. This is a subject so cool that I'll have to devote a post to it sometime soon.
Java, as far as I know, doesn't have macros.