Java Class Design: When to use a Primitive vs Reference Type

preview_player
Показать описание
In this video I will discuss when to use a primitive vs reference type when designing Java classes. I will also answer some questions I have received around immutability and record types.

🔗Resources & Links mentioned in this video:

👋🏻Connect with me:

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

Saw your tweet about someone being negative so just want to let you know I appreciate your content!

mikebonney
Автор

Great stuff, 20 years of experience and after watching you videos creating software becomes enjoyable again. Thanks.

binio
Автор

I’m a new programmer. I started learning Java just 4 months ago. I’m so grateful for these videos. They give me so much practical information that my classes don’t.

Even using var when creating and instance is just so helpful to my brain and thought process.
Thank you so much.

keldur
Автор

Awesome! These 'basic' stuff are much needed to be shared. Please continue :)
Some of them we just do/write in automatic mode without really knowing the underneath rules, or we forget to really think about what we really want/need, but this kind of video keep us (at least me) on track, so thank you!
This 'basic' stuff can potentially cause problems further in the line and we don't have any clue why. For example, knowing that int, long etc default to 0 and Integer/Long default to null sounds just a detail, but in real life, it can be the difference of having a bug and producing dirty data or not.

asterixcode
Автор

I really appreciate the content that you share with us all. Thanks to your work, I became the best in my class and even surprise my mentors. In 30 years of my life, I have had no idols among celebrities or athletes, but you are my idol. I hope one day to become as valuable a person as you are!

ltmhpib
Автор

Dan, your videos help me master the concepts of Java. I really appreciate that, hugs from a Brazilian dev at the beginning of his career. Thank you!

freitas
Автор

You are such a great mentor. Keep up the good stuff. Learn alot from you.

hadikhan
Автор

Regarding the Todo class, I would rather use all primitives because they are given a default value (except String of course) and I can use the default values of the class for checking certain things such as if Todo.id is equal to zero then I know it didnt come from the database because normally primary keys start with a value of 1 or more. In addition I prefer every class variable to be initialized to at least something to avoid a null pointer which is why I often create a default constructor and it signals to other developers what the defaults of the class are. I havent needed to work much with Threads, caching or high levels of performance so immutable objects are a rare occurrence with my work, however I use final a lot on objects being passed to methods and class level objects and constructors.
As an aside to the video I prefer to use primitives on methods for parameters in Apis so that internal objects are not exposed to the outside world.
Interesting video, glad I learnt something about Records.

garethbaker
Автор

Every video i learn something new! Thanks !

nikolaimochalov
Автор

I enjoy these videos very much, tips and tricks

Apopjak
Автор

Great one. I usually prefer Boxed variables unless you are the guy that is working on a thing that requires shaving off additional nanosecond

AleksandarT
Автор

Great video!
One thing worth to mention in terms of immutability are Collections. Making collection 'final' is not enought, because we can still for example add or remove elements from it. To solve this in getter method we can pass copy of collection, not collection itself. But how to achieve that in record?

matsior_
Автор

Hello Dan!
Thank you so much for you amazing tutorials!
Can you plz record a video about "how to log entire request and response in spring boot servlet application like a java champion" =) ?

alekseylubenets
Автор

Very nice Dan Vega. I'm different from people that are so friendly sometimes 🙄 Lol

aldosilva
Автор

Thank you!!! 🙏 🙏 please use dark theme

sadeshure
Автор

you talked about primitive and reference values, is unboxing relevant when you work both type indistinctly?

haroldpepete
Автор

Hello Sir,
Please make a video on ExecutorService in java. I could not understand this concept from anywhere.

joelmartis
Автор

You videos are helpful for me
I am a beginner, so I can't understand. Can you comment out? so that you can understand me
Thank you ❤

RohitMagdum-wcfj
Автор

either increase your mic quality or be louder .PLEASE

darogajee
Автор

Real developers don't use primitive types. Prove me wrong.

scrumtuous
visit shbcf.ru