DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2005
    Posts
    16

    is Array in java are Object?

    is Array in java are Object?

    int a[]=new int[10];

    new will allocate memory. but int is a type not an Class ?

    please help me.......

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    The java compiler treats arrays as objects with a few basic methods and one public final value: length. There is no mystery
    eschew obfuscation

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    255
    Quote Originally Posted by thennam
    new will allocate memory. but int is a type not an Class ?
    You would be surprised to see this.
    Code:
    class Test {
    	public static void main(String[] args) {
    		System.out.println(int.class.getName());
    	}
    }
    Happiness is good health and a bad memory.

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You mean that this indicates that int is a class ? The class method here is used on the type definition, not a class instance.
    So, this does not compile:
    Code:
    class Test {
      public static void main(String[] args) {
      int x=5;
      System.out.println(x.class.getName());
    }
    eschew obfuscation

  5. #5
    Join Date
    Dec 2005
    Posts
    48
    int x=5;
    System.out.println(x.class.getName());

    x is not a object.

  6. #6
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Exactly, neither is int. And an object is not a class, it is an instance of a class.
    Last edited by sjalle; 01-11-2006 at 03:35 AM.
    eschew obfuscation

  7. #7
    Join Date
    Dec 2005
    Posts
    48
    Quote Originally Posted by thennam
    is Array in java are Object?

    int a[]=new int[10];

    new will allocate memory. but int is a type not an Class ?

    please help me.......
    Object is aarray
    Code:
    boolean b = object.getClass().isArray();
        if (b) {
            // object is an array
        }

Similar Threads

  1. Replies: 2
    Last Post: 06-16-2006, 05:58 AM
  2. Java Array and Parameter passing help
    By makaveli316 in forum Java
    Replies: 6
    Last Post: 12-16-2005, 02:23 AM
  3. Calling a Database Object using Java
    By audai in forum Java
    Replies: 0
    Last Post: 12-11-2005, 04:18 AM
  4. Object Array ? Do you Worth it
    By ashish in forum Java
    Replies: 1
    Last Post: 05-23-2002, 07:50 AM
  5. Replies: 2
    Last Post: 12-13-2001, 09:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links