Shows default initial values : Primitive Data Type « Data Type « Java






Shows default initial values

Shows default initial values
     

// : c04:InitialValues.java
// Shows default initial values.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
public class InitialValues {
  boolean t;

  char c;

  byte b;

  short s;

  int i;

  long l;

  float f;

  double d;

  void print(String s) {
    System.out.println(s);
  }

  void printInitialValues() {
    print("Data type      Initial value");
    print("boolean        " + t);
    print("char           [" + c + "]");
    print("byte           " + b);
    print("short          " + s);
    print("int            " + i);
    print("long           " + l);
    print("float          " + f);
    print("double         " + d);
  }

  public static void main(String[] args) {
    InitialValues iv = new InitialValues();
    iv.printInitialValues();
    /*
     * You could also say: new InitialValues().printInitialValues();
     */
  }
} ///:~


           
         
    
    
    
    
  








Related examples in the same category

1.Use Integer constructor to convert int primitive type to Integer object.
2.Convert Java Integer object to Numeric primitive types
3.Convert Java String to Integer object
4.Create an Integer object
5.Arithmetic DemoArithmetic Demo
6.Max Variable Length DemoMax Variable Length Demo
7.Data Type Print TestData Type Print Test
8.Tests all the operators on all the primitive data types
9.Demonstrates the ++ and -- operatorsDemonstrates the ++ and -- operators
10.Literals
11.Demonstrates the mathematical operators.Demonstrates the mathematical operators.
12.Java lets you overflowJava lets you overflow
13.Built in typesBuilt in types
14.Relational DemoRelational Demo
15.Parse Number
16.Java Type Helper
17.Convert the given array (which may be a primitive array) to an object array
18.Convert primitive back and forth
19.Returns a default value if the object passed is null
20.A mutable boolean wrapper.
21.A mutable byte wrapper.
22.A mutable double wrapper.
23.A mutable float wrapper.
24.A mutable int wrapper.
25.A mutable long wrapper.
26.A mutable short wrapper.
27.Primitive utilities