A First Simple Program
/*
This is a simple program Call this file “Example.java”.
*/
Class Example
{
//Your program begins with a call to main ().
Public static void main (String args[])
{
System.out.println (“This is a simple Java program “);
}
}
Entering the program
-The name of a source file is very important
-In Java, all code must reside inside a class. By convention ,the name of that class should match the name of the file that holds the program
-A source file use the .java filename extension
Compilling the Program
C:>\javac Example .java
-The javac compiler creates a file called Example .class, that contain the Bytecode version of the program
-To actually run program, you must use the Java interpreter, called java
C:>\java Example
-When java source code is compiled, each individual class is put into its own output file named after the class and using the .class extension
A closer look at the first program
-All Java application begin execution by calling main()
-A complex program will have dozens of classes, only one of which will need to have a main() method to get things started
-Java applets don’t have any main() method
-Java interpreter run only main() method
-Java interpreter run only the class that have a main method
-println() is a built in method
-System is a predefined class that provides access to the system,and out is the output stream that is connected to the console.
0 comments:
Post a Comment