aspose file tools*
The moose likes Beginning Java and the fly likes basic syntax question ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "basic syntax question ?" Watch "basic syntax question ?" New topic
Author

basic syntax question ?

Yuan Tseng
Greenhorn

Joined: Mar 11, 2003
Posts: 21
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

Joined: May 25, 2001
Posts: 388
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

Joined: Dec 06, 2001
Posts: 3061
Originally posted by karl koch:
ascii coed table

An ascii co-ed table eh?
:roll:
Are the lower-case ones female?


Java API Documentation
The Java Tutorial
Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
Maybe the mixed case ones are definitely teenagers.
doco


doco
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Shen Lin
Greenhorn

Joined: Mar 10, 2003
Posts: 10
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

Joined: Mar 18, 2003
Posts: 118
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

Joined: May 25, 2001
Posts: 388
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

Joined: Jan 31, 2003
Posts: 401

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

Joined: Dec 20, 2001
Posts: 3271
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.


SCJP Tipline, etc.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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

Joined: Mar 17, 2003
Posts: 123
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

Joined: Dec 10, 2001
Posts: 7023
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: basic syntax question ?