This workshop is for you, if you think:

  • I read a lot about bytecode
  • I never got my hands dirty with code yet
  • I never got past ClassCastException

This workshop is not for you, if you are:

  • A Java guru having experience since donkey's age so you should be here to provide others with some useful articles
  • Looking for basics and fundamentals of Java

"Hello World" Heck!

We need JDK for compiling our source Java file to class file (bytecode). So, we do not have JDK installed in our system, we need to install it first. The below steps provide details regarding installing JDK and setting up Java Path Environment variable:

  • Download JDK from Sun Java website and install it, say, at "C:\Program Files\Java\jdk1.6.0_10"
  • Navigate to your Environment Variables by right clicking "My Computer" selecting "Properties/Advanced/Environment Variables"
  • Create a new User Variable name "Path", if it does not already exist, and set the variable value as the complete path of the bin directory of JDK i.e."C:\Program Files\Java\jdk1.6.0_10\bin" in this case
  • If the variable name "PATH" already exist in the system variable, then make sure it points to the right directory where the JDK is installed.
  • Note that more than one value can be set to Path variable with semicolon (;) as value separator.
  • Another way you can set the Path in User variable is through the DOS command prompt.
  • Go to Start menu choose Run and then enter cmd hit enter, you will see the Command Prompt.
  • Execute the following command "set Path="C:\Program Files\Java\jdk1.6.0_10\bin"
  • This can be verified by executing "echo %Path%". This should return the "C:\Program Files\Java\jdk1.6.0_10\bin" value.

     

  • It should be noted that the scope of the Path variable set from the command line is limited to the life time of the DOS Command Prompt session and is applicable only to that specific session of DOS Command Prompt.
  • So, we highly recommend that setting of Path User variable is to be done from "My Computer".

My Hello World Java code

  • Take some simple editor to start with like notepad or textpad.
  • Create a HelloWorld.java application as below
    public class HelloWorld {  
          public static void main(String[] args) { 
              System.out.println("Hello World"); 
          }
    }  
  • Save the file as HelloWorld.java somewhere on your local system, say, at the following location "D:\Hello World Workshop".
  • Open Command Prompt as explained in previous steps and navigate to Hello World Workshop directory with the help of following 2 commands
    "D:" and "cd "Hello World Workshop".
  • Compile the HelloWorld.java file as "javac HelloWorld.java". This will create the HelloWorld.class file in the same directory.
  • Next step is to order Java Virtual Machine to run the HelloWorld application for you. Execute the following command "java HelloWorld"

     Hello World Execution

  • On successful run, you will get the output "Hello World".

Welcome to Java Land!

 

We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.