GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 262 of 507    Print  
Why String is not a primitive data type

  
Total Answers and Comments: 14 Last Update: February 24, 2009     Asked by: gothlururaaja 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Ananth Murthy
 
Float and double both occupy fixed amount of memory irrespective of what number it holds. But String is an object. Memory allocation depends on the content


Above answer was rated as good by the following members:
sandeep_14185
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
June 24, 2006 05:07:50   
Musarath        

RE: Why String is not a primitive data type

The primitive datatypes are nothing but the basic data types..like int char float double etc..Char is a datatype which stores 2 bits of data..String has been derived from Char which takes more number of Char and integers..providing the more memory storage...Its not a primitive coz it is a basic datatype...Its advancement of char..So its not a primitive datatype


 
Is this answer useful? Yes | No
June 26, 2006 09:57:22   
babjiblaji Member Since: June 2006   Contribution: 4    

RE: Why String is not a primitive data type

then how double is a primitive data type

its also derived for float so

pls clarify


 
Is this answer useful? Yes | No
June 27, 2006 11:07:17   
bhargavi        

RE: Why String is not a primitive data type
As balaji has asked a nice question that why double is a primitive data type as it came from float? As double is the default data type given to the floating point-numbers.Naturally when we declare float f 0;---------the memory occupied to it is double.Inorder to use memory effectively we go for float as float f 0.0f;As double is not a two float.
 
Is this answer useful? Yes | No
June 29, 2006 08:23:35   
       

RE: Why String is not a primitive data type

There are two types of datatype 1. primitive 2. Object

I think String can also be primitive and Object type.

If u write String a rabbi ; then the String will be used as primitive datatype.

But If u write String a new String( rabbi ); then String will be used by Object datatype.


 
Is this answer useful? Yes | No
July 01, 2006 15:51:46   
Suri        

Why String is not a primitive data type

I think both:

String a abc ; and String a new String( abc );

are the same.


 
Is this answer useful? Yes | No
July 02, 2006 07:58:06   
rabbi Member Since: June 2006   Contribution: 23    

RE: Why String is not a primitive data type
You r right Suri

Strings are immutable so
String a abc ;
is same as
String a new String( abc );
 

Is this answer useful? Yes | No
July 03, 2006 02:57:45   
babjiblaji Member Since: June 2006   Contribution: 4    

RE: Why String is not a primitive data type

yes u r right suri

thank u


 
Is this answer useful? Yes | No
July 04, 2006 00:35:39   
Ananth Murthy        

RE: Why String is not a primitive data type
Float and double both occupy fixed amount of memory irrespective of what number it holds. But String is an object. Memory allocation depends on the content

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 04, 2006 02:53:45   
babjiblaji Member Since: June 2006   Contribution: 4    

RE: Why String is not a primitive data type
ok thanks
 
Is this answer useful? Yes | No
July 18, 2006 18:14:30   
Amit        

RE: Why String is not a primitive data type

The Main reason behind is that when we talk about primitive data type

Lets say for ex int i 5 it means in memory where we have i if we will access the contents there we will get the value 5.

But in case of a String when we say

String s abe ;

when we try to access the contents of s we get the address where we have abc .


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape