Java Setup Hello World Example

In this post, I am explaining the Java Setup to run a Hello World Example for beginners.

Java Setup Hello World Example

First of all we need to download open source java software from official oracle site. Download

You can download java software according your system configuration i.e. 1. Operating system (Linux, Mac OS, Windows, Solaris etc..) 2. Bit (32 bit, 64 bit)

After downloaded, you can install by click on .exe file and it will be installed in the default directory like as follows.

For Windows : C:/Program Files/Java/

For Solaries / Linux / Unix : /usr/java/

Once you installed Java on your machine, you would need to set environment variables to point to correct installation directories:

How to set system environment variables

System environment variables need to be set if you are going to using javac command to compile the java file in windows, linux, unix, solaries etc.. and java command to execute the java complied file  in windows, linux, unix, solaries etc.. and using notepad tool to create java program. Now a days we have IDE like Eclipse, Netbeans, MyEclipse, Jdeveloper etc… which are having all types of commands in-built like java compile, java execution, jar file creation, war file creation etc…and also supporting many types API like Java API, Advance Java API, HTML, CSS, Spring, Hibernate, Struts etc… to build project quickly.

Set Up In Windows

Assuming Java you have installed in this path C:\Program Files\Java\jdk1.7.0_65

Right Click on My Computer and select Properties

My Computer Properties

My Computer Properties

Click on the Advanced system settings in the left side panel in Windows 7

Advanced System Variables

Advanced System Variables






Click on the Advanced tab in the top tab bar.

System Properties

System Properties












Click on the Environment Variables

Environment Variable

Environment Variable












You can set either User Variables (These variables are applicable for your current user) or System Variables (These variables are applicable for all users)

Click on New in User Variables if PATH  variable not is not exist and add the PATH in the Variable name and C:\Program Files\Java\jdk1.7.0_80\bin in the Variable value click on OK.

Path Environment Variable

Path Environment Variable







If PATH variable already exist then select the PATH variable and click on EDIT. And add semicolon ; in the end of the line and add C:\Program Files\Java\jdk1.7.0_80\bin after the semicolon ; click on OK button in all windows.

Now we can check it out whether variables are properly set up has been done or not.

Open windows command prompt like click on Start button and type cmd in the search .

  1. Type javac and press enter key
  2. Type java and press enter key.
javac class path check

javac class path check

Java Setup Hello World Example

Java Class Path Check











It means PATH environment variable set up has been done successfully and now we can compile and execute the program in the windows command prompt.

Set Up in Unix, Linux, Solaries etc..

In these environment we do not have any user interface like windows so we need to set path through commands only.

Once you logged into these system, you should be exist in your profile root directory by default. In this directory you can find .profile file by using ls -lart command. we will discuss unix / linux frequnctly using commands in another session.

  • Type vi .profile
  • Add the installed java path like :/usr/Java/jdk1.7.0_80\bin to end of the PATH variable;
Unix Path Variable

Unix Path Variable







  • Press Esc and enter ; wq   –it means file has been saved.
  • Compile .profile like ./profile
  • Then type javac and press enter key, see the details.
  • Type java and press enter key, see the details.

Now system is ready to run the java program so write the one java program in the notepad and compile and execute as follows.

Java Program

 class Helloworld {

    public static void main(String args[]) {



How to compile

  • Save it as in any folder.
  • Open windows command prompt and go to the location where the above java file has been saved.
  • Type javac and press enter key then .class file will be generated.
  • Type java Hellowrld  and press enter key then we will get output like Helloworld

I hope you understood the setup of java in different machines and how to compile and execute the java program. If you have any queries or suggestions please comment below and we will get back to you. 🙂

The Author


Hello! I am Narayanaswamy founder and admin of I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

Leave a Reply