REFERENCE vs VALUE TYPES - JAVA

Published: 31 January 2021
on channel: The Sukhdev
100
3

*** CORRECTION: on 1:20 of the video, it incorrectly states that String foo = "foo" is equivalent to:
String foo = new String("foo")
... this is not really true. In fact, it's also misleading to say that Strings are stored in the heap - they are actually stored in a specific place in the heap: "The String Pool". The 'new' keyword will create an object in the heap that references the string in the pool (or create one if it doesn't already exist). Creating a string without using the 'new' keyword will NOT create an additional string object in the heap; it will simply point to the string in the string pool or add it to the pool if it doesn't already exist. This is why "foo" == "foo" will be true (both point to the same string in the pool) and new String("foo") == "foo" will be false (the left part of the expression references an object in the heap, which then references the string in the pool BUT '==' checks for reference, NOT for value). ***

NOTE: a stack is a linear data structure with a particular order in which the operations are performed: first-in, last-out. Also, elements in the stack are encapsulated in frames. To learn more about the role of frames in the stack : https://stackoverflow.com/questions/1...


On this page of the site you can watch the video online REFERENCE vs VALUE TYPES - JAVA with a duration of hours minute second in good quality, which was uploaded by the user The Sukhdev 31 January 2021, share the link with friends and acquaintances, this video has already been watched 100 times on youtube and it was liked by 3 viewers. Enjoy your viewing!