Whenever I read a question like this I really love to cite some basic rule I've read on the internet years ago (and it's still true):
The client is in the hands of the enemy.
So whatever you do: If you think players might change it to cheat, don't provide that part of the code in the first place. While code obfuscation might be a tiny step towards this goal, it's usually futile, because there are even modern tools to deobfuscate code. Picking a different language that is harder to disassemble (like C++ over Java) might be a even bigger (and significantly more effective) step, although not perfect either.
There's no perfect protection, no matter what you do, except taking the code to be protected from the client and moving it server side (assuming that's possible). Otherwise there will always be people putting hours or even days of work into getting some cheats to work, even if it's just some pointless tapping marathon on mobile with a high-score table.
So, if possible, change your game design to respect the quote mentioned above:
Never ever allow any clients to dictate something on the server.
If the client claims to shoot, let the server check, whether that
player is actually allowed to shoot. If so, let him do it. Same goes
for movement or pretty much every other "move". To reduce lag,
clients might show feedback instantly (shooting animation, movement,
etc.) but the server must always have absolute power and be able to
correct any abnormalities (often seen and named as "rubberbanding" in
online games).
If you don't have a strict server/client separation (like peer-to-peer matchmaking), either elect one host temporary or let peers vote over important events (might be complicated).
For example, when voting for the next map, all peers count the votes and the majority will determine the winning vote. If 4 out of 5 peers say "map 1" is next, but one peer claims "map 2", you know who's manipulated or simply lieing. In a similar way you could ensure checksums of scripts and similar, but this may be open for manipulation once again.
Never tell clients/peers things they don't have to know. Imagine a stealth game. If one player has a modified client, he might be able to see all enemies all the time, ignoring their "stealth" flag. However, a cheat like this won't work, if his client won't get any information about players unless they're actually visible.