Tuesday, May 29, 2012

Compiling the program

Let us see now how the simple java program will look like.

You can use any editor like notepad or any Java IDE for writing java programs.
/*This is a sample java program Save this file as Welcome.java*/
import.java.io.*;
class Welcome
{
//  A java program will start from here.
        public static void main(String args[])
            {
              System.out.println("  Welcome to learndotjava ");
            }
}

For those who are using the IDE, you can follow the instructions have given by there.Suppose if you are entering your program in notepad, then save this file as Welcome.java
Filename must be same as that of Class Name

* -->symbol indicates import all function from library
.(dot)-->symbol is used to bind the functions

Compiling the program

After we have written our program we need to compile and run the program. For that we need to use the compiler called javac which is provided by java.Go to the command prompt and type the file name as shown here.


c:\>javac Welcome.java

The javac compiler will create a class file called Welcome.class that contains only bytecodes. These bytecodes have to be interpreted by a Java Virtual Machine(JVM) that will convert the bytecodes into machine codes. Once we successfully compiled the program, we need to run the program in order to get the output. So this can be done by the java interpreter called java. In the command line type as shown here.


c:\>java Welcome

Sample Output

Welcome to learndotjava 

TRY YOUR SELF

1)WRITE A PROGRAM TO PRINT YOUR NAME AND ADDRESS IN SEPERATE LINES

 

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips