tag:blogger.com,1999:blog-8712770457197348465.post2858102625588823410..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: What is Autoboxing and Unboxing in Java ? Example, Tutorial and Corner casesjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-8712770457197348465.post-2340395301459750682015-09-25T08:53:34.507-07:002015-09-25T08:53:34.507-07:00How java provide the facility about autoboxing?How java provide the facility about autoboxing?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-48242268198881011622014-11-18T05:57:24.143-08:002014-11-18T05:57:24.143-08:00Your 1) Comparing Objects with equality Operator e...Your 1) Comparing Objects with equality Operator example is not appropriate in this context.<br />we already know comparing two objects(using == operator) created using new operator will never evaluate to true. Instead you should use something like this :<br /><br />int a = 1;<br />int b = 1;<br />compareInt(a,b);<br /><br /><br />private static void compareInt(Integer a, Integer b) {<br /> <br Kunal Krishna https://www.blogger.com/profile/06202237214255825462noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-71549394334405367352014-09-14T23:47:29.759-07:002014-09-14T23:47:29.759-07:00int x = 123;
long y = x;
In the above cases auto...int x = 123;<br /><br />long y = x;<br /><br />In the above cases autoboxing/unboxing happens ? Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-13573301861093338522013-09-22T06:47:15.930-07:002013-09-22T06:47:15.930-07:00sum = sum.intValue() + i;
Integer sum = new Intege...sum = sum.intValue() + i;<br />Integer sum = new Integer(result); <br /><br />- Based on the javadoc, i think it would be something like (difference is valueOf caches the frequently used value)<br /><br />sum = sum.intValue() + i;<br />Integer sum = Integer.valueOf(result); <br />ramyahttps://www.blogger.com/profile/06444227522227521332noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-67030996138864503862013-08-15T00:48:10.680-07:002013-08-15T00:48:10.680-07:00Hi Javin,
Confirm, if autoboxing and unboxing are ...Hi Javin,<br />Confirm, if autoboxing and unboxing are compile time process, rather than run time.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-42239189305149365192013-04-14T11:45:11.531-07:002013-04-14T11:45:11.531-07:00Hi Javin
Can you plz explain why it is true in 1s...Hi Javin<br /><br />Can you plz explain why it is true in 1st case ?<br />Integer i = new Integer(1);<br />Integer j = new Integer(1);<br />System.out.println("Print value "+(i <= j && i >= j && i != j) ); //true<br />System.out.println("Print value "+(i < j && i > j && i != j) ); //falseAnonymoushttps://www.blogger.com/profile/15505943587709906730noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-51345825786093310272013-04-07T20:46:25.779-07:002013-04-07T20:46:25.779-07:00One of the worst thing about Autoboxing in Java is...One of the worst thing about Autoboxing in Java is NullPointerException. If you have method which returns int by converting Integer to int, then it throws NullPointerException, when corresponding integer is null. It would have been much better to return zero rather than throwing exception. here is an example to watch<br /><br />public int getCount(String key){<br /> Integer value = cache.get(Bhimaninnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-41280430169102806492013-01-10T08:04:49.489-08:002013-01-10T08:04:49.489-08:00Thanks for the insight on autoboxing & unboxin...Thanks for the insight on autoboxing & unboxing..<br /><br />Anonymoushttps://www.blogger.com/profile/13803056408299207262noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-15899272336489928142012-07-25T06:29:22.614-07:002012-07-25T06:29:22.614-07:00Yes you are right, since both variables are pointi...Yes you are right, since both variables are pointing to object it was simple Object comparison without any autoboxing.Javin @ transient variable javahttp://javarevisited.blogspot.sg/2011/09/transient-keyword-variable-in-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-89572569606688194132012-07-25T06:06:26.123-07:002012-07-25T06:06:26.123-07:00Np.you say there:
'It will print "Both o...Np.you say there:<br /><br />'It will print "Both one are not equal" because of no autoboxing'<br /><br />but they are already objects....so perhaps you ment autounboxing....or something else.micheehttps://www.blogger.com/profile/05937230965190972040noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-29966017112291473472012-07-25T05:58:23.560-07:002012-07-25T05:58:23.560-07:00Ahh, Sorry for extra 't' :), michee whole ...Ahh, Sorry for extra 't' :), michee whole point is to stress that avoid autoboxing while using == operator because it can confuse you if you are using it carelessly.Javinnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-9844665078997432692012-07-25T05:44:39.457-07:002012-07-25T05:44:39.457-07:00i still don't get it....What's the point i...i still don't get it....What's the point in talking about 'autoboxing' when you already have 2 objects (not primitives) and you compare them via equal?micheehttps://www.blogger.com/profile/05937230965190972040noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-39372157332833648932012-07-24T07:40:10.969-07:002012-07-24T07:40:10.969-07:00Hi Michee, I have updated autoboxing article to ma...Hi Michee, I have updated autoboxing article to make that point more explicit. On your second question if one of the member is primitive than unboxing of other member is occur.<br /><br />JavinJavin @ FIX protocol tutorialhttp://javarevisited.blogspot.sg/2011/04/fix-protocol-tutorial-for-beginners.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-48088416379140580992012-07-24T05:42:50.715-07:002012-07-24T05:42:50.715-07:00what if one of the members of == is a primitive an...what if one of the members of == is a primitive and the other an object? Is there any auto-un/boxing?micheehttps://www.blogger.com/profile/05937230965190972040noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-88077179775103958462012-07-24T05:37:08.917-07:002012-07-24T05:37:08.917-07:00i don't understand:
' It will print "...i don't understand:<br />' It will print "Both one are not equal" because of no auto boxing" '<br />makes no sense to me....micheehttps://www.blogger.com/profile/05937230965190972040noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-88241099867109939212012-07-22T14:43:43.306-07:002012-07-22T14:43:43.306-07:00Boxing was introduced in Java after C# had include...Boxing was introduced in Java after C# had included it. This is a nice feature for development but, as you stated, not to be overlooked in deployment due to performance issues i.e. too much memory being consumed. Another issue, along the same lines is String versus StringBuffer. The append method of the latter really helps to cut down on the memory consumption and duplication process that Andreashttp://www.hartmannsoftware.comnoreply@blogger.com