Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

basic syntax question ?

 
Yuan Tseng
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have couple questions for this program.(i got this code from JAVA 2)
// Char
class Char {
public static void main (String args[]) {
char ch;

ch = 'X';
System.out.println ("ch contains " + ch);
ch++;
System.out.println ("ch is now " + ch);
ch = 90;
System.out.println ("ch is now " + ch);
}
}
1. on the ' public static void main (String args[])', but i looked another book 'Thinking in JAVA by Bruce Eckel' and he wrote '(String[] args)'. what's the different?
2. on this output 'ch is now z' not 90 because from ASCII. can you tell me where i can find this document?
thank you for your help.
yuan
 
karl koch
Ranch Hand
Posts: 388
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
for your second question:
ascii coed table
check out the ASCII value in the row where DECIMAL value is 90.
for the first:
there is no difference. that easy.

i dont know the exact reason for this. i prefer the String[] way.
k
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by karl koch:
ascii coed table

An ascii co-ed table eh?
:roll:
Are the lower-case ones female?
 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the mixed case ones are definitely teenagers.
doco
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String myStringArray[]; // is for us old C programmers ( well not quite: char* myStringArray[10] would be it )
String[] myStringArray; // is for cool kids
[ March 18, 2003: Message edited by: Barry Gaunt ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The different syntax styles also allow for unnecessarily compounded declarations of different data types.
int a, b[];
a would be an int while b would be an int array.
 
Shen Lin
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am interested in this topic. But I am a little confused. Does this mean that we use String a[] to creat an array a[] with type String and, on the other hand, we use String[] a to creat a, which is an array of String (String[])?
 
Jonas Isberg
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shen Lin:
I am interested in this topic. But I am a little confused. Does this mean that we use String a[] to creat an array a[] with type String and, on the other hand, we use String[] a to creat a, which is an array of String (String[])?

String a[] is an array of Strings, the array is named a.
String[] a is an array of Strings, this array is also named a.
(The type of a is in both cases String[].)
 
karl koch
Ranch Hand
Posts: 388
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
now that i reread my post...douuuugh
but no worries:
i wont correct my typo so you can continue to make fun of it :-)

k
 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

String a[] is an array of Strings, the array is named a.
String[] a is an array of Strings, this array is also named a.
(The type of a is in both cases String[].)

What is the advantage of using one over the other? Or when would one use String[] a and not String a[]?
doco
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by doco mastadon:

What is the advantage of using one over the other? Or when would one use String[] a and not String a[]?
doco

They are equivalent expressions. There is no advantage of one over the other.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you consider those unnecessarily compounded declarations an advantage. I'd tend to consider the ability to do funny things like that a curse.
 
Candy Bortniker
Ranch Hand
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I was reading through here to see if I could offer advice or more likely learn something, then I got confused.
I thought that arrays could be only int or float, etc. I just learned about vectors, similar to arrays but they hold objects such as strings. Am I misunderstanding something?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Candy, since your question is a bit different from this thread's topic, I've begun a new thread for you where we can discuss your question.
[ March 19, 2003: Message edited by: Dirk Schreckmann ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic