Java's SimpleDateFormat is a Disaster Waiting to Happen

preview_player
Показать описание
I bet you've used SimpleDateFormat in Java before! It's a quick, easy, super reliable way to parse and format dates....
Right?
Sometimes, not at all!!

Learn about a dangerous situation involving SimpleDateFormat in this quick Java lesson.

Improve your Java by watching it being coded live in tutorials!

Hey, I'm John! I'm a Lead Java Software Engineer who has been in the industry for over a decade, and I love teaching what I know!

Tell me what else you want to see!

Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.

📕 THE best book to learn Java, Effective Java by Joshua Bloch

📕 One of my favorite programming books, Clean Code by Robert Martin

🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial

🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)

📹Phone I use for recording:

🎙️Microphone I use (classy, I know):

Donate with PayPal (Thank you so much!)

☕Complete Java course:

Рекомендации по теме
Комментарии
Автор

I would love to see a video where you explain threads, web applications etc in Java. I am on my second year in my Java courses and I haven't even heard any of these terms in class. You seem very knowledgeable and I would enjoy learning about it.

nunya
Автор

7:27 thank you. I can not stress the importance of always offering a solution to an identified problem. Thanks.

ndk
Автор

Had a similar experience, company I used to work at uses alot of excel to do calculations. Then one day, after years since that excel calculator tool got deployed to prod, one internal user realised some calculation results were way off, turns out a previous developer (probably an intern) created just 1 static instance of the excel workbook, and it just so happened that years later, at exactly the same moment, 2 requests wrote to the excel file at exactly the same time

TheMoviemaker
Автор

FastDateFormat wierdness:

Ran the example given. Gives the expected output:

10 x "Successfully parsedThu Oct 17 12:34:51 AEST 2024"

Every now and again though (if I hit it hard enough) I get:

"Successfully parsedThu Oct 17 12:34:51 GMT+10:00 2024"

Which is the same, but how come sometimes it picks up the correct named timezone, and sometimes not?

cthoadmin
Автор

I realy like your videos. Short and very clear.
hmm is the naming convention of dataFormat not DATE_FORMAT?

pascalclement
Автор

Ok. I’m an experienced developer, so I know what and why this happening. But blaming SDF is an oversimplified and misleading to newer folks. There are many many classes that are not thread safe. Any time you are doing things in multi-threaded manor you should *never* used shared instances of things unless you absolutely *know* for certain they are thread safe.

brucehartweg
Автор

Thanks John for enlightening video. I never knew SDF can blow up line that. Tomorrow I need to fix some shit in our application! 😂✌️

myselfyuvi
Автор

Can I store yyyy-mm-dd formate in Date date; veriable and not in string

vaishnavi_art
Автор

@Coding with John can this not also be prevented by using good Unit Tests instead?

NLxDoDge
Автор

Could this be happening only on particular date patterns? I guess I can carry out a test and find out

anthonyanyama
Автор

Another way would be simply to synchronize on that object.

Chupacabras
Автор

1:17 oops. Caught John’s bad manners. Unsubscribing. Ok. Ok. Will stay but last warning. 😉

ndk