We still haven't covered enough material to make a working program, but what we'll do is just show you one, and once again defer discussing the details until later. This way we can finally get some of the things we've been talking about running in a program.
public class FirstProg { public static void main(String[] args) { // The next line is the only real executable line in the program System.out.println("This is my first program."); // The preceding line was the only real executable line in the program } }
You've already seen the System.out.println command; it prints the text ``This is my first program.'' to the screen. The lines that start with // are comments. These are not executed, or even compiled, but are put in the program by the programmer to give information to someone reading the program. (including herself!) And the rest we're not going to discuss yet, except to say that every Java program must have a method called main. For now, use this as a template. Just cut out the
System.out.println("This is my first program.");}line and replace it with whatever you like, and change or remove the comments as you see fit.