Java Class Design: When to use a Primitive vs Reference Type
Ғылым және технология
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:
GitHub Repo: github.com/danvega/primitive-...
👋🏻Connect with me:
Website: www.danvega.dev
Twitter: / therealdanvega
Github: github.com/danvega
LinkedIn: / danvega
Newsletter: www.danvega.dev/newsletter
SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️
Пікірлер: 43
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.
Saw your tweet about someone being negative so just want to let you know I appreciate your content!
@DanVega
3 ай бұрын
I appreciate that. I try not to let those get me down but comments like yours bring me up!
@scrumtuous
2 ай бұрын
I'll get them. Nobody says anything negative about my Dan!
@Frank-xu2ed
2 ай бұрын
I second this. Always watching your videos when on the train home
@hou3455
2 ай бұрын
I have discovered Dan Vega on Udemy (Jhipster course) and I was hooked 🙂 Thanks for the good work, Dan Take care
Great stuff, 20 years of experience and after watching you videos creating software becomes enjoyable again. Thanks.
@DanVega
3 ай бұрын
Wow that could be one of the nicest things anyone on this platform has ever said. Coding should be enjoyable (at times) so I am glad to hear I am helping with that. Have a great day!
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!
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.
You are such a great mentor. Keep up the good stuff. Learn alot from you.
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!
Every video i learn something new! Thanks !
Awesome as always 🎉
I enjoy these videos very much, tips and tricks
Awesome Explanation
@DanVega
3 ай бұрын
Thank you!
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.
Thank you!!! Very useful information
Thanks for this useful tutorial ❤
@DanVega
3 ай бұрын
You're welcome 😊
Ótimo vídeo, muito esclarecedor !
Thanks a lot!
thmaks a lot for your work
Great one. I usually prefer Boxed variables unless you are the guy that is working on a thing that requires shaving off additional nanosecond
@zombi1034
3 ай бұрын
Problem with boxed types is comparing them with == can lead to unexpected results. var i1 = Integer.valueOf(10); var i2 = new Integer(10); System.out.println(i1 == i2); This will return false, for example.
Very nice Dan Vega. I'm different from people that are so friendly sometimes 🙄 Lol
@DanVega
3 ай бұрын
🤣 I appreciate that
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" =) ?
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?
@baibula
3 ай бұрын
Super easy, using a constructor.
you talked about primitive and reference values, is unboxing relevant when you work both type indistinctly?
Thank you!!! 🙏 🙏 please use dark theme
Hello Sir, Please make a video on ExecutorService in java. I could not understand this concept from anywhere.
@baibula
3 ай бұрын
Have you watched Jenkov's tutorial?
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 ❤
either increase your mic quality or be louder .PLEASE
@user-cn3gf4xl1i
2 ай бұрын
For me its fine
Real developers don't use primitive types. Prove me wrong.
@DanVega
2 ай бұрын
Real Java developers use both 😉
@ildar5184
2 ай бұрын
Not sure about primitive types, but what I know is real developers use BigDecimal instead of double and float 😊
@scrumtuous
2 ай бұрын
@@ildar5184 To be totally honest, I get tired of all the devs I know bragging about their BigDecimals.
@scrumtuous
2 ай бұрын
@@DanVega Tell me you're not a real developer without telling me you're not a real developer.🤦♀