August 17th, 2010
I can’t take credit for that title. Dondi sent it to me in an email. Not sure if he got it from anywhere, though. If he did, I’m sorry to be using it, but it makes perfect sense in the context of this post.
Anyway, Jacob posed this question (explained through a class) in Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| public class WTFInteger
{
public static void main(String args[])
{
Integer foo = 127;
Integer bar = 127;
System.out.println(foo + "," + bar); //127,127
System.out.println(foo <= bar); //true
System.out.println(foo >= bar); //true
System.out.println(foo == bar); //true
System.out.println(foo.intValue() == bar.intValue()); //true
System.out.println();
foo = 128;
bar = 128;
System.out.println(foo + "," + bar); //128,128
System.out.println(foo <= bar); //true
System.out.println(foo >= bar); //true
System.out.println(foo == bar); //false
System.out.println(foo.intValue() == bar.intValue()); //true
}
} |
A little test class and in the comments, the output from each evaluation. So what’s going on here? Auto unboxing seems to be going on for the comparison operations, but then why does the equality test pass in one instance but fail in another?
After some research, turns out that the object representation of primitives have a cache that acts kind like a String.intern(), meaning if you assign an Integer a value between a range (default for Integers [-128,127]), you end up getting the same object back, which is why the first (foo == bar) succeeds (value is 127) and why the second (foo == bar) fails (values are 128).
From the comments of the Integer class:
/**
* Cache to support the object identity semantics of autoboxing for values between
* -128 and 127 (inclusive) as required by JLS.
*
* The cache is initialized on first usage. During VM initialization the
* getAndRemoveCacheProperties method may be used to get and remove any system
* properites that configure the cache size. At this time, the size of the
* cache may be controlled by the vm option -XX:AutoBoxCacheMax=<size>.
*/
Tags: autoboxing, java, primitives
Posted in Uncategorized | 1 Comment »
May 21st, 2010
I am still heavy on my Python learning kick. One thing that’s always interested me is the Global Interpreter Lock and why Python doesn’t have “real” threading. I came across a talk given by David Beazley called “Mindblowing Python GIL” that was very informative. Pretty shocking really about how it works and very interesting. Obviously only watching this video would leave a bad taste in your mouth regarding Python and threading, so now I need to find another talk about why the GIL is good. There is a link in the comments to a slide show that talks about why it is good, but slides without the talk are almost useless for me.
Tags: gil, global interpreter lock, python, talk, threading, threads, video
Posted in Uncategorized | No Comments »
April 14th, 2010
An update to my previous post about setting up your own web server and using DNS to get your PS3 on the PSN with the old firmware: it seems as if Sony has “fixed” this little loophole that made our PS3s once again functional sometime yesterday (2010-04-14).
No word yet on re-enabling this feature without upgrading to the latest firmware.
Tags: dns, fail, firmware, firmware upgrade, hacks, playstation, playstation 3, psn, sony, upgrade
Posted in Uncategorized | No Comments »
April 7th, 2010
Sony, let me tell you something: this is one fight you cannot possibly win. You saw what happened with the PSP. People started releasing firmware hacks for it and after that, it was over. Removing a very useful feature, a feature that I’ve already paid for, is not a very wise move on your part. You’ve angered the same gods that brought down hellfire upon the PSP. Geohot has said not to upgrade because he is looking into a safe way of upgrading and not losing “Install Other OS.” Let’s hope that works out.
Read the rest of this entry »
Tags: dns, firmware, firmware upgrade, hacks, playstation, playstation 3, psn, sony, upgrade
Posted in Uncategorized | 2 Comments »
March 1st, 2010
Just a note: the Facebook Chat data in my post regarding configuration settings for Pidgin and Facebook Chat can be used in any chat client that can connect to XMPP. You just may have to play around with your settings to see what goes where.
Tags: facebook, facebook chat, setup, xmpp
Posted in Uncategorized | No Comments »
February 11th, 2010
Facebook, earlier this week, released their new XMPP Facebook Chat which now allows any XMPP-enabled chat client to connect to Facebook chat. For whatever reason I thought this was already how things were done, but I guess not. I just set this up with Pidgin and figured I’d share the information.
Read the rest of this entry »
Tags: facebook, facebook chat, setup, xmpp
Posted in Uncategorized | 1 Comment »
December 27th, 2009
Eclipse, for any Java developer, is a tool that is almost as essential for developing Java application as the Java docs itself. The compiler even. With its huge plug-in set and ability to do almost anything you want automatically, it is no surprise why you will probably find this IDE in where where Java is developed.
Then you start using it. One of my main complaints about Eclipse is that there is no way to export the color scheme in use without exporting with it other computer-specific settings. I don’t want to export which specific JRE location to use because it won’t be the same on a Mac and Windows. Nor do I want to export other settings, probably having to do with plugi-ns installed. And I especially don’t want another user’s recently used workspace locations. So what do you do?
Read the rest of this entry »
Tags: eclipse, IDE
Posted in Uncategorized | 2 Comments »
December 23rd, 2009
So, I’m starting this much sooner than I would have anticipated but I suddenly got the urge to start.
Problem 1 is pretty straight forward:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
Read the rest of this entry »
Tags: project euler, python
Posted in Uncategorized | 2 Comments »
December 20th, 2009
People who link to Facebook from Myspace and link to Myspace from Facebook.
Tags: random, social networking
Posted in Uncategorized | 1 Comment »
December 17th, 2009
About a year or so ago, I was told of this site, Project Euler. Unfortunately I didn’t get into it back then, but an email from a mailing list that I’m apart of re-sparked my interest in it. In case you haven’t heard of it before, here is the description of it from the site:
Read the rest of this entry »
Tags: development, math, project euler
Posted in Uncategorized | No Comments »