Posts

Showing posts with the label int

Java Puzzle : Integer Initialization

Here is a simple program which instantiate Integer object using primitive int values with all possible ways, new operator, AutoBoxing , Integer.valueOf() . 1: package com.test; 2:   3: public class IntegerPuzzle { 4: public static void main(String[] args) { 5: Integer a = new Integer(100); 6: Integer b = new Integer(100); 7: Integer c = 100; 8: Integer d = 100; 9: Integer e = Integer.valueOf(100); 10: Integer f = 150; 11: Integer g = 150; 12: 13: System.out.println( "a = b ? " + (a==b)); 14: System.out.println( "c = d ? " + (c==d)); 15: System.out.println( "d = e ? " + (d==e)); 16: System.out.println( "a = c ? " + (a==c)); 17: System.out.println( "f = g ? " + (f==g)); 18: } 19: } What would be the output of  this program ?