Тёмный
No video :(

Java copy objects 🖨️ 

Bro Code
Подписаться 2,1 млн
Просмотров 54 тыс.
50% 1

Опубликовано:

 

25 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 103   
@BroCodez
@BroCodez 3 года назад
//*********************************************** public class Main { public static void main(String[] args) { Car car1 = new Car("Chevrolet","Camaro",2021); //Car car2 = new Car("Ford","Mustang",2022); //car2.copy(car1); Car car2 = new Car(car1); System.out.println(car1); System.out.println(car2); System.out.println(); System.out.println(car1.getMake()); System.out.println(car1.getModel()); System.out.println(car1.getYear()); System.out.println(); System.out.println(car2.getMake()); System.out.println(car2.getModel()); System.out.println(car2.getYear()); } } //*********************************************** public class Car { private String make; private String model; private int year; Car(String make,String model,int year){ this.setMake(make); this.setModel(model); this.setYear(year); } Car(Car x){ this.copy(x); } public String getMake() { return make; } public String getModel() { return model; } public int getYear() { return year; } public void setMake(String make) { this.make = make; } public void setModel(String model) { this.model = model; } public void setYear(int year) { this.year = year; } public void copy(Car x) { this.setMake(x.getMake()); this.setModel(x.getModel()); this.setYear(x.getYear()); } } //***********************************************
@pavelkvasnicka6856
@pavelkvasnicka6856 Год назад
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
@ibrahimylmaz8378
@ibrahimylmaz8378 2 года назад
you really got style. you are changing lives Bro. I thank you from the bottom of my heart.
@odaakeenya
@odaakeenya 2 года назад
you're my dude buddy. nice voice-over, excellent video quality, and easy-to-follow content. God bless you.
@yahelbraun5471
@yahelbraun5471 3 года назад
Great explanation! Keep on the good work!
@BroCodez
@BroCodez 3 года назад
thanks for watching Yahel!
@healer35
@healer35 Год назад
aweeeeeeesome bro..this is the best course in whole youtube
@mimvt
@mimvt Год назад
Absolutely easier after you explain everything. Thank you Bro! you save my day
@juanestebanparraparra8531
@juanestebanparraparra8531 2 года назад
Man, I love your videos, you are so underrated (your videos should have more views)
@gentle9964
@gentle9964 11 месяцев назад
excellent explanation, love it
@elionayzuridasilveira4140
@elionayzuridasilveira4140 3 месяца назад
Thank you for this tutorial, Bro!
@soumelee5661
@soumelee5661 Год назад
wow great explanation
@logeshr1761
@logeshr1761 Год назад
Superb explanation bro code
@vincentchoo7471
@vincentchoo7471 3 года назад
Keep up the great work!
@BroCodez
@BroCodez 3 года назад
thank you for watching Vincent!
@Ballnose
@Ballnose 6 месяцев назад
Brilliant Brilliant explanation and exactly what I needed for my Pokemon game :)
@ShermukhammadKarimov
@ShermukhammadKarimov 4 месяца назад
Thanks for the clear explanation.
@theultimateamazing3722
@theultimateamazing3722 Год назад
Amazing video! I was looking for copying objects for so long.... thanks bro
@eugenezuev7349
@eugenezuev7349 3 месяца назад
brilliant
@kirillutsenko9306
@kirillutsenko9306 2 года назад
thx for your explanation
@unalysuf
@unalysuf Год назад
Thank you so much for your effort
@pasraju
@pasraju 2 года назад
This is a good explanation!
@cristianoseixas2417
@cristianoseixas2417 Год назад
Thanks, excelent
@nguyennhan3966
@nguyennhan3966 Год назад
you are the best
@WorstDruidEU
@WorstDruidEU 2 года назад
Can someone explain why we used (Car x) as an argument of the copy method? What does this x mean? Is it a placeholder for whatever name we're gonna give to the object? Which object does it refer to?
@mr.prince8701
@mr.prince8701 2 года назад
X is the object of type Car that you'll be copying the attributes from. (This)aka car 2 is doing the calling, so u place the attributes from X onto car 2. A copy constructor basically a method that copies the attributes of an object onto another object of the same type. X in this case is Car1.
@yevgenomelchenko732
@yevgenomelchenko732 Год назад
Thanks, very helpful!
@mahdib9361
@mahdib9361 3 года назад
nice
@kemann3815
@kemann3815 2 года назад
Awesome
@TheEvertonDias
@TheEvertonDias Год назад
Thanks, Bro!
@vaika8817
@vaika8817 Год назад
thanks bro
@francosalgado4556
@francosalgado4556 2 года назад
¡Muchas gracias!
@bakaiismaiilov4732
@bakaiismaiilov4732 3 года назад
Love it 👍
@user-zq6yx7of5f
@user-zq6yx7of5f Год назад
Thank you very much!
@OmerFarukAY-ij2xg
@OmerFarukAY-ij2xg 2 месяца назад
I love you bro
@danny.3036
@danny.3036 3 года назад
Thanks, Bro! ☕ You're awesome!
@huuloc8719
@huuloc8719 2 года назад
Nice.
@danielmilewski7659
@danielmilewski7659 2 года назад
Thanks bro! Awesome channel!
@hannakhamutouskaya2299
@hannakhamutouskaya2299 3 года назад
You are great!!
@shubhsharma19
@shubhsharma19 2 года назад
commenting for algo, great video
@alexcaesar5377
@alexcaesar5377 3 года назад
Great Job
@BroCodez
@BroCodez 3 года назад
thanks for watching Metin!
@cdjosh3568
@cdjosh3568 3 года назад
Is it good practice to always have a copy method and overload the constructor to copy as well?
@BroCodez
@BroCodez 3 года назад
not necessarily but it's a common practice
@NikoFool
@NikoFool 2 года назад
Bro code you are a fucking legend!
@stefanescu1000
@stefanescu1000 9 месяцев назад
It s pretty easy and logic
@geneolo
@geneolo Год назад
Thank you Bro🤗How are you doing? This tutorial is great!
@tomjohansson3520
@tomjohansson3520 2 года назад
Thanks, very helpfull!
@qpdbwvwdbqp4730
@qpdbwvwdbqp4730 2 года назад
Thanks a lot Bro! 🙌 But I had no idea how to do it in non-encapsulated classes :/
@qpdbwvwdbqp4730
@qpdbwvwdbqp4730 2 года назад
Oh, finally figured out! //~~MAIN CLASS~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class Main { public static void main(String[] args) { Weapon weapon1 = new Weapon("Sword", 10); Weapon weapon2 = new Weapon("Dagger", 5); System.out.println("WEAPON 1:"); System.out.println(weapon1.name); System.out.println(weapon1.damage); System.out.println(); System.out.println("WEAPON 2:"); System.out.println(weapon2.name); System.out.println(weapon2.damage); System.out.println(); //Copying weapon2.copy(weapon1); System.out.println("New WEAPON 2:"); System.out.println(weapon2.name); System.out.println(weapon2.damage); } } //~~WEAPON CLASS~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class Weapon { //ATTRIBUTES String name; int damage; //CONSTRUCTORS Weapon(String name, int damage){ this.name = name; this.damage = damage; } //METHODS void copy(Weapon x) { this.name = x.name; this.damage = x.damage; } } [OUTPUT]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WEAPON 1: Sword 10 WEAPON 2: Dagger 5 New WEAPON 2: Sword 10
@minhtetpaing1695
@minhtetpaing1695 3 года назад
Thank you so much sir.
@skillR-243
@skillR-243 3 года назад
Thanks bro
@annexsoftworks
@annexsoftworks 2 года назад
Thanks bro!
@MrLoser-ks2xn
@MrLoser-ks2xn 2 года назад
Thanks
@kurosshyu2621
@kurosshyu2621 6 месяцев назад
thanks
@SumbaSlice
@SumbaSlice 2 года назад
amazing, thank you!
@paolobonsignore2813
@paolobonsignore2813 3 года назад
Im kinda confused at this point :/
@yanluisnunezlara319
@yanluisnunezlara319 2 месяца назад
Instances of classes, wether it's either predefined classes in java like String or classes created by programmers, all of them are stored in memory(RAM), this is called data by reference. In the tutorial, copying objects means to do an object point at the same memory space by the reference. Pay attention when the teacher equalize car2=car2 and print both object return the same memory address. I expect that you understand me, I'm not native spiker and have a low level of English.
@gerardonavarro3400
@gerardonavarro3400 28 дней назад
​@@yanluisnunezlara319fué tremenda explicación mi hermano, muchas gracias!
@suryaa5564
@suryaa5564 3 года назад
Thank You So Much
@Muhammadfaisal-kd9kx
@Muhammadfaisal-kd9kx 9 месяцев назад
thankyou
@_7.T_
@_7.T_ 3 года назад
thank you my Bro ♥♥♥
@MrCoolTester
@MrCoolTester 4 месяца назад
Commenting here just because Bro asked me to do so!
@kaushalprasadyadav9242
@kaushalprasadyadav9242 2 года назад
Please make videos for mobile app development....
@ibtesamatif4418
@ibtesamatif4418 3 года назад
what planet are you from .. ? 100% informative
@augischadiegils.5109
@augischadiegils.5109 3 года назад
Thanks bro!!
@stephanieokechi1138
@stephanieokechi1138 2 месяца назад
🎉
@ramok1303
@ramok1303 2 года назад
Hello, this video really helped me, but I have a question. Can I accses the values of Car x in the copy method directly like this since the method is in the Car class: public void copy(Car x) { this.setMake(x.make); this.setModel(x.model); this.setYear(x.year); } it worked for me, but i am rather asking. btw I watched almost the entire java playlist (most of it in the 12h. video) and I love the way you're doing it, it's amazing. (sorry for my English)
@mohamedbenkhalifa1299
@mohamedbenkhalifa1299 2 года назад
Thanks for pointing this out. It actually works and makes sense. Thanks bro!
@DigitalAstronautOG
@DigitalAstronautOG 2 года назад
You can do that and it will work fine if it is set up in the same way. However, it is best practice to make member variables private and use public/protected getters and setters for them. The reason being is let's say you don't want specific things to be set as the value stored in the variable, you can stop this by handling this in your setter however you would like. Then, the only way you can retrieve that variable is by using the defined getter method (since the member variable has private access). If you're calling the variables from within the class itself, it isn't required that you use a getter and setter (since private access doesn't matter within the same class), but, again, it is best practice to make getters and setters to handle how code is accessed and updated. Hope this helps!
@mohammadreza1414
@mohammadreza1414 Месяц назад
This is considered a shallow copy right?
@alexcaesar5377
@alexcaesar5377 3 года назад
is it possible to change a private method or variables only by getter method in different class? (don't use setter only getter)
@BroCodez
@BroCodez 3 года назад
I believe you would need to call some method within the class that contains the private member to access it and change it
@alexcaesar5377
@alexcaesar5377 3 года назад
@@BroCodez could you give me an example?
@lamias7712
@lamias7712 2 года назад
Merci Bro
@ivblock4899
@ivblock4899 Год назад
what happen if we don't use this while calling copy method and set method
@bakaiismaiilov4732
@bakaiismaiilov4732 3 года назад
Bro ? will you be making a video for cloning in java ?
@BroCodez
@BroCodez 3 года назад
I'm not sure, it depends if I can fit it into this playlist
@joshblank4579
@joshblank4579 Год назад
Bro, how do I make a deep copy of an array?
@aboyiphilippa1136
@aboyiphilippa1136 4 месяца назад
@user-yq5hj6lg3e
@user-yq5hj6lg3e Год назад
czx
@greeneggsandmushrooms9855
@greeneggsandmushrooms9855 3 года назад
now i'm a copy machine
@alexyakoveno4682
@alexyakoveno4682 Год назад
@drcod3r329
@drcod3r329 3 года назад
amazing thats what i can say
@wallstreetbets7741
@wallstreetbets7741 2 года назад
Need rewatch
@chakmak
@chakmak 3 года назад
where is the new videos?!
@28santagabo
@28santagabo Месяц назад
@shalajko
@shalajko 3 года назад
let me just copy this
@SinskariBoi3366three
@SinskariBoi3366three 5 месяцев назад
Ai made it easy copy code
@kapebreak
@kapebreak Год назад
comment
@aram8639
@aram8639 2 года назад
excellent explanation, love it
@romanrubanovich9273
@romanrubanovich9273 3 года назад
Thanks, Bro!
@baubaudinamo
@baubaudinamo 3 года назад
nice
@PoorwayTraning
@PoorwayTraning Год назад
thanks
@mudassirnaz1813
@mudassirnaz1813 3 года назад
Thanks
@anjapietralla5767
@anjapietralla5767 7 месяцев назад
@maciejkaminski8535
@maciejkaminski8535 3 года назад
comment
@Simis999
@Simis999 Год назад
thanks
Далее
Java interface 🦅
7:51
Просмотров 186 тыс.
Java lambda λ
18:00
Просмотров 92 тыс.
Whoa
01:00
Просмотров 11 млн
ПАВЕЛ ДУРОВ АРЕСТОВАН
1:45:21
Просмотров 110 тыс.
How principled coders outperform the competition
11:11
Shallow vs Deep Copy in Java
8:22
Просмотров 86 тыс.
How to write a copy constructor in Java - 037
5:38
Просмотров 34 тыс.
Java super keyword 🦸‍♂️
8:09
Просмотров 93 тыс.
Java generics ❓
22:04
Просмотров 106 тыс.
I've been using Redis wrong this whole time...
20:53
Просмотров 354 тыс.
Java serialization 🥣
21:13
Просмотров 74 тыс.
Java multithreading 🧶
15:18
Просмотров 125 тыс.
Java encapsulation 💊
8:27
Просмотров 109 тыс.