• Post Reply Bookmark Topic Watch Topic
  • New Topic

string problem  RSS feed

 
riteshhh kumar singh
Greenhorn
Posts: 13
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused in String.It's given in the book that string is object in java and it is created by using the class "String".And if you write "Object ob" then only the reference of that class is created and it points to "Null",an object is created by using "new" operator,"Object ob=new Object()".
Since the objects are created by using "new" operator where the memory is allocated dynamically during run-time, how in case of string this given statement is possible "String ob="Hello",without allocating memory for it.


any help is appreciated...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String is special - the Java language has special syntax for creating strings. Suppose there were no string literals in Java, then it would be incredibly cumbersome to initialize a String object with separate characters. You'd have to do something like this:

 
riteshhh kumar singh
Greenhorn
Posts: 13
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so,it's a special case in java.
okay,thank you jesper,thankx for the help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!