Hey John! I do not leave comments often, so this is a special event. I am currently learning Java at university and at home, and I wanted to tell you how much your videos are helping me. Your simple way of teaching is amazing for new learners, and I find your channel criminally underrated. Keep on uploading, Im sure youll get big on KZbin, a 100%!
@CodingWithJohn3 жыл бұрын
Thanks a ton! I'll keep working on it, glad it's helping you!
@cagan82 жыл бұрын
Was going to say the same, usually programming videos are either boring or not engaging and taught well. This is completely opposite, very clear and understandable. Thank you
@alexwatts13752 жыл бұрын
The best creators bubble to the top!
@snowwhite21462 жыл бұрын
@@CodingWithJohn Same here. I have a Java exam in June and your videos are a good revision for me. Many thanks.
@csgrinds2 жыл бұрын
Recommend if you're serious about mastering Java that you read e.g. Joshua Bloch rather than watching needlessly long youtube presentations. No criticism of this video intended.
@mohitsanghai54552 жыл бұрын
Thanks a lot for the crisp and clear video, John. Just to summarize String Immutability Benefits - 1) Usage of String pool, saving tons of memory and hashCode calculation 2) safe for multithreading 3) Removes any security threat by not allowing hackers to change referenced string values to cause security issues in the application
@bobfarker4001 Жыл бұрын
You basically summarized the summary.
@Atarian65027 ай бұрын
Thanks for summary. Question regarding #1: Do I understand this correctly: the String pool saves the memory ONLY if you have two or more identical string variables (they point to the same piece of memory), but it wastes memory EVERY time you are changing the strings (it uses new piece of memory for the whole new string even if you change only one letter)?
@MrYourSalvation2 жыл бұрын
Plus one interesting thing - due to String's immutability and presense of a string pool - the hashCode() method is calculated only the first time and saved as a value inside String object. Therefore when you call hashCode() method second time (e.g. on another variable with the same literal value) - it will just return stored value, no need to calculate hash code again.
@finmonster58272 жыл бұрын
ґалічєнин
@annaburdanova83072 жыл бұрын
Yura, thank you for sharing this interesting fact, the video itself and the comments are a real treasure for a Java learner!
@fabio.1 Жыл бұрын
👍
@CodingWithJohn8 ай бұрын
Really cool!
@NuanDaa2 жыл бұрын
Dude I’m in bootcamp now for 6 months and no coding background. I just watched your video and I can say you have a best teaching technique that super understandable. You just got a subscriber. Thanks.
@AdrianWP_TАй бұрын
I watched your videos countless times while doing my online courses. (I got my degree in 2005 in mechanical engineering but made a serious career change this year) Now, years down the line I'm sitting as an intern as a junior software developer (at age 42), and just watched yet another video. Your explanations are crystal clear. Thanks for the effort in creating them - much appreciated.
@alexz40062 жыл бұрын
I always had a question about this topic. I read in a book about java, that strings were immutable, but it never went so much into detail. This is a very good video. Thanks for sharing.
@jiro.nemo.12 жыл бұрын
Ive been using Java as a student for nearly 5 years now, and your content has been completely mind-blowing to me. Made me adopt the "I know nothing" attitude and relearn everything.
@edwardthng25022 ай бұрын
Im literally studying for AP CS and i couldnt understand why a new string would give a false output, until I came across your video. Your a lifesaver.
@rahulshetty93352 жыл бұрын
Never even used Java a lot but I have been asked this question in interview. But this is the first time I understood what I was telling the interviewer.
@Hufsa2 жыл бұрын
first time in this channel and it's absolutely great to dedicate a specific video to talk only about immutable objects in less than 10 minutes, perfectly clear!
@LeninMcDonalds2 ай бұрын
John you have a gift for teaching. Only a Java master can explain the basics with such clarity to newbies.
@praveen123ist2 жыл бұрын
I think I'll never look back again at why string is immutable, you made it super clear 👌🙏 awesome!!!!
@zishanamin36072 жыл бұрын
Protect this man at all costs. Best explanations on Java concepts on the internet
@abolfazlsaravani22142 жыл бұрын
God I love Java, after 5 years of Java programming, I still love how it works.
@matthewharrison39212 жыл бұрын
You have a talent for explaining things in a concise and easy to process manner. Thank you, sir!
@CodingWithGhostInCode2 жыл бұрын
I thought I had a firm grasp of what it means when they say Strings are immutable. After watching this video, Everything i thought i knew went straight outta the window. Thanks John. Way to make things understandable.
@Veganzza Жыл бұрын
Man, you are so amazing. I've read many guides about immutable string but none of them is as clear as your explanation
@misspotato8132 жыл бұрын
I'm self teaching Java currently, I have a lot of questions about the "whys" and "hows" but currently the JavaDocs are a bit too advanced for me. This really helped!
@Rational_Human12 жыл бұрын
@@jake9854 which dark age r u living in ?
@Fadhelalmalki4 ай бұрын
I can swear this man is really a man and know how I think giving the needed answer
@codingweb39042 жыл бұрын
Knew all this but still his way of explaining held me till the end.... His way of teaching is just amazing
@swapode2 жыл бұрын
I think you're kinda missing the main reason why Strings are immutable: You can't really have sensible mutable Strings since you can't change their length without moving everything to newly allocated memory on the heap which is incredibly expensive. I absolutely see your points as benefits, in fact I think Rust has proven that the whole mutable by default approach is a mistake, but it might have been a good idea to go into the actual reason a bit.
@XD-nj7bc2 жыл бұрын
I can think of multiple ways that you can change your String length during runtime without coping (at least most of the time). Lists, Allocating more than cou need and and only get new memory when you run out.
@watertrainer39922 жыл бұрын
@@XD-nj7bc allocating more than you need doesn't really solve the problem though, as you'd then just use more than you need, making it more expensive than immutable Strings
@XD-nj7bc2 жыл бұрын
@@watertrainer3992 of course it is not cheaper than not mutable strings but you can then change the size without the copying he mentionend.
@swapode2 жыл бұрын
@@XD-nj7bc I put the word "sensible" in there for a reason 🙂
@garybuttherissilent58962 жыл бұрын
@@XD-nj7bc yeah he put the word "sensible" in there for a reason bruh
@learnjavaprogramming71322 жыл бұрын
I don't have a words John sir, you are a real teacher I've ever seen , iam very lucky becouse of i found your vedio ☺️☺️
@matthewmoore13072 жыл бұрын
I love how you’re drawing out with examples as you explain
@drewbruggman2 жыл бұрын
There was an error i was dealing with ages ago that i couldn't figure out and this video made that error make perfect sense, thank you!
@wedifilipoprogrammers10732 жыл бұрын
I always procrastinated to search about strings being immutable and here its recommended by KZbin
@JessePoage2 жыл бұрын
Again, thank you for explaining concepts better than most professors
@perox19822 жыл бұрын
Now Everything has sence. I know many teachers that needs THIS VIDEOS. You Rocks John.
@jayskieeee2 жыл бұрын
i wasn't aware of the benefits of immutability, even though i knew exactly what immutability means. thanks for the tid bits!
@THE16THPHANTOM2 жыл бұрын
the coolest thing about the immutable part(to me) is the multiple thread point. i have come to appreciate that after so many times i have replicated that fact for my objects while trying to avoid the synchronized keyword.
@emekaukwuoma33593 жыл бұрын
Learnt a whole lot about string immutability in 7minutes than I have in a year. Lol. Nice one
@anluong81032 жыл бұрын
Thanks so much. I've just come up with an interview question about this subject this morning. Luckily I watched your video the night before :)
@haoshecn2 жыл бұрын
Hi, John. Love your tutorials, but I think there is a little thing you didn’t explain in details here. When you new a string “John”, the object is indeed created in the heap, but “John” is still crated inside string pool. There is a reference inside the object pointing towards “John”. So, you actually created two objects when you use ‘new’ keyword to create a string.
@idkidkidk33333 жыл бұрын
Thank you! I will for sure be checking out more of your videos. You explained everything very clearly!
@drewbhardwaj2 жыл бұрын
probably the best teacher for coding.🙏🙏
@SuprousOxide2 жыл бұрын
Strings are also very commonly used as keys in Map collections. If you insert a value in a map with a key, and then change the key object , you will no longer be able to look up that value with the original key. And with some map types,may have trouble looking up other keys because you have a key stored in the wrong place.
@wamikgildiev6632 Жыл бұрын
When you add a value to a map you specify a key (a String in our case). A key is not an object, it's just a pointer to String object in memory. That String object is used to compute a hash code, and to find a bucket index later. So the question is Does Hashmap store a pointer to that String object and why if it already has computed the hash code? I could use Integer or any other class as HashMap key, but they are final.
@SuprousOxide Жыл бұрын
@@wamikgildiev6632 It needs to keep a the actual key around, not just the hash code, because of hash collisions. If two keys have the same hash-code, you need to compare the actual key values to tell which (if either) is pointing at the value you want. If you actually make a copy of the key when you insert it, that would probably work, but I think most implementations assume your key is immutable.
@hagnap2 жыл бұрын
Such a simple topic explained so well, wish they explained it like this in my early CS courses
@sourav544910 ай бұрын
This is the best explanation of Immutability on youtube You are a gem 💎
@BlackHazama2 жыл бұрын
Never fully understood why strings were immutable or the reason behind them. Thank you!
@rajivseeparsad60052 жыл бұрын
The best video to understand why String literals are immutable
@swastikmohapatra46652 жыл бұрын
i have to say i learn something new every day via this channel .
@hanikhellafi48722 жыл бұрын
Man I just discovered your channel and I find your content amazing. This is the kind of depth I was looking for regarding string immutability.
@nothappyz2 жыл бұрын
Worked with java for years, and never knew the pool thing. Amazing
@sb-zn4um2 жыл бұрын
finally an understanding of why .equals was always preferential over ==
@maresolaris2 жыл бұрын
Finally! I finally understand what immutable actually means. Thank you for this clear explanation.
@dmitriirodionov2 жыл бұрын
Outstanding and easy to understand explanation! Thank you for this video!
@supun_sandaruwan2 жыл бұрын
you are the best java teacher that i saw on the youtube because you are cleary explain what is the behind theory thank you very much 🤩💖
@marciomartins41112 жыл бұрын
I am a brazilian developer. I see your videos to strudy English. Thank you.
@ragore79472 жыл бұрын
John, you are [ immutably ] awesome!
@ChaseDetrick Жыл бұрын
This was fantastic, thank you so much! I've been struggling a lot in my comp sci classes because the professor refuses to go over theory, so this is wonderful :) You've won a very very faithful subscriber haha.
@billwu73672 жыл бұрын
you are the best programmer combining teacher as i ever met!support!
@rajeshchattopadhyaya28052 жыл бұрын
I am currently learning Java your videos give deeper understanding of Java thank you very much!
@rhitamdutta19962 жыл бұрын
Holy shit the way you explain things is so simple and lucid, subbed!!!
@mohitjaiswal35262 жыл бұрын
Now , I really understand . Why Java Strings are Immutable? Thank you John Sir
@arshandubey2 жыл бұрын
To the point , Every bit of information provided in just 7 minutes. SUBSCRIBED !!!
@MIchaelArlowe2 жыл бұрын
One of the saner innovations given to us by Java.
@Pythonology Жыл бұрын
oh man, great explanation! So, that is why it is better to use .equals() instead of == when comparing Strings.
@pgm20042 жыл бұрын
this man really out here saving my grades. god BLESS
@abhiniveshl676 Жыл бұрын
Crisp and clear
@pkmishra23592 жыл бұрын
Thanks john , finally I understand why Strings are immutable .
@h-girlradio46992 жыл бұрын
Thank you so much for explaining this!! I never truly got a grasp on what was meant by Strings being immutable but you explained it perfectly!!
@simonjunior1843 жыл бұрын
Very helpful demonstration of the concept. I hardly found other videos confusing to understand. Keep up the great job bro!
@herrbonk36352 жыл бұрын
But you find this one confusing to understand??
@simonjunior1842 жыл бұрын
@@herrbonk3635 I found this one very clear and straight forward to understand. I went through the video along coding on my IDE.
@herrbonk36352 жыл бұрын
@@simonjunior184 Like most other videos then? (You said you hardly found them confusing, which means that you don't find them confusing.)
@ronniesuvillian48932 жыл бұрын
WOWW!! I am a C++ Developer and i dont even know java, but this discussion was really interesting. Thanks for the information John!!
@amaanmohammad11902 жыл бұрын
Simple Concise and to the point.
@mirzaaqeel2 жыл бұрын
Crystal clear with examples. Hats off to you.
@TG-ri3mu3 жыл бұрын
Wow, wow, wow, FINALLY the explanation of immutable strings that l was looking for sooo long time! THANK YOU!
@jvsnyc3 жыл бұрын
I always do the Trifecta, except that I am already Subscribed. One Very Important thing about String, or anything else being immutable, is that it makes such an object an ideal key for a HashMap or TreeMap (okay, basically any Map) or as a member of a HashSet or TreeSet (okay, basically any kind of Set). This is because if something is mutable, and you use it as a key in a Map or as a member of a Set, and then someone goes ahead and changes its value, there is nothing in Java that magically goes and moves things around to make any and every Map or Set it would be found in to be "corrected". What you have instead is a broken Set or Map which will just yield incredibly confusing, crazy-pills behavior. So yeah, saves some space, yeah, makes threads safer, but also makes it safe as a key for a Map or as a Set member. This goes way beyond String to apply to "Why would I make anything immutable, I like to change things?" but String is quite an excellent introduction to this notion. Of course, when you are changing String-like things a lot, or building them up in pieces, StringBuilder can be your best friend. But that is another video.
@ЛёхаБодунов-б7ж2 жыл бұрын
Yesterday I had this question in my mind and today I saw this video. Thanks!
@thunderstruck27272 жыл бұрын
Love your concise, clear, and informative videos! I normally try to read Oracle Tutorial Trails, but these videos are faster on certain topics. Plus you include great examples. Thank you!
@CodingWithJohn2 жыл бұрын
Those are good too (as they should be, coming directly from Oracle) and I've used them to do some research on various topics I've done videos for. But yeah, often it's easier to watch a video on it. Thanks!
@thunderstruck27272 жыл бұрын
@@CodingWithJohn thanks for the reply! I’m a Comp Sci graduate who just finished my first year working a software job.
@fantasy9960 Жыл бұрын
Wow, this is the best explanation I can find on youtube! thank you john
@TechSY7302 жыл бұрын
Another benefit of immutable Strings, they allow implementation to really mess around with the internals transparently for performance. For example, in OpenJDK 8 and up, you can turn on a feature that will look at String instances with the same value, and point their backing char[] arrays (or byte[] arrays in OpenJDK 9 and up) to the same array (currently done by the garbage collector, not doing this all the time, so it doesn't waste time with short lived String instances). This wouldn't be safe if Strings were mutable, as then you would start tying unrelated String instances together when modifying. BTW: The command line parameter to turn this on is -XX:+UseStringDeduplication Sure, the String object itself must remain a different instance per the specification of "new", but now they point to the same array, thus taking up almost a little memory as if there was one. In this example, once the String instance pointed to by aThirdName lives long enough, it will get its backing array switched to the array used by the String in the string pool.
@huseyinkadioglu Жыл бұрын
Simple and clear explanation John. I appreciate your work and effort. Amazing stuff!
@StobbeTime2 жыл бұрын
Your an awesome teacher! I remember studying this topic in my book and could not understand it till now. Thanks.
@CuriousCyclist2 жыл бұрын
Thank you for taking the time to make this video. I have liked, subscribed and am commenting. Cheers!
@prajwaltirpude85822 жыл бұрын
Great video. It is so clear now and books never explain it such great way
@Bersling2 жыл бұрын
just completing the trifecta: yay, somebody does cool java videos about interesting topics in 2021 - subscribed!
@jayeshgautam71012 жыл бұрын
Well, finally my confusion is gone. Thank you sir.
@alexandrprodan87942 жыл бұрын
Wow, it's great video! Informative, comprehensive and not boring. Thank you very much!
@hannahdlh12 жыл бұрын
The best explanation for this topic that I've seen so far. Thank you!!
@JustinBieberFanSA Жыл бұрын
John, I love your videos. Thank you. Studying for the OCA at the moment and you explain these concepts so well that I do not need to study them after watching the video. I understand it, which means I remember it forever because I understand how it works. I really appreciate your help!
@suneetlimkar2 жыл бұрын
Love how the KZbin recommendations algo work.glad i came across this video.. so well explained.. thank you
@teaadvice49962 жыл бұрын
John I am so thankful for your existence
@codyprevatt6 ай бұрын
You explain things extremely well.
@Ali-cf5lm2 жыл бұрын
Thank you John.. That was the best explanation for understanding what immutable means
@sergokovaltsov34272 жыл бұрын
Good to mention that String Pool in Java in fact is an implementation of Flyweight Pattern so anyone could do same cool stuff
@vasundharachintha5037 Жыл бұрын
Your videos are amazing!!You really do make the concepts clear!!Thanks for such an amazing content.
@eiyukabe2 жыл бұрын
Excellent video, and clearly explained.
@YT-vx9sz Жыл бұрын
My fucking god can't believe somebody actually taught this so clearly
@ThePorpoisepower2 жыл бұрын
I doubt there's a significant amount of memory saving in using the string pool, I mean how often are you going to have 3-4 copies of the same string, or maybe 2 copies of a significantly long string... And I'd have performance concerns about checking the pool whenever you create a new string, however you can easily recover that lost performance in when comparing two memory addresses vs the values in those memory locations. The other advantages brought up in the video are also very good reasons.
@rastkostajic55258 ай бұрын
Man! This is a mind blowing info for me. Never thought about this before! Thanks.
@tiagosilva97955 ай бұрын
What a great explanation! Thanks John!
@1dagmawi3 жыл бұрын
You are easy to understand and always to the point. Glad I found you. Keep up the good work. Cheers.
@manojbhat14402 жыл бұрын
I was getting recommendation for one week but i didn't watch .Today i got the same question in the exam😭😭
@arbchowdary8322 жыл бұрын
Save memory by using string pool. Provide security. And multi threading
@Jakypbekovich Жыл бұрын
Trifecta is done! Very well explained, thank you!
@CodingWithJohn Жыл бұрын
Thanks much!
@knockknockyoo58122 жыл бұрын
His videos must-watch for junior developer
@bonnydavis6730 Жыл бұрын
Beautifully explained. Very informative . Thank you !!
@DragonKlavier2 жыл бұрын
Omg. I just discovered this magnifique Chanel to really learn Java.... thanks!!!!
@Coccoutube2 жыл бұрын
Excellent lesson John! I'm learning a lot with you :)
@SSHHoneypot2 жыл бұрын
I knew that this exists, but I never understood why. Now I do. Thanks :)))
@ishan2k12 жыл бұрын
This is great, tbh I learnt this in school but in a very crude manner and I wanted to see a simpler way to explain things! It’s also a very good starting point for heap and stack memories