• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Primitive Types!!!

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
could anyone please explain me why int, char, byte, short etc. are called primitive data types?
thanks.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java, there is an import distinction between primitive data types and objects. They are very different. When you wish to store an integer, you need a variable of type int. This always uses exactly 32 bits of memory.
Example: int i = 3452;
If I want to store a String (BTW In Java, Strings are objects, not primitive data types), you need an object reference variable, and then you have to instantiate the object.
Example:
String str;
str = new String("This is a test");
You can also write it using Java's shorthand notation for calling the String constructor.
String str = "This is a test";
Nonetheless, you are STILL creating an object reference variable of type String, and "pointing" it to a String object. This is different than a simple primitive data type like int.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Namaste Sathi
int, char, byte, short etc are called primitive because to access them you do not need to create an object reference to them. They can be declared and initialised directly e.g. int x = 5 ; In other words you do not need to new it to assign a value to it.
Hope this helps,
Rajesh
 
Greedy thomas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Namaste Sathi
Add on to my previous reply :
A primitive data type uses a fixed number of bytes.
Rajesh.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic