[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeff Verdegan wrote:
That in itself won't cause the compiler error though. If the array was non-zero size (that is, if you had passed arguments when you invoked your program), you'd have been allowed to overwrite them. It's just not good practice to do so.
Arrays have a fixed size at creation. So if an array is created with new String[0] as the args array was here (by the JVM before it invoked your main() method), it will always be empty, and you can never access and element because there is no element to access.
abrar alvi wrote:
Jeff Verdegan wrote:
That in itself won't cause the compiler error though. If the array was non-zero size (that is, if you had passed arguments when you invoked your program), you'd have been allowed to overwrite them. It's just not good practice to do so.
Arrays have a fixed size at creation. So if an array is created with new String[0] as the args array was here (by the JVM before it invoked your main() method), it will always be empty, and you can never access and element because there is no element to access.
Sorry but i did not understand your these quoted above lines...
Also these are some of the other doubts :
Does JVM create String[] args as empty.....
I did not get any compiler error while using args....
abrar alvi wrote:Thanks Jeff for making me understand.....
yes i am using Net Beans.... but how do i set the command line args there....
also if i can pass directly the arguments while starting then i wont be requiring the InputStreamReader class ???
OCPJP 6 86%
Nikhil Sagar wrote:Abrar, its ArrayIndexOutOfBoundException Not ArrayIndexOutOfBoundError.
abrar alvi wrote:
Nikhil Sagar wrote:Abrar, its ArrayIndexOutOfBoundException Not ArrayIndexOutOfBoundError.
yes it is...
OCPJP 6 86%
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |