Hello World in Java on Windows

If you are a new programmer or already an programmer and want to learn Java, this article is for you to get started in Java by writing “Hello World” program to make sure you compile it on your computer.

The first step is to go to Oracle Site (Since Oracle acquired Sun Microsystems in 2010) and download latest version of JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html

Image

Select the appropriate JDK File. Example, if you are an windows user, select Windows x86 or Windows x64 accordingly.

After downloading, Install Java SE Development Kit

Now add Environment variable at Computer > Properties > Advanced System Settings > Environment Variables > System variables > Path

The path is the bin path of the installed jdk, as in this case is: c:\Program Files\Java\jdk1.7.0_05\bin;

After that go to command prompt to verify the Java is installed and check the verion at command prompt by writing:

java -version
javac -version

You should get the version information accordingly and it should match the version installed otherwise there is something wrong with the environment variable path.

Since JDK is installed, you are ready to write your first Hello World program in Java.

Open notepad and write the following code:

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

Save the file at some location (say, C:\test\) with the name “HelloWorld.java”

Open the Command prompt.
Navigate to C:\test
run javac HelloWorld.java
If there are no errors in the program, it will go to command prompt without displaying anything.

The compiler has generated a bytecode file, HelloWorld.class. Check this file at C:\test\HelloWorld.class
Now that you have a .class file, you can run your program.

 

Now that you have class file generated, run java with name of class, which is HelloWorld


run java HelloWorld
The string “Hello World!” will be displayed in Command Line.


Hurray! This was your first successful Java program.

 

Advertisements

One thought on “Hello World in Java on Windows

  1. I’m not that much of a internet reader to
    be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your website to come back down the road. Cheers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s