• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

null

 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'null' is valid java type.
A) True
B) False
I thought that the answer is False. If it is a valid type then I should be able to create an instance of type null. But it is not possible. null is only a reserver literal. Am I correct?
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a null type inside the JVM. But it is not accessible for the programmer. null always represent a literal value assignable to any reference type via a widening conversion. I agree the answer is false.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sarma, Jose,
This is my first posting to Java Ranch.
The question asks if null is a valid 'java type'
Null is a valid literal constant in Java (under keywords)and if an object is null, it does not point to anything.
obj o; // points to null
o = new something // now o points to something
o = null //o is null again
All the best
Pallavi
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Pallavi
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so what is the answer???
 
Pallavi Chakraborty
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jose,
I thought that if null is a "Valid" literal constant, then we can say that null is a "valid" java type, emphasis being on the word valid.
If that is correct, then the answer is true.
Any other explanations.
All the best
Pallavi
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is FALSE. null is a literal, not a data type.
There are only eight built-in data types in Java: byte, short, int, long, float, double, boolean and char. That's it. All other variables are references of a particular class or interface type, and null is neither a class or interface.
 
Pallavi Chakraborty
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The question says, type and not data type.
Guess that is my concern.
But your explanation is good too.
So,do we all agree on False?
Pallavi
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taken from Sun's JLS:

There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.


1) A null type does exist inside Java.
2) It only holds value for people writing JVMs and such, not for standard Web/Application development.
3) "Valid" is in the eye of the test designer/test grader.
Todd Killingsworth
 
Todd Killingsworth
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taken from Sun's JLS:

There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.


1) A null type does exist inside Java.
2) It only holds value for people writing JVMs and such, not for standard Web/Application development.
3) "Valid" is in the eye of the test designer/test grader.
Todd Killingsworth
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic