out.println( "x = " + x );
}
}
Every program in Java is a class, and that is why the first line says that this is a public class (available for
use by anyone) called ???Primitive.??? The next line says that this is the start of a ???method??? called ???main.??? Any Java
program must have a ???main??? method declared exactly as this is. The line
"public static void main( String[] args ) {"
CHAP. 5] PROGRAMMING IN JAVA 67
is where the program starts. This line will be in all your programs. This line tells the Java Virtual Machine
(JVM) where to start running your program.
???Public??? means that anyone can run the program, ???static??? means that there is only one main method for the class,
???void??? means that the main method will not return any values, and ???String[] args??? means that if the user provided any
???command line arguments,??? they are available to the program in an array of String variables called ???args???. Some of
this probably doesn??™t make sense to you right now, so for now simply remember that every one of your programs
must have a main method, and the first line of the main method must be written exactly as this example is written.
Notice that every statement in Java ends with a semicolon! Notice, too, that the Java language is ???case-sensitive.
Pages:
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191