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

  • @keldur16
    @keldur163 ай бұрын

    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.

  • @mikebonney1462
    @mikebonney14623 ай бұрын

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

  • @DanVega

    @DanVega

    3 ай бұрын

    I appreciate that. I try not to let those get me down but comments like yours bring me up!

  • @scrumtuous

    @scrumtuous

    2 ай бұрын

    I'll get them. Nobody says anything negative about my Dan!

  • @Frank-xu2ed

    @Frank-xu2ed

    2 ай бұрын

    I second this. Always watching your videos when on the train home

  • @hou3455

    @hou3455

    2 ай бұрын

    I have discovered Dan Vega on Udemy (Jhipster course) and I was hooked 🙂 Thanks for the good work, Dan Take care

  • @binio28
    @binio283 ай бұрын

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

  • @DanVega

    @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!

  • @freitas0222
    @freitas02222 ай бұрын

    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!

  • @asterixcode
    @asterixcode2 ай бұрын

    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.

  • @hadikhan6758
    @hadikhan67583 ай бұрын

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

  • @user-lt7mh4pi3b
    @user-lt7mh4pi3b3 ай бұрын

    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!

  • @nikolaimochalov7863
    @nikolaimochalov78632 ай бұрын

    Every video i learn something new! Thanks !

  • @TM-jb8bw
    @TM-jb8bw2 ай бұрын

    Awesome as always 🎉

  • @Apopjak
    @Apopjak3 ай бұрын

    I enjoy these videos very much, tips and tricks

  • @ShubhamYadav-lt6dt
    @ShubhamYadav-lt6dt3 ай бұрын

    Awesome Explanation

  • @DanVega

    @DanVega

    3 ай бұрын

    Thank you!

  • @garethbaker5179
    @garethbaker517916 күн бұрын

    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.

  • @antonslonkin
    @antonslonkin2 ай бұрын

    Thank you!!! Very useful information

  • @michaelchung8102
    @michaelchung81023 ай бұрын

    Thanks for this useful tutorial ❤

  • @DanVega

    @DanVega

    3 ай бұрын

    You're welcome 😊

  • @Victor-bz1xn
    @Victor-bz1xn3 ай бұрын

    Ótimo vídeo, muito esclarecedor !

  • @TheExcentro
    @TheExcentro3 ай бұрын

    Thanks a lot!

  • @zhenyalee2731
    @zhenyalee27313 ай бұрын

    thmaks a lot for your work

  • @AleksandarT10
    @AleksandarT103 ай бұрын

    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

    @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.

  • @aldosilva6
    @aldosilva63 ай бұрын

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

  • @DanVega

    @DanVega

    3 ай бұрын

    🤣 I appreciate that

  • @alekseylubenets1822
    @alekseylubenets18223 ай бұрын

    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" =) ?

  • @matsior_
    @matsior_3 ай бұрын

    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

    @baibula

    3 ай бұрын

    Super easy, using a constructor.

  • @haroldpepete
    @haroldpepete3 ай бұрын

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

  • @sadeshure5241
    @sadeshure52413 ай бұрын

    Thank you!!! 🙏 🙏 please use dark theme

  • @joelmartis4023
    @joelmartis40233 ай бұрын

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

  • @baibula

    @baibula

    3 ай бұрын

    Have you watched Jenkov's tutorial?

  • @RohitMagdum-wc8fj
    @RohitMagdum-wc8fj2 ай бұрын

    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 ❤

  • @darogajee3286
    @darogajee32863 ай бұрын

    either increase your mic quality or be louder .PLEASE

  • @user-cn3gf4xl1i

    @user-cn3gf4xl1i

    2 ай бұрын

    For me its fine

  • @scrumtuous
    @scrumtuous2 ай бұрын

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

  • @DanVega

    @DanVega

    2 ай бұрын

    Real Java developers use both 😉

  • @ildar5184

    @ildar5184

    2 ай бұрын

    Not sure about primitive types, but what I know is real developers use BigDecimal instead of double and float 😊

  • @scrumtuous

    @scrumtuous

    2 ай бұрын

    @@ildar5184 To be totally honest, I get tired of all the devs I know bragging about their BigDecimals.

  • @scrumtuous

    @scrumtuous

    2 ай бұрын

    @@DanVega Tell me you're not a real developer without telling me you're not a real developer.🤦‍♀

Келесі