The Java Development Toolkit ( JDK ) must be downloaded and installed. In Windows 8, the default installation path is:
1 |
C:\Program Files\Java\jdk1.8.0 |
Step #1: Confirm if Java is installed
Open the Command Prompt (Press Win + R, and type cmd, press Enter ). Once the command prompt launches, it should look like:
Now, type:
1 |
C:\Users\Dhiraj Jha>java -version |
Make sure, they are spelt correctly and in small-caps.
This confirms that, the JDK is installed and we are ready or we go to step #2.
Step #2: Look for the folder and set environment variables
You might find the following error on the command prompt:
You can verify the default installation path and see whether the folder is at the aforesaid location or not. If missing, re-confirm, it might have been accidentally placed at some other location while installation. Otherwise, re-install the JDK with default settings for the time being. Go to Step #3.
Step #3: Setting up the Environment Variables
Right Click on My Computer ->Properties->Advanced System Settings->Environment Variables
Within the System Variables, set few variables:
- JAVA_HOME : This is the path to the installation directory of the Java Development Toolkit.
1 |
C:\Program Files\Java\jdk1.8.0 |
- Path: This is the path for the binaries ( \bin folder). There might be some other values within the Path System Variables, so place the following code at the beginning.
1 |
%JAVA_HOME%\bin; |
Make sure, there are no white-spaces between the % and \ characters.
Click on OK->OK->OK. This will close the System Properties window.
Now, close the command prompt (if already opened). Re-open the command prompt, and check for these commands:
1 |
C:\Users\Dhiraj Jha>java -version |
1 |
C:\Users\Dhiraj Jha>echo %JAVA_HOME% |
1 |
C:\Users\Dhiraj Jha>echo %PATH% |
and you should see the following:
Step #3: Write Simple “Hello World” Program in Java
Open Notepad and type the following:
1 2 3 4 5 6 7 8 9 10 11 |
//Hello.java public class Hello { public static void main( String[] args ) { System.out.println(" Hello World"); }//main method ends }//class ends |
and save the file at the location d:\java_codes just for the time-being. Type the following code:
1 |
C:\Users\Dhiraj Jha>d: |
1 |
D:\>cd java_codes |
In order to compile the file:
1 |
D:\java_codes>javac Hello.java |
In order to see that a (.class) file with the same name as that of class is generated called, byte codes:
1 |
D:\java_codes>dir |
In order to execute the application, the utility is java
1 |
D:\java_codes>java Hello |
The output looks like:
Hopefully, this article will help newbies for their first step towards Java Development. Happy Coding!!!
Leave a Reply
You must be logged in to post a comment.