(Answered)int vs Integer
int x = new int; //works int y = new Integer // not works WHAT?? I tried reading on google, but found the language a bit tough, if anyone can explain in easy kiddish language, thanks !!
@Meharban, its for you- int is a primitive type. Variables of type int store the actual binary value for the integer you want to represent. int.parseInt("1") doesn't make sense because int is not a class and therefore doesn't have any methods. Integer is a class, no different from any other in the Java language. Variables of type Integer store references to Integer objects, just as with any other reference (object) type. Integer.parseInt("1") is a call to the static method parseInt from class Integer (note that this method actually returns an int and not an Integer). To be more specific, Integer is a class with a single field of type int. This class is used where you need an int to be treated like any other object, such as in generic types or situations where you need nullability. Note that every primitive type in Java has an equivalent wrapper class: byte has Byte short has Short int has Integer long has Long boolean has Boolean char has Character float has Float double has Double Source: Stack Overflow
int = primitive type Integer = Object with int
In java, int is a data type, while Integer is a wrapper class. Since Integer is a class, we used to create it's object, while primitive datatype like int can have variables
Thanks @Sachin , its almost clear, please tell me about wrapper class
... Are you being serious? You can't set int to be an Integer.