Java serialization 🥣

  Рет қаралды 72,070

Bro Code

Bro Code

4 жыл бұрын

Java serialization tutorial for beginners
#Java #serialization #tutorial
00:19 serialize
08:47 deserialize
13:40 advanced stuff
Coding boot camps hate him! See how he can teach you to code with this one simple trick...
Bro Code is the self-proclaimed #1 tutorial series on coding in various programming languages and other how-to videos in the known universe.

Пікірлер: 141
@BroCodez
@BroCodez 3 жыл бұрын
Java Serialization import java.io.*; public class SerializeDemo { public static void main(String [] args) { //Serialization = The process of converting an object into a byte stream. // Persists (saves the state) the object after program exits // This byte stream can be saved as a file or sent over a network // Byte stream can be saved as a file (.ser) which is platform independent // (Think of this as if you're saving a file with the object's information) // Steps to Serialize // --------------------------------------------------------------- // 1. Your class should implement Serializable interface // 2. add import java.io.Serializable; // 3. FileOutputStream fileOut = new FileOutputStream(file path) // 4. ObjectOutputStream out = new ObjectOutputStream(fileOut); // 5. out.writeObject(objectName) // 6. out.close(); fileOut.close(); // --------------------------------------------------------------- //Deserialization = The reverse process of converting a byte stream into an object. // (Think of this as if you're loading a saved file) // Steps to Deserialize // --------------------------------------------------------------- // 1. Your class should implement Serializable interface // 2. add import java.io.Serializable; // 3. FileInputStream fileIn = new FileInputStream(file path); // 4. ObjectInputStream in = new ObjectInputStream(fileIn); // 5. objectNam = (Class) in.readObject(); // 6. in.close(); fileIn.close(); // --------------------------------------------------------------- // important notes 1. children classes of a parent class that implements Serializable will do so as well // 2. static fields are not serialized (they belong to the class, not an individual object) // 3. Fields declared as "transient" aren't serialized, they're ignored // 4. the class's definition ("class file") itself is not recorded, cast it as the object type // 5. serialVersionUID is a unique version ID //SerialVersionUID = serialVersionUID is a unique ID that functions like a version # // verifies that the sender and receiver of a serialized object, // have loaded classes for that object that are compatible // Ensures object will be compatible between machines // Number must match. otherwise this will cause a InvalidClassException // A SerialVersionUID will be calculated based on class properties, members, etc. // A serializable class can declare its own serialVersionUID explicitly (recommended) User user = new User(); user.name = "Bro"; user.password = "I
@sudhanshu7115
@sudhanshu7115 2 жыл бұрын
I think you can even teach me rocket science & Quantum physics with your teaching skills ❤️
@joshuafrancisriin8078
@joshuafrancisriin8078 Жыл бұрын
Bro i get error in deserialization.. In main class it says java.Lang.ClassNotFoundException:serializer.user I checked everything but i couldn't find out why i get this error.. Pls help bro 😓😭
@lemaaaron9009
@lemaaaron9009 Жыл бұрын
Thanks 🤝
@phaustinanapunyi8057
@phaustinanapunyi8057 Жыл бұрын
@@joshuafrancisriin8078 Ensure that the classes for both the serializer and the desializer are organized in the same structure. E.g. if your serializer Main and User classes are in a package say org.example ensure you have the same package org.example for your deserializer Main and User classes. Secondly, contents of the User classes have to be identical.
@yunanistan2364
@yunanistan2364 Жыл бұрын
That is a hard working bro :)
@exxzxxe
@exxzxxe 2 жыл бұрын
By far, Bro Code has the most succinct, and clearest explanations of Java on KZfaq! No more than needed, no less than required. Good job!
@lucyl3552
@lucyl3552 3 жыл бұрын
such an amazing tutorial! I was having some trouble working with SQL databases and had to resort to serialization for my cs project, saved my life!
@ducare7218
@ducare7218 Жыл бұрын
Clear how-to and break down, still technical but not boring! Thanks Bro Code!
@codingletsdoit2746
@codingletsdoit2746 2 жыл бұрын
This is the guy who needs support! Thanks this tutorial was the best Bro!
@preraksemwal8768
@preraksemwal8768 2 жыл бұрын
This is the only channel on KZfaq I literally feel I must comment on every time I watch , else I'm a bad guy XD Your videos are great ... Seriously !!
@renecabuhan1675
@renecabuhan1675 3 жыл бұрын
You explain it better than my teacher bro. Thank you.
@fantasy9960
@fantasy9960 Жыл бұрын
Absolute the best serialization tutorial video I have ever watched! Thank you
@danielmilewski7659
@danielmilewski7659 Жыл бұрын
Best explanation I ever had for this topic! Thank you! Can't believe this is on youtube!
@Snowmanver2
@Snowmanver2 2 жыл бұрын
Came back to rewatch the video and brush up on that topic. Thanks, Bro!
@FukSN
@FukSN 2 жыл бұрын
Top video. Very informative, and easy to follow as usual. Thanks Bro.
@bitcoin1532
@bitcoin1532 3 жыл бұрын
wanted to learn this for a save function, tysm bro
@haramrit09k
@haramrit09k Жыл бұрын
I have a Software Engineer interview in 2 days, and I never knew what Serializing and Deserializing actually meant in Java, until now. THANKS A TON Bro!
@connorwhitedik
@connorwhitedik 17 күн бұрын
Get the job?
@haramrit09k
@haramrit09k 17 күн бұрын
@@connorwhitedik yeah, got three interviews, and two offers :)
@hansmuller9545
@hansmuller9545 2 жыл бұрын
You're a champ bro! Tried to create a savefile through parsing the objects variables and then reread them and create through it the new objects. This is way easier. Thanks!
@mpelalidiko
@mpelalidiko Жыл бұрын
Hey bro, thanks a lot for your amazing videos! I just want to add another detail: if a class has fields that are other custom-made classes, then these classes ALSO have to implement Serializable
@ricardochica4339
@ricardochica4339 2 жыл бұрын
Thank you so much for these videos!
@seabass6106
@seabass6106 3 жыл бұрын
Bro, this is getting serioulized 💕
@lucyledezma709
@lucyledezma709 3 жыл бұрын
Thanks Bro!.. for the new video!
@alfredhitch9306
@alfredhitch9306 3 жыл бұрын
Legend. Solo carrying My Butt through advanced programming
@amreedoh
@amreedoh 2 жыл бұрын
I feel that in my soul
@fanaha282
@fanaha282 5 ай бұрын
Your videos are very very helpful but its been a while that you did not post anything about Java, your community is waiting and thank you for that
@razvanrusan9319
@razvanrusan9319 2 жыл бұрын
Dope tutorial! Helped me for an exam!
@gobikrishnasharma5041
@gobikrishnasharma5041 11 ай бұрын
thankz bro amazing way to teaching keep it up !!!
@shaynazoedeguzman7418
@shaynazoedeguzman7418 Жыл бұрын
TYVM Bro code! You are superb!
@made4u363
@made4u363 Жыл бұрын
very detail and easy to understand
@usamanadeem145
@usamanadeem145 3 жыл бұрын
Great
@nawfalnjm5699
@nawfalnjm5699 3 жыл бұрын
thanks for this amazing video !
@calebkrauter4027
@calebkrauter4027 Жыл бұрын
Helpful video, thank you.
@kristijanlazarev
@kristijanlazarev 4 ай бұрын
Very complicated, good job
@mrwakacorp
@mrwakacorp Жыл бұрын
The perfect video for the topic!
@jasper5016
@jasper5016 2 жыл бұрын
Great video. All doubts clear.
@mattgraves3709
@mattgraves3709 3 жыл бұрын
Nice! Thanks Bro!
@kemann3815
@kemann3815 2 жыл бұрын
Awesomely great
@percivalgebashe4376
@percivalgebashe4376 Жыл бұрын
Nice
@ikersantana7618
@ikersantana7618 Жыл бұрын
Bro, I need a teacher like him in my classes
@Aditya-fu4jj
@Aditya-fu4jj 6 ай бұрын
Good work bro
@tomhowlingmoon2962
@tomhowlingmoon2962 8 ай бұрын
great stuff, way more complete than what the teacher explained in class lmao
@chuanxinjin9301
@chuanxinjin9301 Жыл бұрын
Guys, make sure your package file need to be the same in both the serialization folder and deserialization, then you won't get ClassNotFoundExpection for this. And bro you your video is fantastic. Love from China
@st3v3cR0zz
@st3v3cR0zz Жыл бұрын
thank god for your comment!!!!
@Mohamed_MDJ
@Mohamed_MDJ 4 ай бұрын
I was looking for this for 30min
@horssentc
@horssentc Жыл бұрын
great video thank you 👍
@hippiestafarii
@hippiestafarii 2 жыл бұрын
Another great video as always
@sabermmirza
@sabermmirza 3 жыл бұрын
Great job bro:)
@shotx333
@shotx333 2 жыл бұрын
Nice tutorial
@dsdcp
@dsdcp 3 жыл бұрын
Thanks Bro.
@benderbg
@benderbg 10 ай бұрын
Great video as the rest you've made.
@25bcmusic37
@25bcmusic37 2 жыл бұрын
great
@eugenezuev7349
@eugenezuev7349 22 күн бұрын
good job
@joyceasante8292
@joyceasante8292 Жыл бұрын
NOTE Converting an object into a byte stream = serialization Converting a byte stream into an object = deserialization
@marekmacku3526
@marekmacku3526 2 жыл бұрын
U re legend thanks so much 🙏
@frankjuuh
@frankjuuh 2 жыл бұрын
Love you, bro
@carloslozan856
@carloslozan856 Жыл бұрын
good tutorial
@elkay7065
@elkay7065 3 жыл бұрын
Thanks mate
@javierpesaresi311
@javierpesaresi311 Жыл бұрын
Tremendo!
@girl6994
@girl6994 3 жыл бұрын
Hey you. If you find this video helpful, pls make sure to like, comment,and subscribe if you want to become a fellow bro. Is that spells right? Because I can speak this sentence in my dream. It’s so familiar.
@MrLoser-ks2xn
@MrLoser-ks2xn 2 жыл бұрын
Thanks
@quachthetruong
@quachthetruong 3 жыл бұрын
Is there anyone here have this problem? "Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "user" is null" When I try to separate serialize and deserialize into 2 projects like in the video, serialize project works fine but deserialize project gives this error. And when I put serialize and deserialize in the same file, it works perfectly. If you know how to fix this problem, please help me!
@Nates2823
@Nates2823 Жыл бұрын
nc one
@user-jq1mp3jc1h
@user-jq1mp3jc1h 2 ай бұрын
13:42 (Part 2)
@amulyan1478
@amulyan1478 2 жыл бұрын
you are the besst!
@KhuongNguyen-sw2ke
@KhuongNguyen-sw2ke Жыл бұрын
thank you bro
@ibrahimylmaz8378
@ibrahimylmaz8378 2 жыл бұрын
thanks bro
@changlim-zp1sv
@changlim-zp1sv 3 жыл бұрын
I really want to get started into coding, but don’t know where to start! Could I get any pointers?
@BroCodez
@BroCodez 3 жыл бұрын
🤔Hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
@user-je4xw6tx3k
@user-je4xw6tx3k 3 жыл бұрын
what is the difference if i store data into json file farmat? i found another youtuber said that serialization is a process to convert data from RAM into string format like json, so that it can be stored and send to your friends, etc. Is he correct?
@Simon-yf7fo
@Simon-yf7fo 3 жыл бұрын
json isnt exactly the same. Json is more like an Object, that every Programming Language can interpret and is more readable for humans
@archaeniac7846
@archaeniac7846 2 жыл бұрын
thankyouuuu
@bix4400
@bix4400 Жыл бұрын
Need series on Android app development bro !
@ahmadosama2652
@ahmadosama2652 Жыл бұрын
when i try to make deserialization i got this message( class libraryBook cannot be cast to class java.util.ArrayList)
@noah77
@noah77 3 жыл бұрын
Please, please, please make a video on ML or Neural net, please teach how to make a very simple neural net in *JAVA* Even if you suck at those ML things, please figure it out, and make a tutorial on it, pleaseeeeeee
@aryanmn1569
@aryanmn1569 3 жыл бұрын
when u get no thumbs down, u can be sure u did good
@babyskeleton7990
@babyskeleton7990 Жыл бұрын
Very helpful video, thanks. If I knew about this, i wouldn't have to create .txt files using damn FileWriter and split them using _ and . When I wanted to read them, I split the entire long character string using split() method, which resulted in countless problems and headaches, as you can imagine lol.
@honoredegg
@honoredegg 2 жыл бұрын
84th. Thank you, ma Bro Sensei
@cinemacat4108
@cinemacat4108 2 жыл бұрын
hey, thanks for the tutorial , however I have a little problem , whenever I use ObjectOutPutStream or InputStream I get an exception wether it was out.writeObject or in.readObject I imported everything and I made sure the error was from those statments when I surrounded them with a try statment please help
@Lukas-qy2on
@Lukas-qy2on 2 жыл бұрын
"ObjectOutPutStream" output is one word so put is not capitalized so its ObjectOutputStream*
@cinemacat4108
@cinemacat4108 2 жыл бұрын
@@Lukas-qy2on thanks, however this wasn't the problem, the class I was serializing didnt implement java.serializable thanks anyway
@joshuafrancisriin8078
@joshuafrancisriin8078 Жыл бұрын
@@cinemacat4108 same problem! How did you solve it?
@cinemacat4108
@cinemacat4108 Жыл бұрын
@@joshuafrancisriin8078 I forgot to implement Serializable in the class that needs to be saved
@azmalshaik1295
@azmalshaik1295 2 жыл бұрын
hello Bro code Iam your Subscriber can you please upload a video on Annotations because of iam confusing about it
@FJ.Y
@FJ.Y 3 жыл бұрын
I love you bro
@st3v3cR0zz
@st3v3cR0zz Жыл бұрын
keep on getting ClassNotFoundException error.
@pesterlig
@pesterlig 3 жыл бұрын
ywaah!
@downhilldreamer5313
@downhilldreamer5313 2 жыл бұрын
liked commented subscribed
@Jha_Aditya01
@Jha_Aditya01 Жыл бұрын
Getting the Classcastexception in my Deserialization package... IDE says everything is correct tho it is not printing the values.. any solutions? Please🥺
@leekbiel
@leekbiel Жыл бұрын
Hi Aditya Kumar; 1.Check if the name of the 2 packages are the same; 2.Check if the name of the 2 class are the same; The both has to be the same;
@yunanistan2364
@yunanistan2364 Жыл бұрын
@@leekbiel thanks I was searching for it since hours
@justswift_1213
@justswift_1213 2 жыл бұрын
I am getting java.lang.ClassCastException. It says that both the user classes are in an unnamed module of loader 'app'. What does it mean? A solution to my problem would be great. Thanks.
@leekbiel
@leekbiel Жыл бұрын
Hi JustSwift_ ; 1.Check if the name of the 2 packages are the same; 2.Check if the name of the 2 class are the same; The both has to be the same;
@justswift_1213
@justswift_1213 Жыл бұрын
@@leekbiel I had already solved the issue. But thanks a lot as those are something to keep in mind.
@charanraj3180
@charanraj3180 Жыл бұрын
@@leekbiel Thanks alot man : )
@dolevdo
@dolevdo 2 жыл бұрын
saved my life
@VeeGotThePower
@VeeGotThePower 10 ай бұрын
I had a problem when I was doing this in VS Code. The software makes packages for both serialization and deserialization folder in the code, which if removed I couldn't run in the VS Code. But even after following Bro's code step by step, I faced the error :- Exception in thread "main" java.lang.ClassCastException: class broCode.Serialization.User cannot be cast to class broCode.Deserialization.User (broCode.Serialization.User and broCode.Deserialization.User are in unnamed module of loader 'app'). This was very annoying cause I followed step by step. So Stack said that I can change the medium of file I'm saving on to something like a JSON file. But if it can work for bro, it can for us. Thus did it without VS Code the manual way by notepad and cmd prompt (also removed the part of packages, even tho both the code lay in different folder) it worked. Typing all of this for anyone who faces Class Cast Exception.
@vuvanphuc6633
@vuvanphuc6633 8 ай бұрын
Hi @vishalrai, I guess your problem can be cause you're using different names for package and class names on 2 projects. It should be the same on 2 projects. You can solve this issue by that way. If you don't want they same the name or package. You can use InputStream instead of FileInputStream as below : InputStream is = new FileInputStream("your path file here..."); ObjectInputStream ois = new ObjectInputStream(is); You can solve this issue.
@koppitent
@koppitent 5 ай бұрын
bro doesnt link git but pastes Code into comments. 👌💪
@developerjunior446
@developerjunior446 3 жыл бұрын
Where do you work Bro ?
@sailorsaturn4693
@sailorsaturn4693 8 ай бұрын
حرفيا ابونا
@gioele33
@gioele33 3 жыл бұрын
Is it possible to save the file as ".txt" instead of ".ser"?
@Simon-yf7fo
@Simon-yf7fo 3 жыл бұрын
Yes it is but there is no point in doing that
@frosty4513
@frosty4513 3 жыл бұрын
yes it is I just did that
@Simon-yf7fo
@Simon-yf7fo 3 жыл бұрын
@@frosty4513 obviosly it is possible but there is no difference in renaming file endings
@annihae5939
@annihae5939 2 жыл бұрын
Oh no how do you know my password?:D Thanks for the video, helps so much with Java test prep:)
@sachwinikumarkhatri1913
@sachwinikumarkhatri1913 3 жыл бұрын
why I am getting error = >Exception in thread "main" java.lang.ClassCastException
@helriskor
@helriskor 3 жыл бұрын
I have the same problem
@justswift_1213
@justswift_1213 2 жыл бұрын
I am having the same problem as well. Did you get any solution? If so, please let me know what it is. It would be really helpful.
@leekbiel
@leekbiel Жыл бұрын
Hi Sachwini Kumar Khatri; 1.Check if the name of the 2 packages are the same; 2.Check if the name of the 2 class are the same; The both has to be the same;
@gabecarmichael254
@gabecarmichael254 Жыл бұрын
@@leekbiel If I have all the classes in the same package, it won't let me name them the same thing (2 User classes and 2 Main classes)... What should I do?
@8oniim622
@8oniim622 9 ай бұрын
beast 🫶
@cannac6995
@cannac6995 3 жыл бұрын
13:12 "To something secure such as *password123* "
@user-jq1mp3jc1h
@user-jq1mp3jc1h 2 ай бұрын
Lol
@DamienRoyan
@DamienRoyan 2 жыл бұрын
*insert The prophecy is true meme clip*
@srinicnu5283
@srinicnu5283 2 жыл бұрын
source code please !!! BRO
@MukulAnand-er8ik
@MukulAnand-er8ik Жыл бұрын
bro code
@MrLoser-ks2xn
@MrLoser-ks2xn Жыл бұрын
@imnithyn4447
@imnithyn4447 2 жыл бұрын
@bogdan_bgp
@bogdan_bgp 4 ай бұрын
"something secure like... password123" 😆😆
@puppeteer7929
@puppeteer7929 Жыл бұрын
: )
@piotrjaga6929
@piotrjaga6929 11 ай бұрын
statistics
@lukashusz7659
@lukashusz7659 3 жыл бұрын
doesn't work :(
@Simon-yf7fo
@Simon-yf7fo 3 жыл бұрын
If you‘d elaborate I might help
@mahirahman3838
@mahirahman3838 2 жыл бұрын
@@Simon-yf7fo I got class not found exception
@Simon-yf7fo
@Simon-yf7fo 2 жыл бұрын
@@mahirahman3838 You try to invoke a class that is not inside the classpath. This is a very common issue. Since you did not provide much information thats the only thing I can tell you.
@mahirahman3838
@mahirahman3838 2 жыл бұрын
@@Simon-yf7fo I serialized the objects In a project named 'Serialization' but when I created an different project(Deserialization) and try to read those serialize objects ,, that time ClassNotFoundException occured.. Though I did exactly same as bro code.
@Simon-yf7fo
@Simon-yf7fo 2 жыл бұрын
@@mahirahman3838 In this case I suspect that your filepath to the serialized Object is wrong (.ser file). Otherwise it could have sonething to do with your run configurations.
@exitspree
@exitspree Жыл бұрын
Thanks so much!
@wombozombo
@wombozombo 5 ай бұрын
Comment
@suyashgupta1741
@suyashgupta1741 2 жыл бұрын
13:10 update the password to something secure 😂😂
@sreeshakv5405
@sreeshakv5405 Жыл бұрын
Nice
Java TimerTask ⌚
11:50
Bro Code
Рет қаралды 69 М.
Java generics ❓
22:04
Bro Code
Рет қаралды 102 М.
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 105 МЛН
Looks realistic #tiktok
00:22
Анастасия Тарасова
Рет қаралды 11 МЛН
ОСКАР ИСПОРТИЛ ДЖОНИ ЖИЗНЬ 😢 @lenta_com
01:01
Получилось у Вики?😂 #хабибка
00:14
ХАБИБ
Рет қаралды 7 МЛН
Java lambda λ
18:00
Bro Code
Рет қаралды 89 М.
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 712 М.
Java Reflection Explained - bɘniɒlqxƎ noiɟɔɘlʇɘЯ ɒvɒᒐ
20:07
Coding with John
Рет қаралды 173 М.
Java multithreading 🧶
15:18
Bro Code
Рет қаралды 122 М.
Serialization - A Crash Course
8:14
0612 TV w/ NERDfirst
Рет қаралды 123 М.
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 228 М.
10 Nooby Mistakes Devs Often Make In Python
24:31
Indently
Рет қаралды 49 М.
Java buttons 🛎️
14:28
Bro Code
Рет қаралды 162 М.
New Java Version 22 - The 3 Best New Features You'll ACTUALLY Use
13:15
Coding with John
Рет қаралды 96 М.
Худший продукт Apple
0:53
Rozetked
Рет қаралды 212 М.
Simple maintenance. #leddisplay #ledscreen #ledwall #ledmodule #ledinstallation
0:19
LED Screen Factory-EagerLED
Рет қаралды 22 МЛН