Beyond Compare's filename filters can include path information or complete filenames; they're not limited to just extensions. From the File Masks topic in the help:
Relative file masks affect files or folders in specific locations.
p\f
f must be in folder p.
.\f
f must be in the base folder.
...\f
f may have zero or more parent folders.
Examples:
Windows\*.txt
affects any text file in any included folder named Windows.
...\Windows\*.txt
affects any text file in any folder named Windows.
.\Windows\*.txt
affects any text file in a folder named Windows that is in the base folder.
For your specific example, you can use c/d/foo.java
just like you wrote it.