aspose file tools*
The moose likes Beginning Java and the fly likes really basic question, arrays .util package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "really basic question, arrays .util package" Watch "really basic question, arrays .util package" New topic
Author

really basic question, arrays .util package

Honey Rathore
Greenhorn

Joined: Nov 11, 2009
Posts: 7
array is in java.util package but still we can use it without importing util package.Why?


the code runs good,without prompting any error
but i didn't import java.util package.
yeah i know it's really basic, but hey help me guys
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 290

hi
Wel come to Javaranch


-Chiru
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Are you talking about java.lang.reflect.Array or java.util.Arrays ? or generally about Object array example : Object[] ?
Pushkar Choudhary
Rancher

Joined: May 21, 2006
Posts: 425

Welcome to Javaranch!

Honey Rathore wrote:array is in java.util package

I'm not sure if this statement is correct. There is no such class as java.util.Array.
Honey Rathore wrote:we can use it without importing util package.Why?

When you create an array, you don't need to use any class other than the one whose array is being created.
For example,

The above code creates a simple String array. While doing so, the only class we use is java.lang.String. So, no importing required for this.

For more information, you can refer to:

JLS is:

http://java.sun.com/docs/books/jls/third_edition/html/arrays.html

JVM spec is:

http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#16446
http://java.sun.com/docs/books/jvms/second_edition/html/Compiling.doc.html#4091
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

Arrays are a built-in feature of the Java language. They have nothing to do with whatever is in the java.util package.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
And be careful about spelling; array and Array mean different things in Java. As Jesper says, you are using the array operators [] not a class called "array" (nor "Array"). Pushkar Choudhary, you are right to say
I'm not sure if this statement is correct.
Honey Rathore
Greenhorn

Joined: Nov 11, 2009
Posts: 7
so array is only a kind of data structure
it is not a class
yes, there are some classes which contain methods for manipulating arrays. like class Arrays in java.util package
but there is an instance variable of name length of class name<idon'tknow> which tells you about the no. of elements in an array
then where is it come from?
is it from java.util.Arrays?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42923
    
  68
but there is an static instance variable of name length of class name<idon'tknow> which tells you about the no. of elements in an array
then where is it come from?
is it from java.util.Arrays?

No, that's a convenience method provided by the compiler for arrays. It is not part of any class or interface.
Honey Rathore
Greenhorn

Joined: Nov 11, 2009
Posts: 7
Is there any other method which is not part of any other class or interface?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Ulf Dittmer wrote:
but there is an static instance variable of name length of class name<idon'tknow> which tells you about the no. of elements in an array
then where is it come from?
is it from java.util.Arrays?

No, that's a convenience method provided by the compiler for arrays. It is not part of any class or interface.


Thanks....


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

array is the only built in collection in Java. This built-in Java array is declared and constructed differently from most of the other java objects. It is a subclass of java.lang.Object, it implements both Serializable and Cloneable interfaces. We can't find a class definition for it in any of the Java Platform class. It's definition is built-in Java language!

Since array is inherited from java.lang.Object. Therefore, it understands all the methods of Object class. Besides the java.lang.Object methods, it also has its own accessible member variable length
Honey Rathore
Greenhorn

Joined: Nov 11, 2009
Posts: 7
thankyou guys
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
There is a section about arrays in the Java™ Language Specification. It is by no means easy to read, however.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: really basic question, arrays .util package