• Welcome to Valhalla Legends Archive.
 

meh?

Started by Forged, August 26, 2004, 09:35 PM

Previous topic - Next topic

Forged

I am taking a java class, and my teacher really hasn't been to clear on anything, and I was wondering why
public static void main (String args[])

needed to be added in excuting programs.  What is the purpose in adding that many types?
QuoteI wish my grass was Goth so it would cut itself

K

void main() is the entry point of the application.  This function will be called by the virtual machine when it loads your application.

public means it's accessible outside of the class you declare it in.

static means that no class instance needs to be created in order to call it; it is shared between all instances of the class it is declared in.

void is the return type (ie, no return value)
args[] is a collection of the command line tokens passed to the program.

HTH.

Forged

thank you for that explination my comp sci teacher failed to give.

what does hth mean?
QuoteI wish my grass was Goth so it would cut itself

hismajesty


K

Quote from: hismajesty[yL] on August 27, 2004, 04:20 PM
Happy to help.

Or "Hope that helped."

depending on whether or not I was indeed, happy.

hismajesty

Quote from: K on August 27, 2004, 05:09 PMdepending on whether or not I was indeed, happy.

:P

MyndFyre

#6
Isn't


public static void main(String args[])

bad syntax?  Isn't it supposed to be

public static void main(String[] args)


???

:P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

iago

Quote from: MyndFyre on August 28, 2004, 07:31 PM
Isn't


public static void main(String args[])

bad syntax?  Isn't it supposed to be

public static void main(String[] args)


???

:P

They both work.  In oldschool java, String []args was only valid.  But, I'm told, people complained that the non-c-style syntax confused people.so they changed it.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Tuberload

Quote from: MyndFyre on August 28, 2004, 07:31 PM
Isn't


public static void main(String args[])

bad syntax?  Isn't it supposed to be

public static void main(String[] args)


???

:P

The way it is being used makes it a matter of preference IMO. The only time a declaration of an array on the variable(s) type would seem more correct to me is if you were declaring multiple arrays of the same type as follows:

public int[] intArray1, intArray2, ... ;

This would eliminate having to declare each variable as an array directly.

As for which way you prefer to use in a method signature, I don't see how ether

public static void main (String[] args)
or
public static void main (String args[])

is more correct than the other.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

MyndFyre

IMHO, it's because the type of "args" is String[].  I guess it's purely cosmetic, but I'm of the school of thought that when declaring locals, it should be

type identifier

vs

type identifier type

:P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Quote from: MyndFyre on September 01, 2004, 06:59 PMIMHO, it's because the type of "args" is String[].  I guess it's purely cosmetic

Well, it depends whether you think of [] as modifying the type or as specifying a new type.  For a screwed up language like Java, I can understand treating an array of a type as being completely different; for C, it makes a lot more sense to use the [] after the variable name, since it's a modifier on the type of the variable.  You're declaring that the variable isn't just an int, but an array of int.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Tuberload

Quote from: MyndFyre on September 01, 2004, 06:59 PM
IMHO, it's because the type of "args" is String[].  I guess it's purely cosmetic, but I'm of the school of thought that when declaring locals, it should be

type identifier

vs

type identifier type

:P

Yes, so then like I said it comes down to being a matter of preference.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

MyndFyre

Quote from: Tuberload on September 01, 2004, 10:38 PM
Yes, so then like I said it comes down to being a matter of preference.

You know Tuber, I must admit that I have NOT missed you ALWAYS having to get the last word in.  :P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

TangoFour

QuoteFor a screwed up language like Java, I can understand treating an array of a type as being completely different;

That's because Arrays in Java are treated like objects, whereas a basic type such as int is not

Then again, String is also an object