There's plenty of questions where you need to know what is and what is not legal Java involving all sorts of rules that might not ever come up when you code, because you know various things that are legal and never write code containing those mistakes.
If you overlook those errors on the code in the exam questions you will get enough questions wrong on the exam even if someone just asked you to "write code that does this" that you would be able to do so.
Someone could say "This is stupid and pointless" if they all resulted in compile failures, but there are plenty of things you could do wrong that would just result in logic bombs in your code, so I would argue that it isn't as pointless as it seems.
Material targeted towards exam preparation highlights many of these annoying little things.
Random ones I can think of:
public static void main() { } // will this compile? What will be the result of your run if that is the only main() method in your class?
Many things around "operator precedence" which would never come up if you just broke your computations up into more intermediate results or liberally used parentheses, but you have to say what the code will do as written.
Weird ways of writing array declarations...
Lots of tricky things about overloading versus overriding and some rules about both.
If a code snippet is numbered and starts with a line number higher than one
you should presume there were some lines omitted before that, if it starts at one you can presume they aren't leaving anything out from above...
Confusion about which mistakes will result in failed compiles and which will just result in infinite loops or runtime exceptions for certain data.
There's a lot of things, if you have some sense which things you lost a lot of points on it would help.
Also, if you look at exam prep materials and start seeing lots of stupid weird rules showing that code you would never naturally write are either actually illegal or legal that alone could get you more than enough "new" points to pass.
I am overly obsessed with those things in any other context, but when trying to ensure you pass one of these exams, you can't possibly remember too many "dumb rules about whether doing some weird thing is legal and just a bad idea or illegal and won't compile" I would say.
I will second the "Don't give up!!" message, because it seems like if you found just a few "Exam Tricks" you were missing, or a few "Stupid Java Rules" you were unaware of and ignoring, you'd get more than enough points to pass next time. There are skills that are needed that just don't get exercised when you write code "the way you always write it" and don't see the problems that you would actually see all the time if you did many code reviews at work, taught classes, or tried to answer questions in these forums.