Just as we humans use different languages to interact with each other, similarly, computers have their own languages through which we can communicate with them. These languages are broadly of two types: High Level and Low Level Languages.
One very popular High Level language is Java, which can be used to write efficient programs for the internet and the world wide web. Java can also be used to write programs for other environments such as consoles and mobile phones, but its popularity is mainly because of its power to generate robust applications for the internet. Today we’ll see how to write a small program in Java. When you begin learning a computer programming language, it is customary to write the "hello world" program as your first. This program tells the computer to display the text "Hello World!" on the computer monitor. It’s like telling the world that you are the newest member on board the Java bandwagon. So let’s get started!
- Navigate to www.java.sun.com and download the Java JDK or Java SE, not JRE (Java Runtime Environment). Once its downloaded, install it. Then restart the computer.
- Open the text editor and write the following code:
public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World!");}
}
- Save this code as HelloWorld.java. In Windows, make sure you choose the "all files" option from the file type drop down list box, otherwise it will be saved as a text file and not a .java file.
- Click start > run and type command or cmd (try each and see which one works for your operating system).
- From the command prompt, drill down to the folder where you saved the HelloWorld.java file. (type "cd <name of folder>" you can use tab for auto completion)
- Type the following: javac HelloWorld.java and press Enter. You should see that after thinking for a while the computer returns to the command prompt.
- Type "java HelloWorld" (no quotes) and see what happens. You should see the text "Hello World" displayed on the monitor right below where you issued the java HelloWorld command.
