java newbie question

Discussion in 'Java' started by dave, Sep 6, 2007.

  1. dave

    dave Guest

    Hello,

    I'm studying Java, and now trying to make sense of the concept of
    types.

    Would it be correct to say:

    a Java type is a classification of what could potentially be bound
    to a Java variable

    Also, The Java class Class really describes types. Would it have made
    more sense to call this class Type instead of Class?
     
    dave, Sep 6, 2007
    #1
    1. Advertising

  2. dave

    Jeff Higgins Guest

    dave wrote:
    > Hello,
    >
    > I'm studying Java, and now trying to make sense of the concept of
    > types.
    >
    > Would it be correct to say:
    >
    > a Java type is a classification of what could potentially be bound
    > to a Java variable
    >
    > Also, The Java class Class really describes types. Would it have made
    > more sense to call this class Type instead of Class?
    >

    <http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html>
     
    Jeff Higgins, Sep 6, 2007
    #2
    1. Advertising

  3. dave

    Mark Space Guest

    dave wrote:

    >
    > a Java type is a classification of what could potentially be bound
    > to a Java variable


    This works for me. I also think of type as how the JVM will interpret
    any given bit pattern to which the variable is bound.


    >
    > Also, The Java class Class really describes types. Would it have made
    > more sense to call this class Type instead of Class?
    >


    Hmm, but ints, chars, booleans and all the other primitives are also
    types, but I don't think that Class describes them. Class only deals
    with Java objects (most of the language, admittedly) but there are a few
    types it doesn't abstract.

    Also, generics are a type, but their type gets erased during
    compilations. I don't think Class can represent the un-erased type.
     
    Mark Space, Sep 6, 2007
    #3
  4. Mark Space wrote:
    > dave wrote:
    >
    >>
    >> a Java type is a classification of what could potentially be bound
    >> to a Java variable

    >
    >
    > This works for me. I also think of type as how the JVM will interpret
    > any given bit pattern to which the variable is bound.
    >
    >
    >>
    >> Also, The Java class Class really describes types. Would it have made
    >> more sense to call this class Type instead of Class?
    >>

    >
    > Hmm, but ints, chars, booleans and all the other primitives are also
    > types, but I don't think that Class describes them. Class only deals
    > with Java objects (most of the language, admittedly) but there are a few
    > types it doesn't abstract.


    Each of the wrapper types has a public static final TYPE field that
    references the Class object for the corresponding primitive. For example:

    "public static final Class<Integer> TYPE
    The Class instance representing the primitive type int."

    in class Integer. Class objects for primitives are important in some
    reflection interfaces.

    >
    > Also, generics are a type, but their type gets erased during
    > compilations. I don't think Class can represent the un-erased type.


    I'm not sure generics count as a type, or anything else, in a running
    program. They are effectively a form of compile-time assertion that
    enables some extra checking.

    Patricia
     
    Patricia Shanahan, Sep 6, 2007
    #4
  5. dave

    dave Guest

    On Sep 6, 12:37 pm, Mark Space <> wrote:
    > > Also, The Java class Class really describes types. Would it have made
    > > more sense to call this class Type instead of Class?

    >
    > Hmm, but ints, chars, booleans and all the other primitives are also
    > types, but I don't think that Class describes them. Class only deals
    > with Java objects (most of the language, admittedly) but there are a few
    > types it doesn't abstract.
    >


    Although primitive types aren't objects, they can return a Class
    object. Example:

    Class cl = int.class; // int.class is an object of type Class
     
    dave, Sep 6, 2007
    #5
  6. dave

    Jeff Higgins Guest

    dave wrote:
    > On Sep 6, 12:37 pm, Mark Space <> wrote:
    >> > Also, The Java class Class really describes types. Would it have made
    >> > more sense to call this class Type instead of Class?

    >>
    >> Hmm, but ints, chars, booleans and all the other primitives are also
    >> types, but I don't think that Class describes them. Class only deals
    >> with Java objects (most of the language, admittedly) but there are a few
    >> types it doesn't abstract.
    >>

    >
    > Although primitive types aren't objects, they can return a Class
    > object. Example:
    >
    > Class cl = int.class; // int.class is an object of type Class
    >


    <http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#23409>
     
    Jeff Higgins, Sep 6, 2007
    #6
  7. dave

    Lew Guest

    dave wrote:
    >>>> Also, The Java class Class really describes types. Would it have made
    >>>> more sense to call this class Type instead of Class?

    ....
    >> Although primitive types aren't objects, they can return a Class
    >> object. Example:
    >>
    >> Class cl = int.class; // int.class is an object of type Class


    Interfaces are also types, but not classes.

    Class != type. Interface != type. Primitive != type.

    Why are you interested in redefining the Java language? Is "class" such a bad
    word?

    --
    Lew
     
    Lew, Sep 6, 2007
    #7
  8. dave

    dave Guest

    > Interfaces are also types, but not classes.
    >
    > Class != type. Interface != type. Primitive != type.
    >
    > Why are you interested in redefining the Java language? Is "class" such a bad
    > word?


    I'm not, I just asked if it made sense, it seemed logical to me,
    although I admit I'm not a Java expert. In fact, you'll notice from
    the title post I consider myself a Java "newbie", meaning there is no
    way in hell I would think I'm smarter than the people at Sun who write
    the Java specification!

    My hope was to understand a bit more on exactly what types means in
    Java.

    Anyway, thanks especially Jeff Higgins for those links. Those pretty
    much clear up the issues for me at least.
     
    dave, Sep 7, 2007
    #8
  9. dave

    Jeff Higgins Guest

    I'm a newb2 and have had a lot of help from the good people
    who frequent this group. I'm happy this "blind pig" was able to
    help find an acorn.
    JH
     
    Jeff Higgins, Sep 7, 2007
    #9
  10. dave

    Roedy Green Guest

    On Thu, 06 Sep 2007 08:56:03 -0700, dave <> wrote,
    quoted or indirectly quoted someone who said :

    >Also, The Java class Class really describes types. Would it have made
    >more sense to call this class Type instead of Class?


    Classes apply only to Objects. Type would be Objects plus primitives.

    Class has some kludges to describe primitives, but for the most part
    it applies only to classes.

    So I think either the name Class or Type would have been appropriate.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Sep 7, 2007
    #10
  11. dave

    Mark Space Guest

    dave wrote:
    > On Sep 6, 12:37 pm, Mark Space <> wrote:
    >>> Also, The Java class Class really describes types. Would it have made
    >>> more sense to call this class Type instead of Class?

    >> Hmm, but ints, chars, booleans and all the other primitives are also
    >> types, but I don't think that Class describes them. Class only deals
    >> with Java objects (most of the language, admittedly) but there are a few
    >> types it doesn't abstract.
    >>

    >
    > Although primitive types aren't objects, they can return a Class
    > object. Example:
    >
    > Class cl = int.class; // int.class is an object of type Class
    >



    Well that's darn interesting. That's for pointing that out!
     
    Mark Space, Sep 7, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. peelman
    Replies:
    2
    Views:
    444
    anonymous
    Jan 13, 2005
  2. Replies:
    0
    Views:
    322
  3. Jerry C.
    Replies:
    8
    Views:
    256
    Uri Guttman
    Nov 23, 2003
  4. Kruno Saho
    Replies:
    0
    Views:
    149
    Kruno Saho
    Apr 7, 2013
  5. Dave Angel
    Replies:
    0
    Views:
    130
    Dave Angel
    Apr 7, 2013
Loading...

Share This Page