Management

Add a new page

Top Rated Pages

Variables are a necessity for any java program. If you looked at the last tutorial, you would have noticed the args[0] was a little strange. If you where to have run the code, it wouldn't have worked. Let's look at that code again:

Alright, look at where it says main(string[ ] args). This is the main method, but what is supplying the arguments for that main method? What you typed on the line afterword of course!!! The string[ ] args part automatically takes the arguments from the command line. The string[ ] part tells whatever is calling this method, in this case, that would be you, directly, that the arguments supplied should be an array of strings. Now, try to run that code again, except make sure to put a space, and then something in quotes, and see if it works. Now do it without the quotes.

String

A String is a collection of characters put end to end. To allocate a new string, just put the string in double quotes like this:

StringmyString = "This is my String"

now, say you want to edit that string:

myString = "This is still my String!!!"

That's right, after a variable declaration, where you specified type and name of the variable, you no longer have to specify type for that variable. You just have to write what value you want to change.

Object

You just learned about a variable type called Strings. Now then, what the heck is this Object thing. Well, to understand that, we have to move on to the next tutorial.