{"id":73,"date":"2006-02-24T23:17:00","date_gmt":"2006-02-25T04:17:00","guid":{"rendered":"http:\/\/www.toomik.net\/helen\/wordpress\/?p=73"},"modified":"2006-02-24T23:17:00","modified_gmt":"2006-02-25T04:17:00","slug":"impressions-of-java-boxing-and-unboxing","status":"publish","type":"post","link":"https:\/\/www.toomik.net\/helen\/blog\/2006\/02\/24\/impressions-of-java-boxing-and-unboxing\/","title":{"rendered":"Impressions of Java: boxing and unboxing"},"content":{"rendered":"<p>It&rsquo;s interesting to put Java and .NET side by side. .NET has been described as Microsoft&rsquo;s attempt to beat Java at its own game, and even as &ldquo;Java done right&rdquo;. The designers of the .NET framework and the Common Language Runtimes could look at Java and see what worked and what didn&rsquo;t, and learn from it.\n<\/p>\n<p>\nSomething that I think Microsoft got right with .NET is <b>making everything an Object.<\/b><br \/>\nIt&rsquo;s like whoever wrote Java thought that object-orientation is good, but didn&rsquo;t quite dare to go all the way. Or perhaps (and more likely) it&rsquo;s historical baggage again&#8230;. Java&rsquo;s distinction between primitive types and their Object equivalents, such as <a href=\"http:\/\/mindprod.com\/jgloss\/intvsinteger.html\">int and Integer<\/a>, is the most obvious example. ints are for simple maths but they cannot be put in Collections &ndash; you need an object for that. On the other hand, you cannot just add two Integers. And each boxing\/unboxing requires an explicit instantiation of a new object. It all adds up to a whole lot of code that just juggles data types.\n<\/p>\n<p>\nThat&rsquo;s being changed in Java 5, but they still appear to be doing some sort of halfway fix. Just reading the Immutable Objects section in <a href=\"http:\/\/today.java.net\/pub\/a\/today\/2005\/03\/24\/autoboxing.html\">this overview of boxing in J2SE 5.0<\/a> makes me nervous.\n<\/p>\n<p>\n<a href=\"http:\/\/msdn.microsoft.com\/msdnmag\/issues\/1200\/dotnet\/\">In .NET, on the other hand, the Int32 data type is a full and proper Object.<\/a> It&rsquo;s a value type and lives on the stack, but you can still treat it as an object. Boxing is still necessary, but is almost invisible. Very smooth, very elegant.\n<\/p>\n<p>\nYou could argue that this is just hiding the details from the user, and leads to less efficient code. An invisible boxing requires as much resources as a visible one. But for most apps, differences of 15 ms are really not important, and developer time costs more than processor time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s interesting to put Java and .NET side by side. Something that I think Microsoft got right with .NET is <b>making everything an Object.<\/b><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-geeky_things"],"_links":{"self":[{"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":0,"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.toomik.net\/helen\/blog\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}