Basic Java Language: Difference between revisions
wikademia>Cremisis13 No edit summary |
wikademia>Cremisis13 |
||
| Line 165: | Line 165: | ||
You can't create two variables with the same identifier, all identifiers must be unique. You also can't use an identifier that is a Java keyword. Here is a list of all the [http://en.wikipedia.org/wiki/Java_keywords Java Keywords]. [[Flashcards for Java keywords]] provides some assistance in memorizing the concepts behind specific keywords. | You can't create two variables with the same identifier, all identifiers must be unique. You also can't use an identifier that is a Java keyword. Here is a list of all the [http://en.wikipedia.org/wiki/Java_keywords Java Keywords]. [[Flashcards for Java keywords]] provides some assistance in memorizing the concepts behind specific keywords. | ||
=Comments= | |||
- Comments are notes that the developer can insert into their code. This allows the developer to keep track of their code and helps when developers are collaborating on a project. It is good to write a summary of the following code at the beginning of your methods, classes, etc. The Java compiler completely ignores comments, so you can say anything in them | |||
- | |||
- Comments are written using two forward slashes | |||
- <pre>//This is a comment</pre> | |||
- Comments can be written at the end of a line | |||
- <pre>System.out.println("I love comments"); //This is also a comment</pre> | |||
- Comments can also be written on multiple lines by starting with '''/*''' and ending with'''*/'''. | |||
- <pre>/* Comment 1 | |||
- Comment 2 | |||
- Comment 3 */</pre> | |||
- :Sun recommends the above form be reserved for information intended for automatic JavaDoc documentation. | |||
=Compiling and Running your program= | =Compiling and Running your program= | ||
To compile your program, go to the directory you saved it. Note that if your class was named NaMe then your file '''must''' be named NaMe.java. Anyways, type: <code>javac NaMe.java</code> where NaMe is your class name. To run, type <code>java NaMe</code>. | To compile your program, go to the directory you saved it. Note that if your class was named NaMe then your file '''must''' be named NaMe.java. Anyways, type: <code>javac NaMe.java</code> where NaMe is your class name. To run, type <code>java NaMe</code>. | ||