Getting Start With JAVA

Topic Covered:

1. Downloading Java 

2. Installing Java 

3. Environment Setting (Setting the Class Path)

4. Writing a hello world program in java.

5. Compiling the JAVA program.6. Running the JAVA program.

1. Downloading JAVA
Programming in JAVA requires JDK (Java Development Kit) which comprises (JDK & JRE). JDK is required for compiling Java codes, after compilation it create .class files. 


Ex:- "Hello.java" is a java program file written in plain text. After successful compilation JDK produce a "Hello.class" file which is a Byte Code of that java program file.
To Run this "Hello.class" file we require JRE (Java run-time environment). So, Developers Requires JDK in their machine but client require only JRE which is small in size and platform independent.

What is platform independence:[Develop any where and run any where] Since Java program produces byte codes and JRE convert it to machine language code so we can develop the program on any OS and can run the program on another OS. JRE is OS dependent. So, JRE works as middle man between java class files and java machine codes. 

The link for downloading JDK is :

Download JDK8 update 25

2. Installing Java

Double click the downloaded file "jdk-8u25-windows-i586".

Click Next


Click Next


Click Next


Click Close. Now the installation completed.


3. Environment Setting (Setting the Class Path)

For Environment Setting Press Windows+Pause key together or right click on Computer Icon and select 'Properties'.

Now Click on 'Advance System Settings'



Now Click on 'Environment Variables...'

User Variable is for "Current User" only but System Variable is for all users. So we set 'System Variables'

Click on 'New..' in 'System Variables'.
Set Variable Name 'JAVA_HOME' and value :'C:\Program Files\Java\jdk1.8.0_25'. The value is actually your java installation folder path (It may be different in your machine). Now Press 'OK'.

Now Edit the 'Path' variable. Give the path up to 'bin' folder of java installation directory. JAVA_HOME path is before 'bin' directory. JAVA_HOME is used by IDE, Web Container, Server, Application Server etc. Path variable will make java available for compiling programs.

Path variable is already exits and have some values. we have to edit and insert our java class path value. Path variable consists of more than one values separated by semicolon ';' so add semicolon in the last and put the value up to bin directory.
i.e. C:\Program Files\Java\jdk1.8.0_25\bin;     or  we can set it like %JAVA_HOME%\bin; because path before bin is stored in JAVA_HOME environment variable.


Now check path variable is working or not, check it by opening 'cmd' and type : java -version
it will give the current version of java installed.



4. Writing a hello world program in java.

Now it is time to create our first program in java
Open Notepad and type :
//-------------------------------------------------------------
class Hello {

   public static void main(String args[]){

System.out.println("Hello World From Java!");
   }

}
//--------------------------------------------------------------


Now save it with a java extension like : "Hello.java". Try to give same name as in the class name.


5. Compiling the JAVA program.6. Running the JAVA program.

 Now Compile it by using javac command and run it by java command.


Hello.java file is created on desktop. so we have to move to desktop in commnad window.
>cd Desktop
now compile it by giving following command
>javac Hello.java
after successful compilation it will create Hello.class file. Now run it
> java Hello
The result will be displayed on the console. 

No comments:

Post a Comment