#are objects' methods on the heap, or are they allocated in a special kind of memory?
467 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @flat cypress! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
for the second question; where else would they be?
oh i just wanna to be sure if i was using the term correctly
at first i thought the object's data was the whole class it was based on
including the methods
but methods are allocated differently, right?
yeah
"object's data" is something that each object has, but all objects of the same type share the same class things
everything in the class is shared between objects. the things that are unique to the objects are the values that the instance variables/fields/attributes/properties hold
constructors, methods, init blocks, all the static things, are shared
the variable declarations are shared, that part is in/of the class
but the variable values are not shared, that's what the data is
probably. i don't know, sorry.
phew that's a relief
i thought methods were part of the objects data lol
but it's stated that an object is on the heap so...
it wouldn't make any sense
unless it's possible for memory to contain other memory allocations
then that'd be... weird
dynamic memory holding stack memory
hm
i wonder if that's... possible
for an object
values are nouns, methods are verbs
suppose you have a bank account
the data would be "owner", "value", "cards", "loans", that sort of thing right?
"withdraw", "deposit", "transfer" aren't data of the account
oh now you're speaking my language
syntax tree
the only problem being the GODDAMN SEMANTICS AND PRAGMATICS
don't even get me started on phonology
thanks for the help
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
now i am sure that object's data refers to the variables themselves
and... fields too?
and whatever the constructor is up too
if it's using super() to do some shenanigans
same thing
nope
the actual data is the stuff inside the variables
i see
the constructor would be more of an instruction, right?
since it's always called when an object is instantiated
yes
"instance variable", "field", "attribute", and "property" all refer to the same thing in java
some might be different things in different languages but to java they're the same thing
cool
the term attributes are never used
you use instance variables instead, right?
hmm now i see the use of fields and instance variables
fields are dynamic within the object
but instance variables can be dynamically assigned values througout the program
so that'd be a way for you too...
oh
interesting
semantics!
like i said, they all refer to the same thing in java
they're all interchangeable within the context of java
i see
just like the terms instance and object
yeah
i need to learn the purpose of them now
is it a bad idea to learn the semantics of it with minecraft modding?
"field" has a focus on it being a class member
"instance variable" has a focus on it being the variable
etc
not at all, no
gonna save this
nice
i still need to learn the purpose of stack memory in making mods
like you said it's just like verbs
oh i see
method calls exist on the callstack
i have no idea what "methods return stack memory" means to you, that doesn't make sense
in my head it sounds just like temporary memory
so the returned value of a method is not on stack
that open more possibilities
if this is for making minecraft mods, these internals aren't significant to you
internals?
you aren't going to be managing memory manually in java
that's one of the selling points of java
oh, it's because i have this itch on me that makes me wanna learn about everything in the minimum details
i am wanna be aware of what's happening
learn about how to use the language first, rather than how the language works internally
i see
so the data that a method returns is not stack memory exactly?
you said callstack, but you were referring to the variables of the method?
sure, knowing everything about the language would be nice, but knowing internals without what they're for isn't going to be useful
it doesn't return memory
it returns values
ah gotcha
oh now i see why someone said it was stack memory
interesting
that's cool
it uses stack memory, it doesn't return it or anything like that
it's up to me to do whatever i want with the returned data
this makes a lot of sense
when you wanna use methods from a class, you need to refer to the object of that class to actually use them methods?
gosh now i am thinking it was a bad idea to start on python
i am gonna take a shower
in case i don't answer what you will type in a few minutes here
yes
noice
python's OOP is cursed, don't try to use it to equate to proper OOP languages lol
i really should have started on java
the fact that it was stated Everything in python is an object
this single statement corrupted my mind
gonna keep in mind that object = data structure on the heap
don't equate them
objects are stored on the heap
there's not really a proper reverse relation
it's 9am for me so yeha
i think i will be here playing with java for more hours
no problem
i need to see the methods thing you told me about
since it just returns values
does that mean it's up to me to do whatever i want with these values?
perhaps even assigning that value to an instance variable
nice
gonna take a look at that, object type methods and... fields
it gives the value and ceases to exist
and give a return value
and manage exception handling
but yes grouping statements is the primary objective of functions
object type methods expect an object as a returned value, right?
actually, a reference to that object
yes
the reference exists on the stack, pointing to an object on the heap
oh shit i need to keep that in mind
null is an all-zeros reference, similarly to how all the primitives have a 0-equivalent default value
Methods need to be called, they can't call themselves, dumbass
gonna put this on my monitor
lmao
methods are just functions in objects/classes
yeah
the fact that i can create a function without being in a class in python corrupted my mind too
java does have Function to simulate functions as first-class objects btw
it's part of the functions api, it's really extensive and really useful actually
you'll get there
alright, i will go take a shower and read some minecraft mods
simple mods that don't do much
like hmm ironchest perhaps
knowing what's done with methods data and instance variables is my primary focus now
thanks to your help, it's not a fog environment
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
if you get into minecraft mods right away, that'll involve integration as well
you may want to consider looking at more basic stuff just using built-ins if you want to focus on java first
hmm idk i think i will hop to modding
i always wanted to make mods since 2012
good old times
couldn't even install mods properly
walk before you run 
more like crawl before i walk
well i will go take a shower
thanks the for the help, again
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
@trail nimbus yo just to confirm again, object = object variables, right?
i hope my memory hasn't gone foggy
"object variable" isn't a thing
I think they mean variables, but type object, not primitive
yeap
i wanna be sure if my memory isn't failing me
An object is a new instance of a class hence the new keyword. Having an variable type object, doesn't make it an object .It just makes it a null variable
oh i mean, when you use the term object
it refers to the instance variables, right?
Yes, if I understand correctly
This is an object new ObjectClassType()
Did I answer?
Your not the only one 😂
i am not taking my adhd meds
problem is that my vitamin D levels are getting normalized
it makes me more energetic
makes adhd worse too
I feel you. I have ADHD and have to take meds, I don't want to, but have to do it
Talk to doctor?
i mean vitamin d
Or whatever those people are called that deal with meds
Ahh ok
Idk man. Can't help you much there
instead of my brain being at 1000 miles per hour it's 10000 miles per hour
it sucks
Yea
I once tried to make a Rainbow 7 Seige mod, but quickly gave up because I didn't feel like it
i see
oh now i get what you meant by object
XD
i need to see the constructor's shenanigans
appears every time in minecraft modding
Well, it is OOP for a reason
I love the super keyword. The super keyword and abstract classes are my fav. Really random, but oh well
ah these and methods that i need to take care of
only because of this post that i realised that object's data is only instance variables
not methods
god damn you python!
XD
minecraft mods are weird
Python corrupted me lmao
I should have went straight to the AP class instead of taking the intro (intro is requirement, but teacher said I could go to AP)
AP teaches Java.
But I have to go
darn in my software engineering course, they make us use a coding language that uses OUR language to type keywords
imagine the confusion
F
i just used chat gpt and procedded to study python
damn it's so cool i can understand this
methods are my next objective
where the hell are they called
I should go, but is that Static ABUSE??????
probably
the mod's author have a separated class for each iron chest material
i think it's because it's using fabric api
Ahh ok
no forge shenanigans
Now I REALLY have to goo
you have a good one
You too
those are reference types
no
i think i was talking about object's data rather than what an object is itself
gosh did i forget everything you told me
that would be the values held within the instance variables
but an "object" in concept is much more than its data
it's the data, the type, the methods, any other members
oh so it includes everything the class states
all the instance stuff, yeah
thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
amnesia moment
yeah, i had an itch as if something about what i learned was wrong
at least what i thought
relatable tbh
always a pain to go figure out what exactly you're forgetting yeah
i even had a dream about it
it was about object's data vs object
yeah i knew i had forgotten to ask something else but similar
there it is
@trail nimbus actually it's not memory
it could be my memory getting better
looks like vitamin d deficiency affects the brain more than i imagined
i am surprised this was not a torturing skepticism process
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
@trail nimbus yo chris remember that thing about using classes as parameters?
am i referring to the object of that class or a reference to that object?
because if it's the object directly
it will make a lot of sense with what i am messing with here
managed to make my creative tab on minecraft
now i need to mess up with classes
oh by the way are parameters positional?
....generics...?
if not, then no
nvm i think i got it
i just need to be sure of one little thing
since the parameter refers to an object that is on runtime
what if there are multiple instances of that object
that's not really a thing
which one will the parameter refer to
instance ≈ object, "multiple instance of object" just doesn't make sense
oh forgive me on that one
what i meant is what if there are multiple instances of a class during runtime
im going to have to come back to this, not too free rn
unless this one is special
np
i will be here doing some tests
doesn't matter, the instance that was passed is the instance that will be used
the method doesn't see all instances
hmm this must be some minecraft shenanigans
or the api
no instances are created in classes
just plain parameters
oh i think i got it
makes sense
when you come back i will tell ya
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
I may be late to the party but in case it hasn't been sorted out as far as I'm aware any object is stored on the heap including all its methods and variables and when you make a method call that instantiates an object you put a pointer in the stack and the object is still in the heap. (Local method primitives are put directly in the stack when the method is called though)
Objects don't contain methods. Classes do.
And while current day JVMs may indeed store classes and with them methods in the heap, the promise of Java is that where classes and methods are is none of the programmer's business. It is where the JVM finds it best to put it in.
If you want to understand heap/stack things better, I'd just write some mildly complex C/C++ code, and look at the assembly output. You'll naturally start figuring out when things are in the Stack/Heap.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
hmm that's weird, i read somewhere that objects do contain methods but they are related to the virtual machine
i got my eyes on these 2
i am loving java
and hating python
in my head it doesn't make sense for methods to be contained by classes since static methods exist
Static methods just means you don't need an instance to call it. That's about it.
yeah
i need to see more about methods
they are a bit weird
it's all about the virtual machine
but i think objects still contain them in some way
As a reflective object
gotta do some research
@feral ether are you sure methods belong to classes rather than objects? even if you need to refer to an object when calling its method?
let's go vyvanse is starting to kick in
methods belong to classes yes, that's where they're declared
you call the method via the object, but the method itself isn't on the object
otherwise you'd need another copy of the method for every object you create, and that'd get quite expensive
hmm i need to take a look at java docs to see what they say about it
this wouldn't be in javadocs
it's on oracle innit?
if anything it'd be in the spec but this is more of just general OOP structure/concepts
java docs describe the api (libraries), not the language
i see
it's because i found this https://docs.oracle.com/javase/tutorial/java/concepts/object.html
This beginner Java tutorial describes fundamentals of programming in the Java programming language
suspicious
ah those aren't docs, those are tutorials
they're just on the same subdomain as the actual docs but under a different slug
it's confusing but eh it works
oh so docs means something else
my bad
i thought it was something regarding to info
docs is short for documentation, it specifically refers to formal descriptions of interfaces
tutorials have a similar purpose but they're more human and less formal
i see
documentation is (or, well, should be) complete, while tutorials might omit stuff for brevity
this + other researches i made still make me think that objects still contain methods but they are a bit special
relating to the virtual machine
i know it's aboslutely weird for me to get into these little details
it's a curse i have to face
it happens for literally anything i learn
i think there's an issue with ambiguous language here, like what does it mean for something to "contain" a method here
yeah indeed
i even searched more about volatile and non-volatile memory
due to this
the actual definition and implementation of the method belong to the class, and an instance of that class can access those methods directly
but nothing of the method itself is stored on the object directly
no clue sorry
it generally doesn't matter for actual use and i tend to explore within the language rather than its underbelly so ive got no clue about this lol
because if objects somewhat contains methods it means that there would be a special allocation in ram that would relate to the java virtual machine since methods are converted into bytecode so they can operate their functions
my guts and skepticism attack again
i need to explore more of classes as well
I wouldn't worry about that so much. I'd assume that class methods are actually static functions in memory, and simply have an additional parameter appended that add a reference to the original Class.
The only issue you'd get is copying that class into new Threads so that multiple Threads can run the same function at the same time.
oh boy, this will be tough to forget
wish me luck
this will make me study computer engineering and physics as well
@feral ether do you mess with minecraft coding, if i may ask?
i am doing some stuff with fabric api
loving it so far
i just need a better comprehension of methods
i even made some rules myself
Nope. I do Web Development with Springboot.
that's cool
and on my list
in the future we will talk a lot about this
dude this is so weird
Just read Baeldung and Spring Docs. They're fantastic for learning, and your goal should be to get to the point to answer questions, not ask them.
i have no thoughts in my head
this is so uncommon
adhd breaks my legs so much
sorry i am just so glad i get to be relaxed at least once
so happy i need to share it
Hope you and That_Guy977... keep this conversation going. I have been following it from the beginning and have found the back n forth between you two very interesting not to mention how your genuine curiosity comes out in your questions. I find them very helpful as someone very new to Java.
oh yeah, that's nice to read
thanks mate
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
i always get bothered by these details
if i am learning a language i will explore phonology
@heady summit alright i have a theory
objects contain methods, but i don't mean containing data, rather, a way of indicating that these methods will be allocated in the virtual machine and then transformed into bytecode! this makes a lot of sense in my head, i am probably wrong, but it's interesting anyway
this would make a lot of sense of static methods
the point of static is so you don't load stuff every time innit?
this might be it
i mean i have seen lots of codes using static as a bridge
which's interesting
the point of static methods would be so you wouldn't need to create an object just for that method, meaning that you would still need an object to use the method due to memory allocation, that's cool!
less objects less allocations
perhaps C++ and C will have more of this
https://betterprogramming.pub/understanding-the-jvm-memory-model-heap-vs-non-heap-c14aa6fa703e This might help. Remember that we're dealing less with how Java behaves, and more with have the JVM is expected to behave.
does every single coding language have a virtual machine?
a specific allocation just for methods
oh i had the word at the tip of my tongue
Interpreted Languages will have a Runtime (or VM) of some sort. Java is both interpreted (Java Bytecode) and compiled (Java -> Java Bytecode)
C++ doesn't have delays
it goes straight up to the objective
yes interpreted and compiled
thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
ah btw when i said that an object contains methods
did it sound like i was referring to methods as data?
the usage of contain in java
not sure if it relates to data
that'd be awkward
Methods are meta-data on the class
alright let me rephrase everything: classes are non-volatile since there is no allocation on RAM, objects are the allocation of the instructions stated in classes, methods are allocated in the virtual machine, converted into bytecode and then processed afterwards. So I see "Object" as memory allocation. Objects don't contain methods as data, rather, it's an indication that these methods will be allocated, unlike static methods. Static methods are used mostly when you want to use a method stated in a different class without having to instantiate that class first in order to make it get allocated. In the end, you'd be calling a method without the need of instantiating the origin class, optimizing the whole allocation process.
so proud i made this text
Read the article I posted, and the JEPs it links. That will help.
Anytime Java is run it is always bytecode. There is no converting to Bytecode in the JVM (Traditionally).
All Bytecode/Metadata is loaded into RAM once the Application begins. The JVM manages its own Heaps in that regard.
alright, just wanted to post my text, it's from a thread
No worries
You're trying to think of Java as a C/C++ language with Stacks/Heaps, when in reality Java is just a Runtime. Think of how a runtime would behave, instead of a Native Application.
idk it's just my curiosity out of hand
@feral ether i took a good read on the article, it's really interesting
correct me if i am wrong. in interpretated languages, such as python, the heap memory would be a bit different wouldn't it?
more limited
with python using a lot of garbage collector of unnused objects
Heap Memory is just a term of a large chunk of semi-organized memory. Heaps can be different within languages.
Java is also Garbage Collected
@feral ether oh NICE! the article confirmed an idea i had in mind
this is really cool
i wonder why people don't care much about memory allocation
tldr:
all methods, field declarations, etc are shared across instances and only exist once in memory, but the values in the instance fields are individually stored for each instance. the nonstatic methods then get that instance, which they can use to do what they want to do. a class with a field “text” and a method “print” that prints out the text variable will only store the print method once in memory, but when you call the print method, that instance with the individual text value will be passed to it, and it will print it
question; with JIT, would it be like there's an extra layer between the code and the vm, where that layer is doing the compilation and feeding the bytecode to the vm?
it's a very specialized topic nowadays, it's not very important to general use of most languages because the language handles it and you just have to tell it to do things
it is still important for language design/architecture, or lower level things like assembly or embedded systems
if you aren't super into it, the conversation just kinda stops at "garbage collection" or "reference counting"
for java, I believe unsafe is pretty much the only use-case of manual memory management I know of
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
From my understanding it's the inverse, the VM feeds the byte code into the JIT to compile it. It's weird because the JVM/JIT are pretty intertwined in the docs, so I'd have to read some source code to really get a grasp of it.
If you're talking about the Unsafe class, that really is not part of the Java Spec, and is more a hacky workaround that power users/frameworks can leverage. I don't even know if it is available in Java 17, and I think you have to use the security manager to get it in 11.
Manual Memory Management is mostly done through JNI/JNA, with the Foreign Function/Foreign Memory JEPs targeting future versions of Java.
