Posted by : Unknown Tuesday, 9 June 2015

Getting started with Java

Developing / Writing a Program

        To write a program in text editor like node pad. Take the following simple program.

class HelloWorld  
{
    public static void main(String args[]) 
   {
        System.out.println("Hello World!");    
   }
}

Here HelloWorld is the class name of the program. Choose the following directory to save the file:

C:\Program Files\Java\jdk1.6.0\bin

On Windows, the JDK is placed in the following path or directory by default:

C:\Program Files\Java\jdk1.6.0

Then save this file like "class name.java" i.e., HelloWorld.java.

Compiling the Program 

Syntax: javac filename.java

First open the Command Prompt (Press windows key+R then type "cmd" and hit Enter). Then type following code:

cd  C:\Program Files\Java\jdk1.6.0\bin

Execute the following command to compile your source file to bytecode:

javac HelloWorld.java

Note: If you do not set the PATH variable correctly, when you use the JDK’s tools, you will receive a message like:

'java' is not recognized as an internal or external command,
operable program or batch file.

Running the Program

Syntax: java classname

Finally, to execute the program using the following command:

java HelloWorld

Output

Hello World!

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Translate

Popular Post

Total Pageviews

Blog Archive

- Copyright © Learning Java Program - Powered by Blogger -