<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3071587328915252663</id><updated>2011-11-29T01:50:56.574-08:00</updated><category term='appletv'/><category term='video'/><category term='enum'/><category term='autoboxing'/><category term='canon'/><category term='sd600'/><category term='java'/><category term='types'/><category term='programming'/><category term='enumerated'/><title type='text'>Mark's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://boyns.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://boyns.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>boyns</name><uri>http://www.blogger.com/profile/01046512192568870231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3071587328915252663.post-8885848171663014594</id><published>2008-03-12T09:54:00.000-07:00</published><updated>2008-03-12T11:07:26.840-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='enum'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='types'/><category scheme='http://www.blogger.com/atom/ns#' term='enumerated'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Java 1.5 Explained - Enum</title><content type='html'>Before Java 1.5, you'd probably write code like the following to implement enumerated types, similar to how it would be done in C using #define:&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;public final static int SUIT_CLUBS = 1;&lt;br /&gt;public final static int SUIT_DIAMONDS = 2;&lt;br /&gt;public final static int SUIT_HEARTS = 3;&lt;br /&gt;public final static int SUIT_SPADES = 4;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Sure this is a little better than #define, but not much better.  Java 1.5 enumerated types are similar to what's available in C++.  Here's a C++ example:&lt;br /&gt;&lt;span style="font-family:monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;blockquote&gt;enum Suit {&lt;br /&gt; CLUBS = 1,&lt;br /&gt; DIAMONDS = 2,&lt;br /&gt; HEARTS = 3,&lt;br /&gt; SPADES = 4&lt;br /&gt;};&lt;/blockquote&gt;In Java this would be:&lt;br /&gt;&lt;blockquote&gt;enum Suit {&lt;br /&gt; CLUBS(1),&lt;br /&gt; DIAMONDS(2),&lt;br /&gt; HEARTS(3),&lt;br /&gt; SPADES(4)&lt;br /&gt;};&lt;/blockquote&gt;There's a subtle different between the Java and C++ syntax.  Java is using parens to initialize the individual enumerated type entries to a specific value.   What's really going on here?  Let's take a look a some byte code.&lt;br /&gt;&lt;br /&gt;First, here is a complete sample of some Java code using enum:&lt;br /&gt;&lt;blockquote&gt;public class Enum&lt;br /&gt;{&lt;br /&gt; public enum Direction { NORTH, SOUTH, EAST, WEST };&lt;br /&gt;&lt;br /&gt; public static void main(String[] args)&lt;br /&gt; {&lt;br /&gt;     Direction d = Direction.EAST;&lt;br /&gt;     System.out.println(d);&lt;br /&gt; }&lt;br /&gt;}&lt;/blockquote&gt;And the corresponding byte code:&lt;br /&gt;&lt;blockquote&gt;public class Enum extends java.lang.Object{&lt;br /&gt;public Enum();&lt;br /&gt;Code:&lt;br /&gt;0:    aload_0&lt;br /&gt;1:    invokespecial    #1; //Method java/lang/Object."&lt;init&gt;":()V&lt;br /&gt;4:    return&lt;br /&gt;&lt;br /&gt;public static void main(java.lang.String[]);&lt;br /&gt;Code:&lt;br /&gt;0:    getstatic    #2; //Field Enum$Direction.EAST:LEnum$Direction;&lt;br /&gt;3:    astore_1&lt;br /&gt;4:    getstatic    #3; //Field java/lang/System.out:Ljava/io/PrintStream;&lt;br /&gt;7:    aload_1&lt;br /&gt;8:    invokevirtual    #4; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V&lt;br /&gt;11:    return&lt;br /&gt;}&lt;/init&gt;&lt;/blockquote&gt;Look at line 0 in the main method.  The Direction enum is really a Java class (in this case an inner class within this Enum class example) and it has a static field named EAST.  Looking a little closer you can see that the field EAST is also Direction object.  That explains the reason for having the parens to initialize the enumerated value.  It's actually passing the value to a constructor.   Now here's the bytecode for the Direction class that was automatically created:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;public final class Enum$Direction extends java.lang.Enum{&lt;br /&gt;public static final Enum$Direction NORTH;&lt;br /&gt;&lt;br /&gt;public static final Enum$Direction SOUTH;&lt;br /&gt;&lt;br /&gt;public static final Enum$Direction EAST;&lt;br /&gt;&lt;br /&gt;public static final Enum$Direction WEST;&lt;br /&gt;&lt;br /&gt;public static final Enum$Direction[] values();&lt;br /&gt;Code:&lt;br /&gt;0:    getstatic    #1; //Field $VALUES:[LEnum$Direction;&lt;br /&gt;3:    invokevirtual    #2; //Method "[LEnum$Direction;".clone:()Ljava/lang/Object;&lt;br /&gt;6:    checkcast    #3; //class "[LEnum$Direction;"&lt;br /&gt;9:    areturn&lt;br /&gt;&lt;br /&gt;public static Enum$Direction valueOf(java.lang.String);&lt;br /&gt;Code:&lt;br /&gt;0:    ldc_w    #4; //class Enum$Direction&lt;br /&gt;3:    aload_0&lt;br /&gt;4:    invokestatic    #5; //Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;&lt;br /&gt;7:    checkcast    #4; //class Enum$Direction&lt;br /&gt;10:    areturn&lt;br /&gt;&lt;br /&gt;static {};&lt;br /&gt;Code:&lt;br /&gt;0:    new    #4; //class Enum$Direction&lt;br /&gt;3:    dup&lt;br /&gt;4:    ldc    #7; //String NORTH&lt;br /&gt;6:    iconst_0&lt;br /&gt;7:    invokespecial    #8; //Method "&lt;init&gt;":(Ljava/lang/String;I)V&lt;br /&gt;10:    putstatic    #9; //Field NORTH:LEnum$Direction;&lt;br /&gt;13:    new    #4; //class Enum$Direction&lt;br /&gt;16:    dup&lt;br /&gt;17:    ldc    #10; //String SOUTH&lt;br /&gt;19:    iconst_1&lt;br /&gt;20:    invokespecial    #8; //Method "&lt;init&gt;":(Ljava/lang/String;I)V&lt;br /&gt;23:    putstatic    #11; //Field SOUTH:LEnum$Direction;&lt;br /&gt;26:    new    #4; //class Enum$Direction&lt;br /&gt;29:    dup&lt;br /&gt;30:    ldc    #12; //String EAST&lt;br /&gt;32:    iconst_2&lt;br /&gt;33:    invokespecial    #8; //Method "&lt;init&gt;":(Ljava/lang/String;I)V&lt;br /&gt;36:    putstatic    #13; //Field EAST:LEnum$Direction;&lt;br /&gt;39:    new    #4; //class Enum$Direction&lt;br /&gt;42:    dup&lt;br /&gt;43:    ldc    #14; //String WEST&lt;br /&gt;45:    iconst_3&lt;br /&gt;46:    invokespecial    #8; //Method "&lt;init&gt;":(Ljava/lang/String;I)V&lt;br /&gt;49:    putstatic    #15; //Field WEST:LEnum$Direction;&lt;br /&gt;52:    iconst_4&lt;br /&gt;53:    anewarray    #4; //class Enum$Direction&lt;br /&gt;56:    dup&lt;br /&gt;57:    iconst_0&lt;br /&gt;58:    getstatic    #9; //Field NORTH:LEnum$Direction;&lt;br /&gt;61:    aastore&lt;br /&gt;62:    dup&lt;br /&gt;63:    iconst_1&lt;br /&gt;64:    getstatic    #11; //Field SOUTH:LEnum$Direction;&lt;br /&gt;67:    aastore&lt;br /&gt;68:    dup&lt;br /&gt;69:    iconst_2&lt;br /&gt;70:    getstatic    #13; //Field EAST:LEnum$Direction;&lt;br /&gt;73:    aastore&lt;br /&gt;74:    dup&lt;br /&gt;75:    iconst_3&lt;br /&gt;76:    getstatic    #15; //Field WEST:LEnum$Direction;&lt;br /&gt;79:    aastore&lt;br /&gt;80:    putstatic    #1; //Field $VALUES:[LEnum$Direction;&lt;br /&gt;83:    return&lt;br /&gt;}&lt;/init&gt;&lt;/init&gt;&lt;/init&gt;&lt;/init&gt;&lt;/blockquote&gt;There's a lot going on in Direction.  It's really just a bunch of code which could have been written by hand prior to Java 1.5, but now the compiler is doing all the work for us.  The code is basically doing this:&lt;br /&gt;&lt;blockquote&gt;public class Direction extends java.lang.Enum&lt;br /&gt;{&lt;br /&gt; public final static Direction NORTH;&lt;br /&gt; public final static Direction SOUTH;&lt;br /&gt; public final static Direction EAST;&lt;br /&gt; public final static Direction WEST;&lt;br /&gt;&lt;br /&gt; static&lt;br /&gt; {&lt;br /&gt;      NORTH = new Direction("NORTH", 0);&lt;br /&gt;      SOUTH = new Direction("SOUTH", 1);&lt;br /&gt;      EAST = new Direction("EAST", 2);&lt;br /&gt;      WEST = new Direction("WEST", 3);&lt;br /&gt;&lt;br /&gt;      VALUES = new Direction[4];&lt;br /&gt;      VALUES[0] = NORTH;&lt;br /&gt;      VALUES[1] = SOUTH;&lt;br /&gt;      VALUES[2] = EAST;&lt;br /&gt;      VALUES[3] = WEST;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/blockquote&gt;How about that?  All that code came from pretty much one line of code in Java 1.5.  Notice also that Direction extends a new class in Java 1.5, java.lang.Enum.  This new class is where the String and oridinal values for the enumerated type are stored.  Now you can see where the nice toString() comes from with enumerated types.  In our example above, the System.out.println(d) will print "EAST".  The Enum.ordinal() method can be used to get the ordinal value as well.&lt;br /&gt;&lt;br /&gt;There's a lot more you can do with enum, like add your own methods that will be included in the class that's automatically generated.  Please see Sun's &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html"&gt;Enum&lt;/a&gt; page for more information.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3071587328915252663-8885848171663014594?l=boyns.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boyns.blogspot.com/feeds/8885848171663014594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3071587328915252663&amp;postID=8885848171663014594' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default/8885848171663014594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default/8885848171663014594'/><link rel='alternate' type='text/html' href='http://boyns.blogspot.com/2008/03/java-15-explained-enum.html' title='Java 1.5 Explained - Enum'/><author><name>boyns</name><uri>http://www.blogger.com/profile/01046512192568870231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3071587328915252663.post-8646426792986171200</id><published>2007-12-21T10:38:00.000-08:00</published><updated>2007-12-21T11:47:28.913-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Java 1.5 Explained - Varargs</title><content type='html'>Varargs pretty much does what is sounds like, it adds variable number of arguments support to Java methods.  This is very similar to varargs in C and C++, but not exactly the same.  Since many Java developers come from C or C++ backgrounds, support for varargs has probably been one of the top most requested features over the years.  Along with varargs, Java 1.5 also added support for &lt;span style="font-style: italic;"&gt;printf&lt;/span&gt;.  I really haven't used &lt;span style="font-style: italic;"&gt;printf&lt;/span&gt; much since I just got used to appending strings together and/or using &lt;span style="font-style: italic;"&gt;StringBuffer&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;If you read my other blog entry about autoboxing, you'll remember that the Java compiler inserted some extra byte code to autobox and unbox primitive types.  Similar things are happing for varargs.  Let's look at some code:&lt;br /&gt;&lt;blockquote&gt;public class Varargs&lt;br /&gt;{&lt;br /&gt;    public void m(String...args)&lt;br /&gt;    {&lt;br /&gt;        System.out.println(args[0] + " " + args.length);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void main(String[] args)&lt;br /&gt;    {&lt;br /&gt;        Varargs v = new Varargs();&lt;br /&gt;        v.m("hi", "there");&lt;br /&gt;    }&lt;br /&gt;}&lt;/blockquote&gt;Above you'll see a method that takes a variable number of String objects and within the method you refer to the strings as if they were an array.  Well, it turns out they really are an array. So then the call to method m from main must also be doing some array stuff.  Let's take a look at the byte code:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-size:85%;"&gt; public void m(java.lang.String[]);&lt;br /&gt;  Code:&lt;br /&gt;   0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream;&lt;br /&gt;   3:   new     #3; //class java/lang/StringBuilder&lt;br /&gt;   6:   dup&lt;br /&gt;   7:   invokespecial   #4; //Method java/lang/StringBuilder."&lt;init&gt;":()V&lt;br /&gt;   10:  aload_1&lt;br /&gt;   11:  iconst_0&lt;br /&gt;   12:  aaload&lt;br /&gt;   13:  invokevirtual   #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;&lt;br /&gt;   16:  ldc     #6; //String &lt;br /&gt;   18:  invokevirtual   #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;&lt;br /&gt;   21:  aload_1&lt;br /&gt;   22:  arraylength&lt;br /&gt;   23:  invokevirtual   #7; //Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;&lt;br /&gt;   26:  invokevirtual   #8; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;&lt;br /&gt;   29:  invokevirtual   #9; //Method java/io/PrintStream.println:(Ljava/lang/String;)V&lt;br /&gt;   32:  return&lt;br /&gt;&lt;br /&gt;public static void main(java.lang.String[]);&lt;br /&gt;  Code:&lt;br /&gt;   0:   new     #10; //class Varargs&lt;br /&gt;   3:   dup&lt;br /&gt;   4:   invokespecial   #11; //Method "&lt;init&gt;":()V&lt;br /&gt;   7:   astore_1&lt;br /&gt;   8:   aload_1&lt;br /&gt;   9:   iconst_2&lt;br /&gt;   10:  anewarray       #12; //class java/lang/String&lt;br /&gt;   13:  dup&lt;br /&gt;   14:  iconst_0&lt;br /&gt;   15:  ldc     #13; //String hi&lt;br /&gt;   17:  aastore&lt;br /&gt;   18:  dup&lt;br /&gt;   19:  iconst_1&lt;br /&gt;   20:  ldc     #14; //String there&lt;br /&gt;   22:  aastore&lt;br /&gt;   23:  invokevirtual   #15; //Method m:([Ljava/lang/String;)V&lt;br /&gt;   26:  return&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;/blockquote&gt;The first thing to notice is that the method m does take a String[] as an argument.  That's what you would have normally used to pass a variable number of strings to a method.  Now the compiler is doing this for you.&lt;br /&gt;&lt;br /&gt;The next thing to notice is the byte code to call method m from main.  You'll see that it's actually creating a String[] of size 2 and assigning the string constants "hi" and "there" to elements 0 and 1 respectively.  That's really handy.  The compiler writes all the array code for you.&lt;br /&gt;&lt;br /&gt;One nice way to get used to programming with varargs is to start using the following:&lt;br /&gt;&lt;blockquote&gt;public static void main(String... args)&lt;/blockquote&gt;instead of:&lt;br /&gt;&lt;blockquote&gt;public static void main(String[] args)&lt;/blockquote&gt;String... and String[] are the same thing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3071587328915252663-8646426792986171200?l=boyns.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boyns.blogspot.com/feeds/8646426792986171200/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3071587328915252663&amp;postID=8646426792986171200' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default/8646426792986171200'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default/8646426792986171200'/><link rel='alternate' type='text/html' href='http://boyns.blogspot.com/2007/12/java-15-explained-varargs.html' title='Java 1.5 Explained - Varargs'/><author><name>boyns</name><uri>http://www.blogger.com/profile/01046512192568870231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3071587328915252663.post-7761780579496365643</id><published>2007-12-20T14:33:00.000-08:00</published><updated>2007-12-21T09:19:26.622-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='autoboxing'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Java 1.5 Explained - Autoboxing</title><content type='html'>Here's the start of a short series on how many of the new language features were added in in Java 1.5.   I'm going to start with Autoboxing.  Autoboxing is language feature that allows you to write code using primitive types where previously you had to use the object equivalent.  For example, the primitive type &lt;span style="font-style: italic;"&gt;int&lt;/span&gt; not the same as &lt;span style="font-style: italic;"&gt;Integer&lt;/span&gt;.  You can convert between the two manually but that can be cumbersome.  There's also extra code required when you're dealing with lists, sets, maps, etc., since you cannot store primitive types in collections.&lt;br /&gt;&lt;br /&gt;Let's look at some code:&lt;br /&gt;&lt;blockquote&gt;List&lt;integer&gt; list = new ArrayList&lt;integer&gt;();&lt;br /&gt;list.add(100); &lt;span style="font-style: italic;"&gt;// instead of list.add(new Integer(100)&lt;/span&gt;);&lt;/integer&gt;&lt;/integer&gt;&lt;/blockquote&gt;Adding a primitive &lt;span style="font-style: italic;"&gt;int&lt;/span&gt;  to a list is now super easy.&lt;br /&gt;&lt;br /&gt;So how is this actually working?  Primitive types are not magically objects in Java 1.5.  The 1.5 compiler is doing tricks behind the scenes to make writing code easier.  Let's take a look:&lt;br /&gt;&lt;blockquote&gt;        List&lt;integer&gt; list = new ArrayList&lt;integer&gt;();&lt;br /&gt;     list.add(100);&lt;br /&gt;     list.add(200);&lt;br /&gt;     int i = list.get(0);&lt;br /&gt;     Integer j = list.get(0);&lt;/integer&gt;&lt;/integer&gt;&lt;/blockquote&gt;&lt;integer&gt;&lt;integer&gt;This code adds two primitive ints to a list and then gets them in two different ways.   The compiler generates the following byte code:&lt;br /&gt;&lt;/integer&gt;&lt;/integer&gt;&lt;blockquote&gt;&lt;span style="font-size:85%;"&gt;   0:   new     #2; //class java/util/ArrayList&lt;br /&gt;3:   dup&lt;br /&gt;4:   invokespecial   #3; //Method java/util/ArrayList."&lt;init&gt;":()V&lt;br /&gt;7:   astore_1&lt;br /&gt;8:   aload_1&lt;br /&gt;9:   bipush  100&lt;br /&gt;11:  invokestatic    #4; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;&lt;br /&gt;14:  invokeinterface #5,  2; //InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z&lt;br /&gt;19:  pop&lt;br /&gt;20:  aload_1&lt;br /&gt;21:  sipush  200&lt;br /&gt;24:  invokestatic    #4; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;&lt;br /&gt;27:  invokeinterface #5,  2; //InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z&lt;br /&gt;32:  pop&lt;br /&gt;33:  aload_1&lt;br /&gt;34:  iconst_0&lt;br /&gt;35:  invokeinterface #8,  2; //InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;&lt;br /&gt;40:  checkcast       #9; //class java/lang/Integer&lt;br /&gt;43:  invokevirtual   #10; //Method java/lang/Integer.intValue:()I&lt;br /&gt;46:  istore_2&lt;br /&gt;47:  aload_1&lt;br /&gt;48:  iconst_0&lt;br /&gt;49:  invokeinterface #8,  2; //InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;&lt;br /&gt;54:  checkcast       #9; //class java/lang/Integer&lt;br /&gt;57:  astore_3&lt;/init&gt;&lt;/span&gt;&lt;/blockquote&gt;Interesting things start on line 11.  The compiler added some extra code to call Integer.valueOf(100) so the 100 value can be added to the list.  It's the same code you'd normally have to write yourself, but now autoboxing is doing it for you.&lt;br /&gt;&lt;br /&gt;Next look at line 35.  The generated code is calling the list &lt;span style="font-style: italic;"&gt;get&lt;/span&gt; method and returning an object.  The object is then cast to an Integer and the &lt;span style="font-style: italic;"&gt;intValue&lt;/span&gt; method is called to obtain the primitive type.  Again, it's the same code you'd have to write but you don't have to anymore.&lt;br /&gt;&lt;br /&gt;You can compare the byte code for the list.get(0) that returns and Integer.  It's the same byte code generated for autoboxing.&lt;br /&gt;&lt;br /&gt;You'll see there's some use of generics here since the list.get(0) doesn't have to do any casting to an Integer.  I'll cover generics in detail later.  That's about it for autoboxing.  Go back to enjoying using primitive types and not having to manually create all those Integer and Long objects.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3071587328915252663-7761780579496365643?l=boyns.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boyns.blogspot.com/feeds/7761780579496365643/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3071587328915252663&amp;postID=7761780579496365643' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default/7761780579496365643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default/7761780579496365643'/><link rel='alternate' type='text/html' href='http://boyns.blogspot.com/2007/12/java-15-explained-autoboxing.html' title='Java 1.5 Explained - Autoboxing'/><author><name>boyns</name><uri>http://www.blogger.com/profile/01046512192568870231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3071587328915252663.post-6211246166850566344</id><published>2007-12-10T22:07:00.000-08:00</published><updated>2007-12-20T15:10:34.629-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='video'/><category scheme='http://www.blogger.com/atom/ns#' term='canon'/><category scheme='http://www.blogger.com/atom/ns#' term='appletv'/><category scheme='http://www.blogger.com/atom/ns#' term='sd600'/><title type='text'>Convert Canon SD600 videos for the Apple TV</title><content type='html'>&lt;blockquote&gt;&lt;/blockquote&gt;The Canon PowerShot SD600 captures video in the following format:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;RIFF (little-endian) data, AVI, 640 x 480, 30.00 fps, video: Motion JPEG, audio: uncompressed PCM (mono, 11024 Hz)&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Note the fps and resolution can be changed within the camera video settings.&lt;br /&gt;&lt;br /&gt;Turns out the SD600 AVI files are not one of the Apple TV &lt;a href="http://www.apple.com/appletv/specs.html"&gt;supported video formats&lt;/a&gt;.   I've converted other AVI files to MPEG-4 for the ipod using &lt;a href="http://ffmpeg.mplayerhq.hu/index.html"&gt;ffmpeg&lt;/a&gt; so I decided to give that a whirl.  Some of the files worked while others would display an error in itunes about still not being a supported video format.  I read the Apple TV specs page again and noticed the bit about up to 3 Mbps.  I guess depending on the video content, ffmpeg was outputting a bitrate higher than 3 Mbps for some videos.  The following command is what finally worked for me.  You can see the -b option to specify desired bitrate.  The actual bitrate in the MPEG-4 files will vary.&lt;br /&gt;&lt;blockquote&gt;ffmpeg -i input.avi -f mp4 -r 30 -b 2Mbps -vcodec mp4 -acodec libfaac ouput.mp4&lt;/blockquote&gt;I've tried this on windows and linux.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3071587328915252663-6211246166850566344?l=boyns.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://boyns.blogspot.com/feeds/6211246166850566344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3071587328915252663&amp;postID=6211246166850566344' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default/6211246166850566344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3071587328915252663/posts/default/6211246166850566344'/><link rel='alternate' type='text/html' href='http://boyns.blogspot.com/2007/12/how-to-convert-canon-powershot-sd600.html' title='Convert Canon SD600 videos for the Apple TV'/><author><name>boyns</name><uri>http://www.blogger.com/profile/01046512192568870231</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
