Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

really basic question, arrays .util package

 
Honey Rathore
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Wel come to Javaranch
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about java.lang.reflect.Array or java.util.Arrays ? or generally about Object array example : Object[] ?
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15203
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays are a built-in feature of the Java language. They have nothing to do with whatever is in the java.util package.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any other method which is not part of any other class or interface?
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou guys
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a section about arrays in the Java™ Language Specification. It is by no means easy to read, however.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic