There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
so they designed the language to not use it.
Punit Jain wrote:although pointer directly refer to address so they are much faster
Punit Jain wrote:well, if i point to any value, than it will go to that address, but if i point directly to the address, it has no need to go to address so it makes faster, i believe.
please correct me if i m wrong..
C uses null-terminated Strings, so access to the ith character takes linear complexity. Java™ uses array-based Strings, so access to the ith character runs in constant time.Punit Jain wrote:. . . pointer directly refer to address so they are much faster, . . .
Java references contain (point to) an address
Punit Jain wrote:okay but although wrappers refer to address, but also they stored in heap, whereas primitives stored in stack, so accessing primitives is faster, i think, but again wrappers refer to address so they should be faster??
Campbell Ritchie wrote:You should beware of simply googling; people can post misinformation, or simply be mistaken themselves.
With few exceptions, objects live on the heap. Many primitives are fields of objects, so they live inside the objects on the heap.
Local variables and method arguments usually live on the stack; these might be primitives, in which case their actual value is stored there, or reference types, in which case the reference to their memory location is passed.
With few exceptions
Punit Jain wrote:
With few exceptions
what type of exceptions are they??
Punit Jain wrote:okay...but it creates a question in my mind??
where primitives are stored and where objects actually??
and do we have direct access to them??
All local variables are still on the stack, and most objects are still on the heap, but some short-lived objects may be on the stack, though we probably wouldn't in general be able to predict which ones.
Jeff Verdegan wrote:Up to Java 6...all objects are stored on the heap (including all member variables--static, non-static, primitive, and reference). Simple and tidy.
Praveen Kumar M K wrote:
Jeff Verdegan wrote:Up to Java 6...all objects are stored on the heap (including all member variables--static, non-static, primitive, and reference). Simple and tidy.
Need a little clarification here. When you refer to static member variables, you mean that these static variables are stored in the Class object of that class right?
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|