Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • So String datatype is non-primitive in Java. In every Java main() program we write "public static void main(String args[])". Why? Why we always have to pass a String argument in main? Also we never need to import the String type in Java the way we include it in C/C++(eg. #include<string> or using std::string). Please explain. Commented Mar 14, 2012 at 16:08
  • 8
    @Maxood String does have special status in the language (it gets literals, it's in the signature of main, there's interning which I presume is explicitly allowed by the JLS, it's available automagically, etc.) but it isn't a primitive data type. One might call it built-in. Commented Mar 14, 2012 at 16:15
  • @Jesper Why are primitive types faster to work with? Just simply due to the fact they don't have the extra wrapping non-primitives do? I'm trying to figure out the difference between primitives and non-primitives...as in are primitives built into the CPU or something? Commented Aug 18, 2016 at 11:59
  • From Wikipedia: "Depending on the language and its implementation, primitive data types may or may not have a one-to-one correspondence with objects in the computer's memory. However, one usually expects operations on basic primitive data types to be the fastest language constructs there are." --- So this 1-to-1 correspondence is the root cause of it being faster, whereas with objects, it isn't 1-to-1. Am I correct? Commented Aug 18, 2016 at 12:01
  • 1
    @Abdul don't make it too complicated. The CPU has a number of registers, that can contain different kinds of primitive values (for example a 32-bit or 64-bit integer or a single or double precision floating point number) and the CPU has instructions implemented in hardware to do operations on the values in the registers. Your last remark is essentially correct. Commented Aug 18, 2016 at 13:42