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

  Рет қаралды 6,740

Dan Vega

Dan Vega

Күн бұрын

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
@mikebonney1462
@mikebonney1462 3 ай бұрын
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 3 ай бұрын
I'll get them. Nobody says anything negative about my Dan!
@Frank-xu2ed
@Frank-xu2ed 3 ай бұрын
I second this. Always watching your videos when on the train home
@hou3455
@hou3455 3 ай бұрын
I have discovered Dan Vega on Udemy (Jhipster course) and I was hooked 🙂 Thanks for the good work, Dan Take care
@keldur16
@keldur16 3 ай бұрын
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.
@binio28
@binio28 3 ай бұрын
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
@freitas0222 3 ай бұрын
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!
@user-lt7mh4pi3b
@user-lt7mh4pi3b 3 ай бұрын
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!
@asterixcode
@asterixcode 3 ай бұрын
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.
@nikolaimochalov7863
@nikolaimochalov7863 3 ай бұрын
Every video i learn something new! Thanks !
@hadikhan6758
@hadikhan6758 3 ай бұрын
You are such a great mentor. Keep up the good stuff. Learn alot from you.
@garethbaker5179
@garethbaker5179 Ай бұрын
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.
@TM-jb8bw
@TM-jb8bw 3 ай бұрын
Awesome as always 🎉
@TheExcentro
@TheExcentro 3 ай бұрын
Thanks a lot!
@antonslonkin
@antonslonkin 3 ай бұрын
Thank you!!! Very useful information
@Apopjak
@Apopjak 3 ай бұрын
I enjoy these videos very much, tips and tricks
@Victor-bz1xn
@Victor-bz1xn 3 ай бұрын
Ótimo vídeo, muito esclarecedor !
@ShubhamYadav-lt6dt
@ShubhamYadav-lt6dt 3 ай бұрын
Awesome Explanation
@DanVega
@DanVega 3 ай бұрын
Thank you!
@zhenyalee2731
@zhenyalee2731 3 ай бұрын
thmaks a lot for your work
@michaelchung8102
@michaelchung8102 3 ай бұрын
Thanks for this useful tutorial ❤
@DanVega
@DanVega 3 ай бұрын
You're welcome 😊
@AleksandarT10
@AleksandarT10 3 ай бұрын
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.
@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.
@sadeshure5241
@sadeshure5241 3 ай бұрын
Thank you!!! 🙏 🙏 please use dark theme
@alekseylubenets1822
@alekseylubenets1822 3 ай бұрын
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" =) ?
@aldosilva6
@aldosilva6 3 ай бұрын
Very nice Dan Vega. I'm different from people that are so friendly sometimes 🙄 Lol
@DanVega
@DanVega 3 ай бұрын
🤣 I appreciate that
@haroldpepete
@haroldpepete 3 ай бұрын
you talked about primitive and reference values, is unboxing relevant when you work both type indistinctly?
@joelmartis4023
@joelmartis4023 3 ай бұрын
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-wc8fj 3 ай бұрын
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
@darogajee3286 3 ай бұрын
either increase your mic quality or be louder .PLEASE
@user-cn3gf4xl1i
@user-cn3gf4xl1i 3 ай бұрын
For me its fine
@scrumtuous
@scrumtuous 3 ай бұрын
Real developers don't use primitive types. Prove me wrong.
@DanVega
@DanVega 3 ай бұрын
Real Java developers use both 😉
@ildar5184
@ildar5184 3 ай бұрын
Not sure about primitive types, but what I know is real developers use BigDecimal instead of double and float 😊
@scrumtuous
@scrumtuous 3 ай бұрын
@@ildar5184 To be totally honest, I get tired of all the devs I know bragging about their BigDecimals.
@scrumtuous
@scrumtuous 3 ай бұрын
@@DanVega Tell me you're not a real developer without telling me you're not a real developer.🤦‍♀
Java is slow and verbose (or so they say)
20:39
Dan Vega
Рет қаралды 10 М.
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 11 МЛН
МАМА И STANDOFF 2 😳 !FAKE GUN! #shorts
00:34
INNA SERG
Рет қаралды 4,7 МЛН
Java is ALWAYS Pass By Value. Here's Why
5:22
Coding with John
Рет қаралды 118 М.
Value vs Reference in JavaScript in 1 Minute
1:00
ColorCode
Рет қаралды 50 М.
OpenAI Whisper Command and Python Library
4:13
Wes Higbee
Рет қаралды 321
Test Driven Development (TDD) in Spring
51:09
Dan Vega
Рет қаралды 22 М.
Connect with me on Live | Ask me Anything series
Abhishek.Veeramalla
Рет қаралды 257
5 Common Mistakes Spring Developers Make
18:06
Dan Vega
Рет қаралды 15 М.
How to create an Immutable Class in Java from Scratch?
14:04
Riddhi Dutta
Рет қаралды 3,7 М.
How to call a Java REST API using JDK Http Client
22:23
Dan Vega
Рет қаралды 6 М.
Records In Java - Full Tutorial
14:20
Daily Code Buffer
Рет қаралды 23 М.
Klavye İle Trafik Işığını Yönetmek #shorts
0:18
Osman Kabadayı
Рет қаралды 190 М.
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 3,7 МЛН
ИГРОВОВЫЙ НОУТ ASUS ЗА 57 тысяч
25:33
Ремонтяш
Рет қаралды 343 М.