Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@rutee07 Java is cancerous but if you want to have a CS degree you need to know at least the basic of it
-
Java passes you the value for primitive data types like int (or integer? Can't remember), bool, byte etc. All the types that are lowercase and predefined.
For everything that is stored on the heap (Obiects, Strings (not a primitive), Array, etc.) it passes you a reference.
Note that Integer is not a primitive data type. Instance of Integer are objects (so reference) store an int that is usually unboxed and boxed again on the fly. There is also a fancy word for it that I forgot. -
No it doesn't pass Only by Value, but instead @OnlyBytes .
Jokes aside, like @OnlyBytes said, don't confuse your head -
Well, if objects were passed by value you couldn't pass it to a function and let that function change that object (edit: and expect to work with the modified object after the method call), right? You'd have to return a new object or use some kind of special notation to explicitly pass a reference. It's pretty intuitive if you think about how it works in practice and what the implications are 👍
-
@irene That's true. Is it wrong of me to make a distinction between "value types" and "reference types", even though both are passed by value? I'm curious, since this is a bit out of my comfort zone.
-
@ihatecomputers That is not my point. Yes, you can pass an object's reference and change the value of the object. But the reference itself is passed by value
-
@ihatecomputers I spent a little time reading the java language specification. I think I figured out something about the data accessing mechanism of java but I still don't get the exact detail :D please help me
-
@AI-Overlord lol I'm just as confused as you are.
Man, computers are a piece of shit. They are just too complex and there's one million ways that stuff can fail, it's like you're staring into the tesseract at the end of Interstellar but it's made out of 1's and 0's.
You know when someone reported a bug for the first time like three years ago and it keeps happening but no one has been able to replicate it, but you have evidence of it occurring? Goddamnit, I hate computers. -
devTea240886y@AI-Overlord not really most cs degress now interested in data science so either R should python should be preferred. If you want to build a software then yeah, learning OOP is required
-
Zenq26yJava passes by value.
But in case of objects and String it passes object' or String memory address location. Though technically it still passes by value the location but when used you will end in using that object.
So people say it passes object by reference. -
Java always passes by value. For primitives that value is the primitive value. For any object that value is a reference to that object [NOT a copy of the object. Just a ref]
Related Rants
Since I have learned Java I was taught that Java only passes by value. But my Uni Professor discusses that Java is passed by reference for object and string. I am really confused right now and need some advice.
question
java