aspose file tools*
The moose likes Beginning Java and the fly likes Super dumb newbie question...String[] args vs. String args[] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Super dumb newbie question...String[] args vs. String args[]" Watch "Super dumb newbie question...String[] args vs. String args[]" New topic
Author

Super dumb newbie question...String[] args vs. String args[]

David Junta
Ranch Hand

Joined: Dec 10, 2000
Posts: 86
I've seen different people use both these in their main methods:
String[] args vs. String args[]
Is there any difference?
Marius Holm
Ranch Hand

Joined: Sep 11, 2000
Posts: 84
Yeah, only the 'String[] args' (or 'String[] whatever') works.
Marius
David Junta
Ranch Hand

Joined: Dec 10, 2000
Posts: 86
Thanks, Marius. One of the places I saw String args[] was here in JavaRanch in the first few lines of code on the "How To Make Methods" page: http://www.javaranch.com/drive/method.html
I assume it works if it was there, but I haven't tried compiling it or running yet. Perhaps I shall.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
David,
No in Java there is NO difference between the two examples you gave. This is VERY important to know about Java! If you don't know that these two are equal then you better start reading some Java books ... You have shown an easy example, 1 dimensional array. For 2 dimensional arrays it gets even more interesting:
String[][] a == String[] a[] == String a[][]
You had better get used to this because it is all over in Java, as it is a personal preference NOT a specified Java requirement.
Try it with your favorite Java compiler!
Manfred.
Bad code can always be used as
good examples on what not to do!
Marius Holm
Ranch Hand

Joined: Sep 11, 2000
Posts: 84
Really, Manfred?
Well, thanks for the enlightment. I didn't know that. But it doesn't make sense, does it? Is it just a matter of flavor, or does it have other implications?
I'd love to read a good Java book, can you recommend one?
(And how would that be with 4-dimensional arrays?
No, just kidding! )
Marius
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

personally I prefer String[] args.


SCJP
Visit my download page
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Marius,
A good book that is free is:
Thinking in Java by Bruce Eckel.
he has his own web site that lets you download an Adobe PDF of the book. He explains concepts very well and has exercise programs that help a lot. Best FREE book I have ever read about Java!
Another good book is:
The Complete Java 2 Certification Study Guide by Simon Roberts, et al. This book is geared towards certification but the explanations are VERY clear and the examples given are EXTREMELY easy to understand. Roberts makes the inner concepts of Java very easy to understand without complex examples that don't relate to the current topic. The book is also divided up into exam objectives that help to break up the Java elements. I think this book is the best Java book on the market for certification hands down. It costs about $45 though ...

Enjoy,
Manfred.
Ronald Pruitt
Ranch Hand

Joined: Jan 15, 2001
Posts: 32
Need a method that would check to see if a word being added to a list is already in the list at the current position and if so to increment the list count but not add the word. Don't know how to do this. I have method to append the list, would it be better to write some sort of if statement for these methods instead.


in the main
L2.append(new WordElem("Mountain", 5));
want to append the list, check to see if the item that is being added is at the current position(end of the list) and if so increment the count only.
thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Super dumb newbie question...String[] args vs. String args[]