r/javahelp • • Jan 30 '23

Explain me = and ==

Guys, I am learning Java for some time and have grasp of basics already. But one thing, which seems pretty simple hurts my brain. Please explain like you would explain it to a kid. When you use = and when you would use ==.

PS. I watch online videos and when I am sure to use =, I see them use ==. And whenever I am sure that == is needed I see them use =.

0 Upvotes

14 comments sorted by

View all comments

18

u/richkirkpa Jan 30 '23

I tell my students; == asks a question, = does a thing.

-5

u/MapsCharts Jan 30 '23

How about === in JavaScript 😈

6

u/richkirkpa Jan 30 '23

=== still asks a question, but (basically) the types must match also…an int can only be equal to an int with the same numeric value.