Implementing a Java Program
Implementing
of a java application program involves a
series of steps. They include:
·
Creating the
program
·
Compiling the
program
·
Running the
program
Creating the Program
We
can create a program using any text editor. Assume that we have entered the
following program:
Simple program for testing
class
Test
{
public
static void main(String agrs[])
{
System.out.println(“Welcome
in java class”);
System.out.println(“
Learn about java in class”);
}
}
We
must save the program in a file called Test.java ensuring that the filename
contains the class name properly. This file is called the source file. Note
that all java source file will have the
extension java.
Note
also that if a program contain multiple classes, the file name must be the classname of the class containing the main method.
Compiling the Program-
To compile the program we must run the java Compiler javac, with the name of source file name in command line
javac Test.java
If everything is okk, then javac compiler create the source file called Test.class containing the bytecode of the program.
Note that the compiler automatically nae the bytecode file as<classname> .classjava program Compilation -
· Running the program-
We need to use the Java interpreter to run a stand- along program. At the command prompt, typejava TestNow the interpreter looks for main method in the program and begin execution from there. When executed, our program display the following.Welcome to Java classLearn about java in classNote that we simply type “Test” at the command line and not “Test.class” or “Test.java”.
No comments:
Post a Comment