File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
David Junta
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, only the 'String[] args' (or 'String[] whatever') works.
Marius
 
David Junta
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
personally I prefer String[] args.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic