A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCM Java EE 6 Enterprise Architect Exam Guide
this week in the
Vijay jai Singh
Joined: Jan 07, 2009
Jun 29, 2009 04:40:57
What is difference in these two statements:
str = null;
String str = "";
Jesper de Jong
Joined: Aug 16, 2005
Jun 29, 2009 04:52:10
In the first one, you set the variable str to null (which means that it does not point to any object), and in the second one you set it to point to a String object which has no content.
Two very different things.
Java Beginners FAQ
JavaRanch SCJP FAQ
The Java Tutorial
Java SE 7 API documentation
- My blog about Scala
Joined: Mar 23, 2009
Jun 29, 2009 05:04:49
Seems you are a beginner in Java.No problems we all start somewhere.
I hope you are aware that there are two types of variables in Java
in the code line
int a ;
'a' is a primitive variable as it can refer to the primitive of the type int.
Similarly in the code line
str can contain a reference to a String object .
For your information in Java String is a class in the package java.lang.
So if you do a
String str= null what it does is
Makes a reference variable(the bit holder
for a reference value) named str of the type
and making it equal to null simply means the
variable is not referring to any object.
Simply creates an object of the type
with no value in it and assigns the refernce variable str to this object.
Joined: Jun 26, 2009
Jun 29, 2009 08:40:34
str = null;
The variable does not point to any memory location.
The vairable points to some memory location having blank value
SCBCD for JEE 5
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: String Question
how to read lines in BuffredReader
question regarding strings
how many type or how many kind of way we can create an object in java??
setAttribute & getAttibute doubt
Is String[ ] Serializabel?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014