Комментарии:
useless video, wasted time
ОтветитьAwesome
ОтветитьNothing and no-one is equal to Newman 🤣
ОтветитьHi John, thanks for the brilliant video.
ОтветитьHi John, how useful are JML, checker framework, Nullaway these annotation tools in professional development work? Thanks
ОтветитьThanks ❤
ОтветитьThank you John
ОтветитьCompany will start adopting Java 17 when I am a feeble old man.
Ответитьmaybe i'm fully wrong, but why no a try catch?
Ответитьthank you so much, i got what i want
ОтветитьHello John,
Thank you for this wonderful video!!
Currently I am working on a project someone else wrote before, and I an new to Microservices (IoC & DI, all that fun);
Since it's structure is a bit complicated and not usually we can use null checker in production environment, how can we avoid that?
I am new to Microservices, and noticed recently when I wrote some codes, it came back with null pointer in the log, and I had to spend some time to find the issue, sometime more than others.
You can also avoid null pointers by ensuring data basically can't be set to null.
For example, the .setName() method in his example could easily have a null check where it sets the name to a default value like "Unknown" when you call setName(null).
thanks a lot... for sharing this.
ОтветитьHey, thanks for that
ОтветитьHi John
Why null pointer exception is occuring while I'm entering a policy number after clicking on run illustration button it's show error that is null pointer exception why this occur can you pls exam explain this plsssss
gah!
ОтветитьGreat explanation, thanks
ОтветитьOr use Kotlin. There is a button up there in the Intellij to convert your Projekt to Kotlin. PRESS IT!
ОтветитьMan, I really hope Java finds a way to add nullable types to the language. Once you start using them on Kotlin, you really miss them ):
Ответить//Shortcut for throwing a NullPointerException:
throw null; //The downside is that you can't give it a custom message.
I get to be the guy who introduces fresh-out new hires to our code base. There are two things I grind into them from day 1.
* Always check for null!
* Source commentary is like sex. When it's good it's VERY good. When it's bad it's usually better than nothing.
I see a lot of situations of String comparison in which our process is case insensitive. For that we use
if ("Cosmo".equalsIgnoreCase(myOtherCat.getName()) { ... }
Man I work at company with a pre 14 Java version and you have no idea how many times I had a npe on a line with like 5 different objects and I would have no idea where to start. I actually didn’t know about the new exception text, very nice!
ОтветитьAnother great video, John. I've gotten to the point in my practice where I'm considering initializing stuff to null. This came just in time.
ОтветитьBut what about Optional? Why you not mention about this? I think it's good approach to avoid NPE
ОтветитьVery helpfull. Thank you !
ОтветитьHey John please please make series on SpringBoot and microservices :(
The way you explain stuff is Amazing
Great video! This is java 11 or above?
Ответить"Null was a mistake"
- Tony Hoare, inventor of Null
Hi John! What's about Optional objects? That's a great way to get round Null values and NullPointerExceptions 8.-)
ОтветитьI think you missed an important part of "strategies to avoid null pointer exception" that is "design your code to not use nulls at all!" Instead of nulls use default values, empty collection or throw an exception. This way you can avoid all the null checks and make the code more readable. If a null pointer exception happens that is for sure a bug that needs to be resolved. A null check with an if statement is just a workaround the issue in my opinion and is a very bad practice in modern java code.
ОтветитьI'm not even a Java developer, I use C# but I still enjoy watching your videos and for a lot of your videos I still learn from them as Java and C# are really similar.
I don't know what it is about your videos, is it your voice or the way you talk but I love you videos.
Wasn't this video also a good opportunity to talk about the nullable and not null annotations so that your IDE's linter can help find NullPointerExceptions early?
And for the String comparison at the end you could have also used Objects.equals(string1, string2) which will do a null check for you.
Objects.equals(...) also avoids NPEs very successfully. However, the best way of avoiding NPEs in the JVM is introducing the language Kotlin in your Java project. It allows you declaring anything as not Nullable on language level.
ОтветитьThank you John, great explanation.
Ответитьthanks man !, can you please explain the "optional" keyword it is also used to avoid null values, please add it as you make things super easy :), waiting
ОтветитьString defaultMessage = “Excellent video as usual”;
System.out.println(defaultMessage);
Please do JVM, JDK, JRE. I have been coding since 2 years yet struggle to understand it. Please help.
ОтветитьIs java dead for new projects? Is java only support 1.8 jobs or migrating 1.8 to 1.11? They say everywhere that python is new java, I understand that you make these video to sell your java course, but can I ask you to be honest and answer my questions.
ОтветитьThe solution for this problem is: Optional. Use on methods that may or not return a result. It will force you, on the client code, to handle it. Thus avoiding null pointer situation.
Ответитьhelps a lot for my essay.. thy john!
ОтветитьHi john, could you please explain us the difference between object and instance.
ОтветитьHi, Jonh. Nice video. You could talk about the garbage collector. It's a good subject.
ОтветитьTalking about nulls and not to say anything about Optionals? :)
ОтветитьI always learn something new with you! Thanks a lot!!
ОтветитьYou are THE BEST. precise and concise to perfection
ОтветитьThere is also 3rd option - just catch this exception in other place and never care about it. You should avoid null/nullchecks in your code as much as possible. This technic is called fail fast and i would recommend it to anyone.
But i also like the way you did it here with ArrayList - like return actual fake null implenentation which will have the same methods, for example by including interface, but i wouldn't do things like return 0 etc, sometimes when debugging your code why something is behaving the odd way - it can be actually this 0 thing.
Good explanation, but can't we use try catch to handle NPE?
Ответить