PDA

View Full Version : Java Tutorial


SBJ95
12-14-2006, 12:43 AM
Well, I'm sure a lot of you would like to learn it. It's a relatively easy programming language, but still not recommended for people who can't tell the mouse from the keyboard XD. Here goes, with some of it directly taken from the notes given to me by my instructor:

This is a working program, which I will break down into parts and explain. Please note that Java is case-SENSITIVE:

public class Hello {
public static void main(String [] args) {
System.out.println("Hello, world");
}
}
The public statement means that other programs can run it. class Hello { statement is the object definition. All programs must have it. The second word (Hello) should always be capitalized, and the filename should be the same as it. You can change the Hello statement to anything you like. The curly brace is important. Don't leave home without it!!

public static void main(String [] args) {. You must capitalize the S in String. This is the main method. It's what the computer actually runs.

System.out.println(“Hello, world!”); This is the class. The ln is optional, it just means to display it on it's own line. The semicolon should be placed at the end of lines such as this. And this line's function is to simply display what is in the parenthesis and quotes.

At the end, don't forget to close the curly braces you forgot to close! In this case, put one 4 spaces from the left, and one more at the edge. It's important to remember that for neatness, for every curly brace you open, you should indent four spaces.
------------
What you need to develop Java is either a good IDE (such as Eclipse or Netbeans), or some sort of plain text editing program (such as Notepad). When using Notepad, be sure that when you save it, you select 'All Files', and save it as the object definition name (in this case Hello) .java

You'll also need a Java compiler and executor, such as Sun JDK and/or Sun JRE.

If you have any questions, please post them and I'll be happy to answer them.