Java does not support garbage values. An unassigned local variable gives compilation error and an instance (global) variable takes a default value. Following program illustrates the default values given by JVM for unassigned instance variables.
String is not a data type. If not assigned, String takes null as the default.
public class DataTypeDefaults
{
byte byteValue;
short shortValue;
int intValue;
long longValue;
float floatValue;
double doubleValue;
char charValue;
boolean booleanValue;
String stringValue;
public static void main(String args[])
{
DataTypeDefaults dtd = new DataTypeDefaults ();
System.out.println("byte default value: " + dtd.byteValue);
System.out.println("short default value: " + dtd.shortValue);
System.out.println("int default value: " + dtd.intValue);
System.out.println("long default value: " + dtd.longValue);
System.out.println("float default value: " + dtd.floatValue);
System.out.println("double default value: " + dtd.doubleValue);
System.out.println("char default value: " + dtd.charValue);
System.out.println("boolean default value: " + dtd.booleanValue);
System.out.println("String default value: " + dtd.stringValue);
}
}
Observe the screenshot on Data Types Default Values Java. The default values for whole numbers is 0, for floating-point numbers is 0.0 and for primitive data type boolean it is false. String takes null and char does not print any value. Actually, it prints a value equivalent to Unicode value of /u0000 which prints nothing.
Plz any one tell me default value for global char variable??
Refer this link:
http://way2java.com/java-introduction/data-types-default-values-no-garbage/
Please, Can you also include the default values of StringBuffer and StringBuildert?
The default size of the buffer is sufficient to accommodate 16 characters.
please explain non-primitive data type on java?
non-primitive data type is nothing but reference variables like : Demo d1;
Think you sir for your guidence. I like your explanation with simple example, which i understand very fast and remember it easilly.
thank you! thank you!! thank you!!!
Thank you so much sir this website is very nice…and it is very useful to me….if you can possible please post j2ee also sir
sir ,this website is very useful for us .i have sugested this website to many and all are saying so.
Hello Siva,
Thanks. It is my pleasure sharing the knowledge.
sir ,this website is very useful for us .i have sugested this website to many and all are saying so.
sir one more thing can u upload the same kind of website for c and c++ also
This is my best Java site, you are number one. I cant stop reading.
We can write a book.
This site is very helpful for us to learn everything very easily Sir.Thank you for developing such a nice site.Thanks alot Sir.
Hello,
Thanks.
S N Rao