Your code calculates the sum of the even Fibonacci numbers in the first N Fibonacci numbers
. This is not the same as calculating the sum of the even Fibonacci numbers smaller than N
Fibonacci number is approximately 1083,590
. This is larger than any built-in type in Java (or any other language I'm aware of).
Check the condition of your loop; it should be something like:
while (b < n)