If you use GNU grep on text files, use the -a (--text) option
shoutout to [RipGrep](<a href="https://github.com/BurntSushi/ripgrep" rel="nofollow">https://github.com/BurntSushi/ripgrep</a>), which is generally faster, has more intelligent defaults (searches cwd by default, ignores files matching .gitignore), and can search through only certain text files (like your .java and .py files, say). Not affiliated, just found it worth the effort to learn some slightly different flags, though many are the same as normal grep.