8 Replies Latest reply on Oct 20, 2009 4:53 AM by 3004

    do java primitives have defualt values

      I am trying to determine if java primateives (like an int) have default values.

      On sun's web page I read this:

      "It's not always necessary to assign a value when a field is declared. Fields that are declared but not initialized will be set to a reasonable default by the compiler. Generally speaking, this default will be zero or null, depending on the data type. Relying on such default values, however, is generally considered bad
      programming style." http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html

      Yet, when I declare an int and then try to print it, I get a compiler error if I do not set a value to that int.

      So, I know this is bad programming, but I am just wondering which way it is. Are there default values or not?