Тёмный
Byte Pint
Byte Pint
Byte Pint
Подписаться
Welcome to Byte Pint, your ultimate destination for immersive and enlightening tutorials!.
Whether you're a seasoned developer seeking to expand your skills or a newcomer eager to embark on the coding odyssey, our channel offers a diverse array of educational content tailored to suit all levels of expertise. From beginner-friendly introductions to advanced techniques and industry insights, join our community of passionate learners as we explore the fascinating realms.
Subscribe now and empower yourself with the knowledge to code with confidence!
Комментарии
@HagenvonEitzen
@HagenvonEitzen 7 часов назад
So perhaps its safer to use `if a< b else if b< a else`
@DeclanMBrennan
@DeclanMBrennan 7 часов назад
What a horrible mess! What genius thought caching some values was a good idea so the == operator doesn't have consistent semantics?
@rakshitharangarajan2445
@rakshitharangarajan2445 12 часов назад
Does ur channel teaches java
@zenniththefolf4888
@zenniththefolf4888 13 часов назад
That's probably why you should just use primitive int. The wrapper class should only be used for it's methods.
@AlvinYap510
@AlvinYap510 15 часов назад
Thank god I never learned Java, and I never planned to do so.
@Misteribel
@Misteribel 18 часов назад
Another way of saying this is that == is "reference equals" for objects and "value equals" for value types. This doesn't surprise experienced programmers, this is Java 101. This difference exists in virtually every language (though with different syntax).
@zombiezoo1384
@zombiezoo1384 18 часов назад
such a quality,short, to the-point video... thanks i did not knew this happens
@dominiorrr6510
@dominiorrr6510 23 часа назад
That's why all my homies hate Java
@test-rj2vl
@test-rj2vl 23 часа назад
Putting 9==9 and 900 == 900 both in interview questions is evil. People are used to equals method so some might assume 9==9 is false while rhea reality is that such developer would simply use equals and thus the code would not fail.
@ZachAttack6089
@ZachAttack6089 День назад
What the fuck
@tylerd5924
@tylerd5924 День назад
cause its shit
@T33K3SS3LCH3N
@T33K3SS3LCH3N День назад
I was so confused by the thumbnail until the first seconds reminded me of the existence of this idiotic wrapper class concept. Java is truly the worst major programming language.
@rodrigoqteixeira
@rodrigoqteixeira День назад
Nah bro, just use int when you can. There is almost no case where Integer is good, except for LinkedLists and stuff
@nagesh007
@nagesh007 День назад
Super
@xcoder1122
@xcoder1122 День назад
The main problem is that in Java == works like in C, whereas in all modern programming languages, == works like .equals() in Java, which makes much more sense, as there are barely any situations where it really matters that two object references really point to the same object, most of the time it only matters if two objects are equal or not.
@Durayne
@Durayne День назад
For Integer types == does not have that problem. Otherwise most of the embedded code could be shredded.
@xcoder1122
@xcoder1122 День назад
@@Durayne YYou mean for "primitive" types (the types in the video were integer types, but they were objects, not primitives). Yet that's just another weakness of Java. There shouldn't even be primitive types. A language can cheat all it wants under the hood, but at least to the programmer it should be consistent. In SmallTalk, everything is an object, but that's a lie. SmallTalk only pretends that everything is an object. In actual SmallTalk implementations, not everything is an object, but the language just hides that fact from you as a programmer. Swift is similar: In Swift, all simple numbers can be used as complex data types; in fact, the compiler will often just store them as primitives in the compiled code, even in CPU registers when possible, but there is no boxing/unboxing for the developer at any time. Java could simply change "a == b" to "a.equals(b)" for all object types after compilation to bytecode, and for primitives it would just compare them directly at runtime instead, as it does today. And if you mix primitives and objects, it would box/unbox each as needed to compare them. After all, Java is completely type-safe, so it always knows the type of everything, even at compile time. At runtime, the bytecode would have looked the same as it does today, only the compiler (javac) would have produced slightly different bytecode depending on the two types to the left and right of ==. primitiveA == primitiveB => Do what you do today. objectA == objectB => Compile to "objectA.equals(objectB)". objectA == primitiveB => Unbox objectA if possible, then compare primitives, otherwise box primitiveB and compare with equals().
@zekiz774
@zekiz774 14 часов назад
It does. Have you not watched the video?
@Durayne
@Durayne 13 часов назад
​@@zekiz774 I was talking about C. Which the autor clearly was referring to.
@xcoder1122
@xcoder1122 13 часов назад
@@Durayne You mean for "primitive" types (the types in the video where Integer types, but they were objects, not primitives). But that's another weakness of Java. There shouldn't even be primitive types. Under the hood, a language may cheat as much as it likes but at least to the programmer it should be consistent. In SmallTalk everything is an object but that's a lie. SmallTalk only pretends everything is an object. In actual SmallTalk implementations not everything is an object but the language just hides that fact from you as a programmer. Similar with Swift: In Swift all simple numbers can be used just as if they were complex data types; the compiler will in fact often just store them as primitives in the compiled code, even in CPU registers when possible, but it will store them as object-like types whenever required. Java could just made "a == b" to mean "a.equals(b)" after compilation in case a and b are objects, it could compare them just as it does today in case they are primitives and it could just box/unbox automatically if one is a primitive and one is an object (if the object can be unboxed, do that, otherwise box the primitive and use equals()). This would not have required any change to the Bytecode specification at all and thus would not have affected interpreters or JIT compilers. This would only be a change to the Java compiler (javac), after all Java is fully type-safe and the compiler knows the type of every variable and return value at compile time, so it would always know how to compile == according the rules I just specified.
@kellervfx629
@kellervfx629 День назад
Fuck Java.
@dewmi4403
@dewmi4403 День назад
Deep but not much to dive in 😺👍🏻
@Z3rgatul
@Z3rgatul День назад
Lmao, and ppl are bitching JavaScript 🤣
@russianyoutube
@russianyoutube День назад
Maybe don't use Integer and just use int?
@Fasteroid
@Fasteroid День назад
Disgusting. Java is gross.
@juliantheivysaur3137
@juliantheivysaur3137 День назад
Why is Integer an object anyways? What functionality would be lost by using a primitive value?
@bytepint
@bytepint День назад
Integer (or other wrapper classes) are very much required for certain reasons, for example if I fetch data from DB and certain (integer) column is blank then I don't think representing it as '0' or '-1' is a good idea, in that case Integer is required so that we can represent it as null (primitive can't have null values). 2nd. In Java generics (which is powerful feature of Java), primitive can't be used.
@no_nuts0614
@no_nuts0614 День назад
Why is there an object for an int
@you_are_the_best2233
@you_are_the_best2233 День назад
Primitives can't be used as generic types so these wrapper classes were created.
@Abc-jq4oz
@Abc-jq4oz 19 часов назад
Why primitives can’t be used as generic types?
@you_are_the_best2233
@you_are_the_best2233 19 часов назад
@@Abc-jq4oz If I remember correctly during compilation generic type provided is swapped to Object. Object is base class for everything in Java. Everything except primitives such as int or byte. Because of this caveat you have to use objects like Integer. If you want more in depth explanation search this topic on the net. There are more wierd things with generics in Java. For example you can't create generic arrays.
@2wheels2
@2wheels2 День назад
this is y i dont like an abstracted lang like java. then again i dont like the 0xffffffff times my program segfaults cuz a pointer was freed with new address 0x01 instead of NULL in c
@HansBezemer
@HansBezemer День назад
Actually - according to the standard _free()_ does *NOT* update your pointer. You have to reassign your pointer yourself when you want to check its value later on. And that's a good practice.
@2wheels2
@2wheels2 День назад
@@HansBezemer i was making a screen saver for fun and i had to deal with the pointer pointing to 0x01 instead of 0x00 or null and it is weird cuz i set the pointer to be equal to NULL after free too. the "fix" was to not have the condition be pointer != NULL but pointer >= (illigalPageSize) 0x1000
@Kagmajn
@Kagmajn День назад
Good to be aware of that. My 1st lessons with Java were learning how to compare objects and primitives, and our teacher told us about ".equals()" and "instanceof". Cool video!
@kyleeames8229
@kyleeames8229 2 дня назад
WTF!? Is this really a problem in Java?? That’s a failure in basic functionality. Why do people use this language?
@bytepint
@bytepint День назад
Well every language has some quirky behavior, otherwise Java is really powerful language.
@earth2k66
@earth2k66 День назад
Still better than the mess they call JavaScript, especially on the backend nowadays.
@itsahandle
@itsahandle День назад
I bet you're a python programmer
@1creeperbomb
@1creeperbomb 2 дня назад
"OOP will be the future" -- Oracle probably
@Andreas_Mann
@Andreas_Mann 14 часов назад
not an oop issue
@gorlix
@gorlix 2 дня назад
what is the point of having Integer class? this seems like such a bloat
@bytepint
@bytepint День назад
cuz Object-Oriented Programming ;) Well, Integer (or other wrapper classes) are very much required for certain reasons, for example if I fetch data from DB and certain (integer) column is blank then I don't think representing it as '0' or '-1' is a good idea, in that case Integer is required so that we can represent it as null (primitive can't have null values). 2nd. In Java generics (which is powerful feature of Java), primitive can't be used.
@Z3rgatul
@Z3rgatul День назад
C# (which was based on Java) implement this differently, and there is no Integer class, only primitive type. And everything works fine.
@marcoaureliofernandezreyes1413
C# is better. What a headache is java, tbh.
@baconboyxy
@baconboyxy 4 часа назад
Yea c# you can just add a ? to the data type to make it nullable and generics don’t have this constraint
@cmyk8964
@cmyk8964 2 дня назад
Python has similar behavior! Integers from 0 to 255 and (if I recall) -1 to -4 get cached, so any instance of 255 `is` 255, but multiple instances of 256 may not be true when compared with `is` and not `==`.
@Walter_
@Walter_ 2 дня назад
"is" is used for checking same object pointer. "==" is used for checking contents. In 9/10 cases you want to use "==".
@williamdrum9899
@williamdrum9899 День назад
@@cmyk8964 This behavior feels more like a bug rather than a feature. If I'm using a language like Java or Python, it's clear that I don't want to deal with pointers.
@HansBezemer
@HansBezemer День назад
@@williamdrum9899 Agreed - if you create a language with the intention that any idiot can use it, "because it's safe", this kind of behavior is unacceptable - for it violates the primary design objectives. Now I don't mind languages that require you to know what's under the hood in order to do some useful work with it. That's why I (personally) like C and Forth. What I absolutely hate, though, is "simple languages" that do lots of stealthy transformations and conversions behind the curtains in order "to make it simple", but by doing so open up gaping holes every unaware programmer falls into. Which is not that bad when those things are caught early enough, but devastating when left undetected. I think that language designers should refrain from implementing these "hidden" conversions and design a language that does what it says it does. Sure, it's cool you can do *"A$ == A"* and simply transform the string to an integer, but what you're actually doing is supporting bad habits. Programmers need discipline - especially when they're actually noobs (you can give a true professional a language like C and it'll work out fine).
@minhnguyenphanhoang4193
@minhnguyenphanhoang4193 День назад
​@@williamdrum9899You normally don't use it at all. Only for things like None object but you can also just use ==
@largewallofbeans9812
@largewallofbeans9812 День назад
In python, they make it pretty clear that “is” compares references so I don’t think you could call this “similar behavior”.
@Gigasharik5
@Gigasharik5 2 дня назад
because java sucks
@bytepint
@bytepint День назад
😅
@russianyoutube
@russianyoutube День назад
Pretty sure python does a similar thing too lol
@baconboyxy
@baconboyxy 4 часа назад
In python == checks for equality (including for strings) and “is” checks for reference (pointer location). So, this isn’t usually a problem in python unless you are writing custom objects you need to compare, then you need to build your own comparison (ex based on their attributes) anyway.
@williamdrum9899
@williamdrum9899 2 дня назад
Doesn't Python do the same thing?
@bytepint
@bytepint День назад
Yes, see reply comment of @cmyk8964
@largewallofbeans9812
@largewallofbeans9812 День назад
No. Python supports operator overloading, so A == B is defined by a method of type(A). You may be thinking of the “is” operator, which always and only compares references.
@martinschroederglst
@martinschroederglst 2 дня назад
Operator overloading doesn't sound like a bad idea now, huh?
@friedrichmyers
@friedrichmyers 3 дня назад
Lmao that's why I'm still on C. But I like Java too.
@zanagi
@zanagi 2 дня назад
Im even a c++ user, and damn this Java is not an honest language lol
@friedrichmyers
@friedrichmyers День назад
@@zanagi Yeah. I liked C++, coming from C but the problem with it is that the learning curve is a lot high. I've met people who write blackmagic C++ and it fucks up the code. But who gives a fuck when you can have Aesthetic "std::views::iota<<unique_ptr!!:::af>> new" instead of just writing shit in the way that makes sense.
@HansBezemer
@HansBezemer День назад
@@friedrichmyers C++ was created to avoid common bugs and make software more solid by adding lots of features to 'automate' things. They made programmingso easy that nobody has a clue what they're doing. C++ (and Java) are the perfect examples of missing your original design objectives by a mile.
@blackscrow
@blackscrow День назад
​@@friedrichmyers well to use C++, you don't need to use that "black magic" stuff though... just use the features you want to use, and you can still write in C for the rest
@AKA-077
@AKA-077 День назад
Try c#
@larvajoke4255
@larvajoke4255 4 дня назад
It is possible in c++
@bytepint
@bytepint 4 дня назад
In c++ afaik there is not concept of Integer caching and autoboxing hence behaviour is different.
@UltraAryan10
@UltraAryan10 3 дня назад
​​@@bytepintEven if there was, the concept of operator overloading to get desired behaviour is common in C++. You can also already check if two objects are same kindof with &a == &b
@DHARMA252
@DHARMA252 4 дня назад
I kinda knew it but thanks man. There's never enough knowledge about something.
@bytepint
@bytepint 4 дня назад
Yes 😄
@21k60
@21k60 5 дней назад
Nice🎉🎉🎉🎉
@dhineshd94
@dhineshd94 5 дней назад
nice bro i always use equals method for comparing 2 strings... now got some info
@bytepint
@bytepint 5 дней назад
Thanks bro. Yes, Make a thumb rule. If primitive then == Anything else .equals no matter what.
@williamdrum9899
@williamdrum9899 День назад
@@bytepint "Primitive" being anything like your typical C numeric types, char, short, int, long, float, double. Just checking to see if I understand
@bytepint
@bytepint День назад
Yes Primitives are : all you mentioned + byte.
@bhimesh99
@bhimesh99 5 дней назад
Nice
@SoumendraHarichandan
@SoumendraHarichandan 6 дней назад
Nice animations and explanation. Keep it up!
@FaizanFurqan034
@FaizanFurqan034 6 дней назад
👍
@DeanBeckerdjbckr
@DeanBeckerdjbckr 6 дней назад
Well.... when comparing objects, you are supposed to use the .equals() method. This is the ONLY way to test the equality of objects. You can use == ONLY on primitive types.
@bytepint
@bytepint 6 дней назад
Yes, that is the rule: always use .equals() for object equality checks. The goal of this video was to educate. Even if == sometimes gives the correct result, it should not be made standard practice. For example, if you create two strings like String a = "Hello"; String b = "Hello";, both a == b and a.equals(b) will always give the correct result no matter what. However, in real-world scenarios and more complex repositories, we cannot be certain. Let's say someone somewhere creates String c = new String("Hello");, then most probably == will fail. Therefore, to prevent any mishaps, do not use the == operator for object content comparison. cheers!
@mr.rabbit5642
@mr.rabbit5642 3 дня назад
I reckon there's a safer option with static method Object.equals() that takes two arguments instead. It won't derp out with a NullPointerException
@bytepint
@bytepint 3 дня назад
@@mr.rabbit5642 Yes there is java.util.Objects.equals() for null safe and deepEquals for checking arrays equality.
@MortvmMM
@MortvmMM 3 дня назад
I mean sorry, if the Integer class has not yet overriden the == operator, that's not the users problem. Gezus how is Java so behind??
@DeanBeckerdjbckr
@DeanBeckerdjbckr 3 дня назад
@@MortvmMM You indeed bring up a good point. The designers behind Java are highly reluctant to change behavior like you suggest, so it stays that way. And this brings up the reason for languages like Groovy, Scala, and most recently Kotlin. You can design your own operators on any class to behave the way you think it should be.
@AswinS-l6u
@AswinS-l6u 7 дней назад
good explanation
@bytepint
@bytepint 7 дней назад
Thanks brother!
@surajupadhyay8111
@surajupadhyay8111 Месяц назад
Make more videos on such topics..... groupingBy, Collectors etc
@From_amu_kitchen
@From_amu_kitchen Месяц назад
C