Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Is String really object ?

  Asked By: Techguy    Date: Oct 18    Category: Java    Views: 656
  

I am really new to Java.
I read about String data type, all books told me that String is class.
But why we could use String variables without creating the instance of the
class ?

String myString;
myString = "Ini string loh...";

As a class, String variables should be created as the instance before we
could use them, right ?

String myString;
myString = new String("Ini string loh...");

So, I assume the first one....String is a primitive data type not class.
Please, explain me about this situation ?

Share: 

 

8 Answers Found

 
Answer #1    Answered By: Sonya Flores     Answered On: Oct 18

Java is a true Object Oriented Language. Please check
out the information at:
http://java.sun.com

Study the online tutorial too.

 
Answer #2    Answered By: Eric Foster     Answered On: Oct 18

When you state :

String myString;
myString = "Ini string  loh...";

java compiler turns it in :

String myString;
myString = new String("Ini string loh...");


Because the "Ini string loh..." is read  as it were
new String("Ini string loh...") ....

 
Answer #3    Answered By: Oliver Evans     Answered On: Oct 18

Well, if it's the fact...I agree, but it's not good for newbie, I think :).
(Because, primitive data  type totally different from object.)
Ok, thanks for all responds, I accepted it.

 
Answer #4    Answered By: Geb Chalthoum     Answered On: Oct 18

String is an Object as is everything in Java. You
could write "new String(...)", but if you don't this
is essentially what the compiler does.

// These statements are essentially the same, since
the compiler handles this for you
String str = new String( "This is a string" );
String str = "This is a strint";

 
Answer #5    Answered By: Corey Brown     Answered On: Oct 18

I'm not sure everything in Java is object.

There are data-types, like boolean and int, that
aren't objects ...

for that sake there the static classes like Integer .

 
Answer #6    Answered By: Fred Hicks     Answered On: Oct 18

I believe that the use of strings in to form of "string" is a shortcut
because of how often strings are used.

 
Answer #7    Answered By: Ludo Ricci     Answered On: Oct 18

Okay I stand corrected, those are called primatives.
I think the word you are trying to find instead of
static classes are non mutable classes which an
example is String, and all of your primative wrappers
such as Integer, Long, Float, Char, etc.

 
Answer #8    Answered By: Luigi Fischer     Answered On: Oct 18

That's waht I meant and couldn't express corectly in
English.

 
Didn't find what you were looking for? Find more on Is String really object ? Or get search suggestion and latest updates.




Tagged: