Wednesday, 29 January 2014

Write a simple JAVA program in Notepad and compile with javac

This is another in a series of videos that I am producing for my YouTube channel HowDoYouDoStuff.

In this video, I am going to show you how to write a simple JAVA program in Notepad and compile with javac

You can read the transcript below.

HTML 5 Player


Hi guys. I'm Phil Stirpe.

In this video, I am going to show you how simple it is to write a simple JAVA program in Notepad and compile it with javac.

In an earlier video, I showed you how to download in install the Java Development Kit - JDK.

I also showed you how to define a number of environment variables so that Windows could locate the JDK files no matter where you were on the command line.

In this video, I just want to write a simple program to test that everything is working as it should.

So I'll create a new folder off the Desktop named FirstClass to work in.

Next, I'll create a file to contain my java class. I'm creating it as a text file because that is what code files usually are.

Now convention has it that the first program that you write in a language should be the classic Hello World app but I'm going to call mine hiGuys and change the extension to .java rather than .txt.

I am proud to say that I have never written a Hello World app. Well I'm either proud or pedantic.

Right. Let me edit that file in Notepad so that I can add some code.

You write a simple class by typing in the keyword: class followed by the class name. In this case hiGuys. This in turn should be followed by a pair of curly braces to define the scope of the class.

As I want my program to run independently on the command line, I must provide it with a main method which should be a public static that returns a void (or nothing).

The main method should have a pair of curly braces also.

Actually, I should probably add a string array named args to capture any command line arguments. I don't need them in this program but it is very common.

OK. I just need to add one line of code to this method. I want to call the println method which is defined in the System.out package. And I'll pass the method my string message of "Hi guys!!".

Not forgetting the semi-colon that needs to terminate each statement.

This is a very simple class containing a single method.

I just need to save it before moving on to the build process.

To build this I need to go to the command line.

Let me make a note of this folder location first.

Now I can open the command line and then change directory to the location of my source file.

Now although the source file is here, the compiler isn't.

Remember though that I have added a path to the compiler in the Environment variables.

So I can go ahead and type in javac and press enter.

Note there is no echo here but my source code has compiled.

We can see the compiled code here in the folder. It has the class file extension.

The fact that my code compiled proves that not only has java and the javac compiler been installed but that I have also set the correct paths in the environment variables.

In order to run or execute my code, I now need to type in java higuys which is the file name given to my compiled code.

My mistake. That cannot run. I forgot that java is case sensitive and I had used a capital G in my name.

So this time, I'll try java hiGuys.

And there you go, my message is echoed to the console.

So there you go.

In this video I showed you how to test the JDK by writing a simple class, building it with javac and running it with the java runtime environment - JRE.

Now it is all well and good to write simple code in Notepad but in the real world, developers use more powerful tools to do their development. One such integrated development environment - IDE tool is Eclipse and in my next video, I will show you how to download and install it.

Thanks for watching this video. I hope you found it useful. Feel free to comment on my blog ( and Facebook page ( Perhaps you could suggest more video topics? Most of all, don't forget to subscribe to keep up with my videos as I release them.

Bye for now.

Flash Player

See you soon

Phil Stirpé
"I don't do average!"


  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

  2. You left me wowed, I feel luck I found your website. Keep producing the great content Assignment writing services in UK