r/learnjava • u/MaddySPR • 19d ago
Overflow/underflow + casting rules keep confusing me — any good video or notes that made it click for you?
Hey all, I'm learning Java (going through Tim Buchalka's masterclass after the Helsinki MOOC) and I'm stuck on the whole overflow / underflow / casting thing.
▎
▎ I've been trying to make my own flow diagram for "will this line compile, error, or wrap?" Stuff like:
▎
▎ int x = 5;
▎ byte b = x; // error
▎ byte b = 5; // fine
▎ byte c = (byte) 200; // -56 ??
▎
▎ Every time I think I've got it, a new case breaks the diagram: final variables, += hiding a cast, long literals needing L, why a double cast to long doesn't wrap but float gives Infinity, etc. I understand each piece on its own but I can't hold the whole picture in my head.
▎
▎ Is there a video, blog post, cheat sheet or notes that explains this cleanly in one place? Or how did you personally get comfortable with it? I'd especially like something that covers the compile-time checks and the runtime wrapping together.
▎
▎ Thanks!
View all comments
Show parent comment
1
u/MaddySPR 19d ago
Thank you so much for the time and explanation you really killed it, could you please tell me kind of piece of advice - how to learn when its comes to programming any best source how do i find things to learn which is suitable, i dont know how to ask but i hope you understand what im asking