In git 1.9.0 the “magic word” exclude was added to pathspecs. So if you want to search for foobar in every file except for those matching *.java you can do:
git grep foobar -- ':(exclude)*.java'
Or using the ! “short form” for exclude:
git grep foobar -- ':!*.java'
Note that in git versions up to v2.12, when using an exclude pathspec, you must have at least one “inclusive” pathspec. In the above examples you’d want to add ./* (recursively include everything under the current directory) somewhere after the -- as well. In git v2.13 this restriction was lifted and git grep foobar -- ':!*.java' works without the ./*.
There’s a good reference for all the “magic words” allowed in a pathspec at git-scm.com (or just git help glossary).