The main difference is related to where they stay in the memory, objects are stored in the heap while value type are stored directly in the Stack ...
heap : is an area of memory used for dynamic memory allocation.
stack : is the section of memory that is allocated for automatic variables within functions. Data is stored in stack using the Last In First Out (LIFO) method.
About NSInteger and NSNumber :
NSInteger is nothing more than a synonym for a long integer, while NSNumber is an Objective-C class, a subclass of NSValue to be specific.
Answer from aleroot on Stack Overflowiphone - What is the difference between primitive data type vs an non primitive data type(apple defined data type)? - Stack Overflow
What is the reasons and the benefit of non-primitive data in Java?
In Java, why is String a non-primitive data type? - Stack Overflow
java - What is the difference between the terms non-primitive type and object type? - Stack Overflow
Videos
The main difference is related to where they stay in the memory, objects are stored in the heap while value type are stored directly in the Stack ...
heap : is an area of memory used for dynamic memory allocation.
stack : is the section of memory that is allocated for automatic variables within functions. Data is stored in stack using the Last In First Out (LIFO) method.
About NSInteger and NSNumber :
NSInteger is nothing more than a synonym for a long integer, while NSNumber is an Objective-C class, a subclass of NSValue to be specific.
object is : member data + function operating on the data
so, primitive data type is just data, no method directly related to it.
object is something like a module, include the data and function (method here).
NSInteger is primitive data type. NSNumber is object, it's member data maybe NSInteger.
I am new to Java and I dont get the reason behide non primitive data type that is created by a programmer e.g. School student, in this case School is non-primitive data .
Whats the point of this and how is it useful?
Please enlighten me
Thank you for answering
String is non-primitive because only class can have methods. Primitive can not. And String need many functions to be called upon while processing like substring, indexof, equals, touppercase. It would not have been possible without making it class.
Also class has made it possible to make strings immutable and final to enhance security and efficiency by allowing pooling.
The String Javadoc clearly indicates that String is a subclass of Object; and further String.equals(Object) overrides Object.equals(Object).
JLS-3.10.5. String Literals specifies that
A string literal consists of zero or more characters enclosed in double quotes.
Also, JLS-4.3.3. The Class String adds
Instances of class String represent sequences of Unicode code points.
A String object has a constant (unchanging) value.
String literals (§3.10.5) are references to instances of class String.
The string concatenation operator + (§15.18.1) implicitly creates a new String object when the result is not a compile-time constant expression (§15.28).
It's also worth pointing out that arrays are also Object(s), and An Array of Characters is Not a String. Finally, if a String wasn't an Object it couldn't be null.
Part of this confusion may be in that, in C#, (mostly) everything inherits from Object. To refer to an Object type in the same way, would refer to every type in the language, and essentially be useless.
In C#, the primitive types are Boolean, Byte, Char, Double, Int16, Int32, Int64, IntPtr, SByte, Single, UInt16, UInt32, UInt64, UIntPtr. These types still inherit from object, though they are treated differently by the language. There are a few types that don't inherit from object, but they are not what you would consider primitives (ie Interfaces). The list of C# primitives can be acquired with this code, taken from here:
var primitives = typeof(int).Assembly.GetTypes().Where(type => type.IsPrimitive).ToArray();
A more appropriate dichotomy, if you wanted such a thing, would be value types versus reference types. When you begin considering that difference, then you can include things such as Enum types, and other values type, like structs.
in Java:
the primitive variables are categorized in 8 data types: boolean,byte,short,int,long,float,double and char.Every primitive variable has his own range of space in memory.
The references variables,refers to objects(Array,String,ArrayList,StringBuilder,...), and doesnt matter the space of the object referred.
Differences:
1.references types can be assinged as null /primitives dont.
2.references types can be used to call methods when they dont point to null/primitives uses literals.
3.references types have all the same size / in primitives depends of the
data type
4.primitives declarations starts with lowercase/java classes with
Uppercase