Monday, 7 April 2014

Java Primitive Data Types - Default Values

TARGET LANGUAGE:JAVA

THEORY:(DATA TYPE:Default Values)

  • Java primitive data types are initialized to some default values when they are declared as class members.
  • While programming in Java you declare and use variables at two places.
  • First, inside a function those are local to that function.
  • And second, as a class member. When a variable is declared local to a function it must be initialized or assigned before its first use otherwise compiler reports an error "variable <variable name> might not have been initialized". But when a variable is declared as a class member or field, it is not always essential to assign a value to the member.
  • In that case class members are initialized to some default values by the compiler. However, leaving class members uninitialized is not considered a good practice.
  • The following table lists the default values for the data types shown in Table 1.
  •  

No comments:

Post a Comment