• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Null Literals

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please tell me the Difference between Null Literals and Null (the Keywords)?
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this thread to the Beginner section...
 
Trailboss
Posts: 24046
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would guess it has to do with the value that is stored in a reference when it is null vs. the the keyword null that you would compare it to or set it to.
The value null vs. the keyword null.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
null means nothing
whereas "" means the empty string

------------------
Regards,
Dave
 
Honey
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that Null is a keyword whereas Null literal is not a keyword but Null literal could have only Null as value.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Urg. "null literal" and "null keyword" sound to me like two names for the same thing - except that "null keyword" isn't really correct since null isn't really a keyword at all, but it is a reserved word which is what people often really mean when they talk about keywords. I'm not going to try to make sense of everyone's statements, since everyone seems to have a different interpretation, but I do have two more important points:
  1. The word "Null" has no special meaning at all in Java - "null" does. Capitalization is important in this language.
  2. The empty string "" should not be called a null at all in Java, as that just creates confusion. An empty string is an actual String object with no characters in it and length 0. A null is not an object at all; it represents the lack of any object.

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please explain null values. If there are varibles such as int i or j or an int array without specifically assigned values, are the values then considered null? On the other hand, if there is an empty string array, is it just empty or is it null? I am confused about this.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When u declare a variable, you have to initialize it, unless u specify that variable as static, otherwise compiler will complain, that the variable may not be initialized. In case of arrays, when you create a int array, all the elements are initialized by default to 0 and the String array is initialized to "null"( which is nothing).
Hope this helps.
[This message has been edited by Java2learner (edited March 02, 2000).]
 
Theresa Duick
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! Key lesson to remember is: array elements not initialized are set to zero & strings set to null. Hopefully I won't forget this in a few days!
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Errr... not quite. When an array is created, any elements not initialized will be set to the appropriate default value for the type of the array. If it's an array of primitive numerics (byte, char, short, int, long, float, double) then the default value is 0. If it's boolean, the default value is false, and if it's any kind of reference type (any sort of Object, including String) then the default value is null.
As for Java2Learner's statement about "when you declare a variable, you have to initialize it, unless it's static" - that's incorrect. If it's a local variable then you have to initialize it (and local variables can't be static anyway). If it's an instance or class variable (i.e. a member variable with or without "static" modifier) then you don't actually have to initialize it - if you don't, it will get the appropriate default value for its type, as I listed above (0, false, or null).
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim, thanks for correcting my statement.
 
Honey
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jim. I really forgot about capitalization.


[This message has been edited by Honey (edited March 03, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to JLS:
null is NOT A KEYWORD. It is a NULL LITERAL.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No ,null is s keyword ,you can refer to Robert and Heller's book.
Or you can refer Sun Site.


 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No ,null is a keyword ,you can refer to Robert and Heller's book.
Or you can refer Sun Site.


 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, technically, in the real world, according to the Java Language Specification, "null" and "true" and "false" are not keywords but they are reserved words. Roberts/Heller/Ernest do not outrank the Java Language Specification.
However, in the exam,, which is what RHE are wrinting for, we don't care about this distiction. All Sun wants to know is, do you know that these words are illegal to use as identifiers? Hopefully, they will correctly call these "reserved words". If they slip and say "keywords" or "reserved keywords", just pretend they said "reserved words".
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Honey,
Do you know what MVSR means?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic