ArrayList: "I'm fast at adding elements!" John: "But you did not add of them in multithread call" ArrayList: "I said I'm fast, not correct"
@monishbiswas1966 Жыл бұрын
Well they realised that synchronising things by default was a bad design choice as A) there was a performance cost to synchronisation as it stops the JVM fro m doing certain optimisations, and users should not may the cost of hey are notneeding concurrent access. B) if concurrency was required, you would probably need to synchronise the calling code anyway, to allow read and modify ops to be atomic, so no point syncronsing the list operations. You can see this in stringBuilder vs StringBuffer
@neealdon2-g6j Жыл бұрын
That makes sense.
@haltsmaul. Жыл бұрын
By the way, you can add underscores to number literals to make them more readable: int size = 1_000_000;
@ManosSef Жыл бұрын
I never knew that and it looks so weird lol
@v0xl Жыл бұрын
jusr like in rust and js
@xyvadimxy Жыл бұрын
@@v0xl and python :)
@yankobzykant5579 Жыл бұрын
It works only with Java 11 and newer, but yeah you can.
@nuclear.prometheus Жыл бұрын
You can do 1e6 too
@chpsilva Жыл бұрын
I started working with Java back in 2001 and one of the first things I learned was Vectors were a big no-no, but nobody bothered to explain why. Many years later you showed us the reasons, so thanks!
@micleh Жыл бұрын
I've been longing for you to publish a new video, and each time I'm fascinated by them regarding presentation technique, confidence and knowledge gain. This video - among all others you've produced - will be added to the "interesting video list" of my computer science class here in Germany. Thanks for making these kinds of videos.
@siomarapantarotto Жыл бұрын
I ❤coding with you John! I coded with Vector and then migrated to ArrayList, I knew about thread safe, but only in theory. Your class was fantastic for me to understand how this works in practice. Congratulations.
@stephanieezat-panah7750 Жыл бұрын
I used vectors in C++ for years. I had no idea that Java had vectors. I shall continue using ArrayLists, as you instructed us. Thank you, Coding With John. Awesome explanation and demonstration, as always.
@ayankhanra7910 Жыл бұрын
no way anyone goes emptyhanded from your videos ,there is always something to learn in deep.. thanks teacher.....
@PauxloE Жыл бұрын
For the benachmarking, I'd keep the `new Thread` part outside of the timing - just time from before the starts to after the joins.
@KT-tc9jr Жыл бұрын
I want to buy your course but I have been with Java for some time now. Thus, I would 100% be buying your Advanced Java course which includes advanced contents just like how you do it in this Channel.
@RustysAdventures Жыл бұрын
Such an interesting video. I've used Vector in C++ but never knew it existed in Java too. Your videos are always so educational
@soniablanche5672 Жыл бұрын
C++ Vector = ArrayList in Java
@yuriytheone Жыл бұрын
The Power of C++ you can write any realization you need both threadsafe and none... With or without buffering and so on...
@gamerzero6085 Жыл бұрын
@@yuriytheone Yeah you can do all of that in Java too. Your point?
@monishbiswas1966 Жыл бұрын
I think they modelled the early Java on C++, which is why they used the same names. However they made a design error in making vector synchronised as you pay a high cost to it being synchronised, and also most ops require synchronisation at a higher level. They could not fix the design errors without breaking backward compatibility, so they created ArrayList instead
@zeeshannaqvi4091 Жыл бұрын
Hi John I really appreciate the effort you put into explaining Java topics with such simplicity. The first video I watched was on Optionals and it finally made sense why they were introduced in the first place. Can you please make a video on Java Functional Interface, Consumer, Predicate and Supplier?
@raggstukov6 ай бұрын
Great video, in my case for some reason the Vector was faster than the ArrayList form some reason!! But now I know how to use them! Great video thanks.
@casperes0912 Жыл бұрын
Vector is thread-safe, ArrayList is not, but ArrayList is faster. You can wrap it in a synchronisedList to get thread safety on ArrayList. That's the video condensed. You're welcome
@chan-edidz11 ай бұрын
❤
@enfieldli9296 Жыл бұрын
Finally a new video
@vyankateshodilwar Жыл бұрын
Really love the way you demonstrated this in the minimalistic way
@tarifhalabi Жыл бұрын
Very interesting video. I used Vectors way back in 1.2 or 1.3 but never bothered to find out how they are different than ArrayList. Thank you. Keep up the good work.
@sirinath Жыл бұрын
You can used synchronized in one of the threads. This synchronises in both threads which might not be necessary when there are 2 threads. N threads N - 1 synchronisations. If N is large you can synchronize all threads.
@gowthamselvaraj7793 Жыл бұрын
Thats a very good explaination. ArrayList has less time for execution but vector is high and Threads are high in Vector but less in ArrayList.
@zakariyaechmaili5647 Жыл бұрын
i have never heard of vectors lol, now I feel like I have a much better understanding of them. thanks for explaining the concept in such a clear and engaging way, seriously you are the only education youtuber that i watch his contents not because i have to but i want to, so fun to watch and not boring at all ♥ unlike many educational youtubers, can't wait for the next video keep up the great work! ♥(we miss the smile)
@snesmocha Жыл бұрын
Laughs in c++
@SuprousOxide Жыл бұрын
With the vector both add and get methods are synchronized. You might have a case where you build a list once, and then want to READ from it from multiple threads. That should be safe with just the unsynchronized ArrayList, but to be safer you could wrap the list in an Collections.unmodifiableList. Then you won't need the overhead of synchronization on your get calls.
@LBCreateSpaceАй бұрын
Such a clear explanation! Ty so much for making these videos
@waseemahmad-t7m Жыл бұрын
SIRRRRRR......U R Great... you solved my longlasting issue by vector class. i was making a 2d style java game and usling LinkedList. when i skip level or in fast or sometime it stuck it always gave me error. linkedlist. it tried above code for sync, but did not work. after watching your video, i changed it to vector . no issue now, no significant or noticable lagg or any issue that was facing and hitting head with codes and its technique OOP method. Great.......
@codeZarathustra Жыл бұрын
Wow! John I have not idea about this concept, but now is clear. Thank you.
@paulushcgcj Жыл бұрын
Great video. One suggestion I would give is to use Duration to measure time instead of System.currentTimeMillis() as it is not that reliable, specially when dealing with lots of data, the effect of CPU throttling and time leap will mess your count. LocalDateTime with duration to measure the difference is better
@rlasc84 Жыл бұрын
Hi! Nice video. When I was working with JTable I always extending AbstractTableModel using ArrayList because I believed that the DefaultTableModel was deprecated for use Vectors. But Vectors are still around here as DefaulTableModel too. Thanks John and sorry for my english..
@Blazsejka Жыл бұрын
Awesome as always. I work as a Java dev but I still can find interesting and not-known topics in your videos.
@pranavmahajan4190 Жыл бұрын
This is the best video I have seen on Vector. Thanks a lot
@joshuatienda Жыл бұрын
Good to watch your videos!
@madhav_0075 Жыл бұрын
Sir kindly create complete video for Java . Which will be helpful for lot of beginners to understand what exactly java❤
@alfredochola5971 Жыл бұрын
Thank you very much John. You do teach really well.
@bobfarker4001 Жыл бұрын
Im going to use start and end to measure my code's time. TY
@oguzhantopaloglu9442 Жыл бұрын
Whole video summarized in a sentence: Vectors are slower because unlike arraylists they are thread-safe so just use arraylists and if you have multiple threads use Collections.synchronizedList(arrayList).
@michaeltaylor4817 Жыл бұрын
no idea if it has been covered, but explaining public, private, protected and package private might be a good idea. just a thought. and in my opinion making some examples a little bit more complex might help for like a real world example. as extending some functionality might be tricky for learning developers. also if possible, please stick to one IDE swapping between intelli J and Eclipse can be mildly distracting. and an ide specific functionality is a pain if someone is using Eclipse and they wanna do something only available in Intelli J other wise love your good work, very helpful could we have a lesson on FUNCTIONS, BIFUNCTIONS, SUPPLIERS, CONSUMERS and other functional interfaces with a demo of passing them to methods etc :)
@abhishektiwarijr Жыл бұрын
Thanks a lot for all of your information to the point content man. It would be great to see videos on SOLID principles and Design Patterns from you.
@christopherreif3624 Жыл бұрын
I’m really glad I found your channel, thank you for such quality content!
@brenolavieri Жыл бұрын
OMG - im suffering here with vectors for no reason at all...Thx for this excellent explanation
@earomc Жыл бұрын
I love your videos!!! Learned something again I didn't know!
@SandileMnqayi11 ай бұрын
❤ your videos, thanks a mill. Please show up how you would create your own synchronized class.
@timkreutzkamp85198 ай бұрын
Funny Thing is if i switch the first example around, adding to the vector is faster than adding to the arraylist. Checked again with two ArrayLists and adding to the first datatype is always half the time than adding to the second one ^^
@kc771810 ай бұрын
Vectors is one of the topic that always kind of confused me. Thanks for detail explanation
@anpadjahil9711 Жыл бұрын
Thanks a lot John.
@shaunhorton5619 Жыл бұрын
I have a quick question regarding the performance difference between Vectors and Arraylists, or more specifically with the synchronizedlist, if you create the synched list wrapper for your arraylist, does it only take that performance hit and start behaving comparably to a Vector in a threaded environment, or does it slow down the ArrayList when accessing it in a single thread also?
@erickgozan Жыл бұрын
I love your videos, you really explain very well, greetings from Mexico city.
@mihirgore4074 Жыл бұрын
After so long....good to see it :)
@Zeero3846 Жыл бұрын
Vectors in Java were initially implemented to be thread safe as the original philosophy in Java was to just do everything one way to fit every use case. It's the reason why every method is virtual and must be contained in a class, among other things. By the way, the other data structure from the original Java version is Hashtable. It corresponds to the more useful HashMap. It's also worth noting that Java also have a number of other concurrent data structures in the java.util.concurrent package, like BlockingDeque, ConcurrentHashMap, etc.
@chrisp267 Жыл бұрын
Good video! One question: Aren't Vectors deprecated?
@andromilk2634 Жыл бұрын
Please, do more videos, I love them.
@anaselmakhloufi2180 Жыл бұрын
ArrayList is fast because it is non-synchronized , Vector is slow because it is synchronized
@fahadgaliwango450210 ай бұрын
Thanks for sharing about vectors asd arraylist , you demonstrated how arrayList performs poorly with multi threads if not synchronised. what happens if parallelStreams are used? Does it automatically gets wrapped into Collections.synchronized()
@Soltryful Жыл бұрын
Hello John, always appreciate your clear and concise way of explaining difficult JAVA concepts, can you please talk about Dynamic proxies when you get a chance? Thanks
@clingyking2774 Жыл бұрын
Someone tell John we would really love an intro to springboot course from him, perhaps some 30 min crud app of some sorts. His videos helped me finally get the hang of recursion after reading hundreds of articles and numerous youtube videos later.
@CodingWithJohn Жыл бұрын
I'll let him know 😮
@clingyking2774 Жыл бұрын
@@CodingWithJohn Lots of thanks.
@re37re Жыл бұрын
Hi, John! Can you make a video on Quarkus and GraalVM?
@rajithlahiru55804 ай бұрын
Just wow! nice explanation
@nicholaswhite73518 ай бұрын
Very good job. Best wishes to John.
@ВладиславСалюкТВ-23 Жыл бұрын
Hello , John Ukraine is watching you 🇺🇦 You are the best Java-blogger I’ve ever seen)
@itsolidude2353 Жыл бұрын
Hey John, love your vids! Will you ever make a video on thread pooling and asynch. programming?
@MuksEmmaN Жыл бұрын
Hi sir can you please do a video on Thread pools and executor service in Java?
@svalyavasvalyava9867 Жыл бұрын
awesome video, thank you! 😊
@fez0062 Жыл бұрын
Hello John! Please post more videos!! When I watch your explanations I don’t feel like a complete idiot who can never be a developer but the opposite!!!! It would be cool if you made some videos about patterns of programming or about spring framework or about microservises Anyway whatever you do I love your content!)
@anath04 Жыл бұрын
Could you please make some video on Reactive Java , particularly project reactor.
@awesomebearaudiobooks Жыл бұрын
Can someone please explain, why do I get the same results for both ArrayList and Vector? I am not using any wrappers, I am jsut running the same code as John, and yet my ArrayLists are not in any way faster than my Vectors, why is that? Am I using a wrong JRE or something? Maybe there is something to do with Maven? For example, I get this: Added 10000000 elements to ArrayList: 251ms Added 10000000 elements to Vector: 242ms Added 10000000 elements in a multithreaded way to ArrayList: 1030ms Added 10000000 elements in a multithreaded way to Vector: 1275ms
@sohpol Жыл бұрын
Me Gusta :) Next video, maybe something about switch statement and how it evolved in Java? Or maybe something about using debugger in most popular IDE's? That would be also extremely useful for beginners :)
@GeoffryAbiFarah Жыл бұрын
Great video!
@RajinderYadav Жыл бұрын
Learned something new!
@saddyman__7107 Жыл бұрын
Hi, Can you make a video about composition ? thx a lot
@ahmadiyad2860 Жыл бұрын
thank you man
@exitspree Жыл бұрын
The way you explain things is so nice.
@B.Aboobaker Жыл бұрын
can you please make a video on: encapsulation, inheritance, polymorphism, and abstraction... pleaseeeee
@LourenzoFerreira Жыл бұрын
I saw weird behaviours when testing... I ran it with Java 20, and consistently Vector was faster than ArrayList with a milion item, but with 10, ArrayList is faster again...
@leno_tc0610 Жыл бұрын
I never see join() method, it's possible to make deadlock with it?
@mminahid9662 Жыл бұрын
in javaFX Application is an abstract class. In this abstract class there have some abstract methods which are overridden in main class which extends abstract Application class and also have static launch() method in abstract class Application. The launch() method calls from the main method in main class. Now how is it possible launch() method calls these abstract methods and for these calls overridden methods in main class are executes? please help to understand
@sblantipodi4 ай бұрын
Hi there. Is there some news on the Vector Api? When they will exit the incubation state? I put a lot of effort to use them in my program and they are devastating on some loads with CPUs that supports AVX512. My concern is that I'll need to rewrite everything for API changes when the APIs will exit the incubator state. I have some "development questions" on those APIs, are there a mailing list where to discuss about the use and the benefit of those APIs?
@trup10ka Жыл бұрын
Hello, awsome video as always, i learned so much from you. I wanted to ask if you could do a video about Http requests
@yuriytheone Жыл бұрын
Hello and thank you. Should we use Vector if we are just reading from List in multithreading mode? Is ArrayList is safe for reading in multithreading? Thanks in advance!
@monishbiswas1966 Жыл бұрын
If it’s only accessed from one thread you do not need to synchronise, and if it’s accessed from multiple threads you may want to handle the synchronisation in the surrounding code to allow several operations to be atomic. Alternatively there says there are constructs that are better suited to concurrency, such as a concurrent hash map
@yuriytheone Жыл бұрын
@@monishbiswas1966 thank you for reply
@troeteimarsch Жыл бұрын
perfectly informative :)
@techStatuss Жыл бұрын
What about concurrent collection?
@neelkrishna Жыл бұрын
I'm running this code locally and the elements are being added to a vector about 2x faster than an arrayList (consistently). Could this be because I'm on an M series Mac with ARM architecture?
@juggernaut41446 ай бұрын
Your videos are gem
@mauricesmith8234 Жыл бұрын
HEES BACK!!!!!!
@WiseDog1 Жыл бұрын
hello John, love your content. Can you make your course available on Udemy or LinkedIn ?
@mayurlaniya5049 Жыл бұрын
awesome!!! JOHN
@hansudowolfrahm48568 ай бұрын
Haters gonna say the new updates are bad, but you can still use the old ones and also if you don't develop you will just get stuck in the past. I think most new things are optional and you don't have to use them, however it's always good to use both. I will continue to use the old hello world but I will also try out new things and learn the new update as well. Having additional knowlege will always give an advantage.
@redcrafterlppa303 Жыл бұрын
When using awt/swing parts of the api uses vector (probably because the api was written before the collections framework) and it's pretty annoying to be forced to use vectors in multiple places or copy a bunch of array lists into vectors.
@codingoak4701 Жыл бұрын
This is perfect
@jansentanu2637 Жыл бұрын
What's the font you use in the code editor?
@chirathhevavitharana48382 ай бұрын
ArrayList: Hey,Hey, Buddy iam the fastest Vector: Na na na In the multithreads 😂😂 That was awesome John
@ramosm198 Жыл бұрын
hahahaha the end was awsome, thanks man u r the best
@Zeero3846 Жыл бұрын
The only other situation is if you're using 3rd party code, and they force you to use Vector. Of course, you'd try to limit the use of Vector by copying into a Vector at the very last minute just before passing it as a parameter. If a Vector is returned, it may be useful to just put it into a List variable if you're not going to manipulate the elements in any way afterwards. If you are, still put it in a List variable, but consider if you need the thread safety. If not, then copy from the Vector into an ArrayList.
@aaf2011 Жыл бұрын
Hello John I would like to see a real practical example of using the java collection framework. I never understood the fundamentals of collection framework and if it is related to the database like mysql. I am really struggling with the concept of database and data structures. Please help 😢 SOS
@sagniksaha4179 Жыл бұрын
That was damn good info
@JacobMockler Жыл бұрын
Good Monday coffee waiting for breakpoints to trigger
@heyimemad5626 Жыл бұрын
can u explain JavaFX Basics? please
@advrakshachaudhari36994 ай бұрын
great vid
@Fanchiotti Жыл бұрын
The thread experiment probably does not guarantee mutual exclusion and order of delivery, right? So, how does ArrayList and Vector behave on synchronized scenarios with semaphores, reentrant locks and so on... Also, in the beginning you just printed out the static 1M integer value instead of printing the Collection object's size, but still good video, very informative, thanks.
@Fanchiotti Жыл бұрын
Also: how dare you say ill things about Vector, what are you a pagan or an anarchist? 🧐
@cuongnguyenhuu2836 Жыл бұрын
why Arraylist is faster even in the single-threaded example?
@jurgenaddicks1634 Жыл бұрын
But, I love my good old Vectors 😢, just kidding ! Nice Video 😀👍
@VuLinhAssassin Жыл бұрын
Is this Vector the same as something something Vector API coming with the most recent Java version?
@falklumo Жыл бұрын
No, new vector api is about using SIMD processor instructions in a portable way.
@julborre4 ай бұрын
I used Vectors way back in Java 1.2 or maybe 1.3, after ArrayList I never looked back
@Qbe_Root Жыл бұрын
could've extracted the single-threaded and multi-threaded benchmarks into separate functions taking a List instead of copy-pasting and renaming variables all over the place
@EnderCrypt Жыл бұрын
Now compare vector and synchronized list (from Collections.)