a
Java class
Attafottty
of aclass
When
thejVM starts running, it looks for the class you give it at the com-
mand
line. Then it starts looking for a specially-Written method that
looks
exactly
like:
public
static void main (String() argsl {
// your code goes here
}
Next,
theJVM runs everything between the curly braces { }of your main
method.
EveryJava application has to have at least one class. and at least
one
main method (not one main per class , just one main per application).
Writing a class with main
In Java, everything goes in a class. You'll type your source code file (with a
.java extension), then compile it into a new class file (with a . class extension).
When you run your program, you're really running a class.
Running a program means telling the Java VIrtual Machine (JVM) to "Load the
Hello class, then start executing its main () method. Keep running 'til all the
code in main is finished."
What can you say in the main method ???
Your code can tell the JVM to :
1. Statements : declarations , assignments , method calls
int x =3;
String name = "Dirk";
x = x * 17;
System .out .print("x is " + x);
double d = Math.random();
// this is a comment
2. Loops : for , while , do while
while(x < 10)
{
System.out.println("Java");
}
3.Branching : if , else . else if
0 Comments