Results 1 to 7 of 7
  1. #1
    nagesh1811 is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Cool length method belongs to which class

    Hi

    my doubt is

    int a[]={2,5,9,8,4,1,3,7};

    alength=a.length();

    actually that length method belongs to which class ...

    which class method is invoked at that point: cool:

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    The code you posted is invalid - there is no length() method for arrays. However, arrays do have a length property, so you can use that instead:
    Java Code:
    int aLength = a.length;
    Java arrays are objects, but have special syntax, so they are not used quite like other objects.

  3. #3
    nagesh1811 is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    but in which API we can able to see.. that length Instance variable/constant

  4. #4
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    I don't understand what you're asking.

  5. #5
    nagesh1811 is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    if u open java.lang.thread class u can see
    MAX_PRIORITY
    MIN_PRIORITY
    NORMAL_PRIORITY

    fields/property

    like that length which we are using to find array length should be some where in java API. where it is in java api classes

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default

    It's not part of the api.
    It's a special thing...built into the JVM possibly?

  7. #7
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Arrays don't have a class in the API - for most coding purposes they're treated like primitives, although behind the scenes they are implemented as class objects and can be assigned to Object references.

    The custom syntax is handled by the compiler. At runtime the JVM creates array classes dynamically - they don't have an external binary representation like API classes (see JVM Spec 5.3.3 Creating Array Classes).

Similar Threads

  1. Help! Wierd glitch invalidated int[].length method!
    By soccermiles in forum New To Java
    Replies: 3
    Last Post: 04-18-2010, 07:15 PM
  2. How can I implement the String's length() method?
    By kiregad in forum New To Java
    Replies: 6
    Last Post: 03-26-2010, 06:06 AM
  3. what does num.length method does?
    By kris09 in forum New To Java
    Replies: 1
    Last Post: 08-07-2008, 10:19 PM
  4. Replies: 2
    Last Post: 12-12-2007, 05:01 PM
  5. Help with method length
    By toby in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •