Effective Java - Still Effective After All These Years
ฝัง
- เผยแพร่เมื่อ 26 ส.ค. 2024
- Joshua Bloch serves up a few Java Puzzlers as an appetizer before and as dessert after the main course on Effective Java.
Organized By: Silicon Valley Web JUG - Van Riper and Kevin Nilson
Hosted and Sponsored By: Google
Video By: Marakana
Event: www.meetup.com/...
Slides: files.meetup.co...
Gotta love the THC joke @ 36-37. This man is a true inspiration.
"misteaks" lol, this guy is a genius
He's a very good orator who has a descent sense of humor.
the #2 returns 1 since the caching is there from -128 to 127. if we change the numbers in the string array from 129 to 133, then we will get -2 as the result while searching for 130
I don't like PECS because Producer/Consumer paradigm is confusing (what's pushAll, it produces into the stack but consumes from the array, which is it???). I like GESS (as in 'guess' more) which stands for Getter-Extends (i.e. the function that gets stuff from data structure arg you pass in uses Extends) and Setter-Super (i.e. the function that sets stuff inside the passed data structure uses Super).
The temperature example at 43:32 is not polymorphic and violates the Open/Closed Principle (OCP). If you add a new unit such as Kelvin, you have to change the already existing class to include a new option into an if or switch statement. In fact, it would be better to have a class Celsius and classes Fahrenheit and Kelvin that can convert from Celsius.
Why would I do that, isn't a single parameter of enum type handle that?
Enlightening...Engaging...Effective !!
Thank You !!
Thanks for sharing!
Very interesting Video, I am loving it.
Thanks, very interesting.
Your Books are great .
Awesome!
This is great!
one of the best
Interesting what he is saying about the serialization proxy. He explained it well. But, would that pattern still be useful in 2015?
14:30 The second question answer is wrong (nowadays). It returns 1, the answer is b. I think the valueOf method has changed since the video, and now it caches them instead of creating new Integers, as long as the Integer value is between -128 and 127. This integer creation from cache works with literals too, like Integer i = 127; (is cached) and Integer j = 128; (is not cached) With two integers compared with == where it's created with 127 it is the same integer and returns true. While with 128 it returns false.
So with that code it returns 1, and answer b is correct. If Integer.valueOf(s) is replaced with new Integer(Integer.parseInt(s)) It will still return -2, as in the video.
Also, the best compare method imo is return i - j;
Here it is obvious you are comparing their values, because it's a subtraction, and you dont need any if statements or ternary operators, or additional variables. The returned value doesn't have to be -1, 0 or 1, just that it's negative, 0 or positive. Very simple.
10:36 Is where the human brain forks a new thread to do a physical maneuver and the original thread blocks and then continues.
For the third puzzler I would have used Integer#compareTo(Integer).
Isn't putIfAbsent ok to use, if you want to gather stuff without returning it right away?
is threre only one video?
Java is the future COBOL, which is good. Please discuss.
super!
The more I learn about Java, the less the hate on it is justified. But it will prolly continue since they're king of the mountain (#1 tiobe this year), and likely will be for years/decades to come.
Hm, example #2 from 11:20 is incorrect. It actually works as expected (tested even on JDK6U45), because of Integer class caches the values from -127 to 128 by default. The return value will be 1.
public static Integer valueOf(int i) {
if(i >= -128 && i
Your suggestion of continuing using reference comparison is dangerous. It explicitly exposed your code a the mercy of platform changes of which outside our control.
We all strive for code that clearly works not merely works.
Woooosh
While Python generally leads to more compact code, it certainly is not faster than Java if equal care is taken with regards to performance. Most of the time it will be a lot slower than Java, occasionally a little faster in special cases.
Why is he, not using Externalize instead if using Serialization proxy ?
who can tell me why the result of the second puzzle is -2 ? i runed the demo , it truns out to be 1 . i really wanted to know why ! tks advance !!
Same problem,I think, maybe we use the different JDK version.The video is Uploaded on Oct 22, 2009. JDK 7 is released at July 28, 2011.
Wen er The problem is because of the Integer constant pool in Java. In most implementations Integers between -128 to 127 are stored in the pool, so there is only one instance each of them. If you change 1 to 1000, 2 to 2000 etc. and pass 1000 as a binarySearch parameter in the code snippet you'll get expected -2 output.
Jakub Hruby tks ! i've checked the source code , u r right .
Wen er
"HTML5" only. Oy vey.
Jakub Hruby that's correct, thanks.
Aaaaand what programming lang. you are using? :)
@avafanasiev it's noisy sound I ment
非常好
Anyone here in 2020???
He missed the best fix for Searching for the One (18:00) by a mile. It is:
return i - j;
What if it was a long or a double.
FeLiNe418 That would make no difference at all. Why do you think it would?
Jim White What is ( 1/10f * 1/3f * 3 ) - 1/10f according to your compiler?
Regardless, it was typed for Integer and your trick would've worked in this case.
shirankao69 It is not a "trick". The definition of Comparable and thus compareTo is directly derived from the mathematical concept of subtraction. The convoluted analysis and solution that Bloch goes through shows he misses this fundamental idea. And the solution for floating types is Math.sign(i - j).
Jim White No it isn't and you haven't answered my question.
Yesp.
I watched this, I must go and flex my pecs😝
I bet it was a...... Mistake
YYYYEEEEEEEEAAAAAAAAAAAAAAAAAAAHHHHHH
Sorry, but those little dots are NOT all the same color! Are you messing with people? ;)
Duh. Of course it was a joke you silly billy. :)
Kinda sad somebody actually started trolling here.
Wanting me to grow up? Why should I grow up if I'm 13?? A Spammer is a harder than you thought actually. Try yourself boy. Also. Some respect please :)
c# fanboy
If Java is so bad and you're so smart; feel free to invent your own language. Until you've done that please be quiet.
this guy dances way too much
i hate seeing all these heads. its annoying.
Ahah, 13 and smarter than you, and it feels funny. I can make other programs in C++ more than your Hello Worlds. I made a spammer. But, the only thing I told you was winky tinkys are people that can't accept other languages that C++. Just cause you've been told that it's the best. So for you C++ is a god.
讲的啥,感觉完全听不懂啊,英文太垃圾了我