Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

Java

Learn step by step



Getting Started with Java

How to Download Java

Latest version of Java can be downloaded from here.

Java Installation

Once downloaded Java can be installed like any other software(.exe) on Windows.

Setting Environment Variable

After installing Java there are some environment variable that needs to be set.

CLASSPATH : This environment variable should be declared in system variable. This env variable points the location of JDK home directory. It can also contains the address to folder from which you want jars to get loaded by classloader(For more details of ClassLoader visit here)

JAVA_HOME : This environment variable will point to the location of Java home directory.


How to set environment variable in different platform

Windows XP

To set environment variable in windows XP right click “My Computer” icon and select properties. From property windows

Windows Vista / 7

To set environment variable in windows Vista / 7 right click “Computer” and select properties. From property windows select “ADVANCED SYSTEM SETTINGS”. In System Properties window select “ADVANCE” tab and then click “ENVIORNMENT VARIABLES”. In next window enter enviornment variable under user/system variables settings.


How to Check if Java is Installed

To check if Java is installed properly open COMMAND prompt in windows OS. To open command prompt write “CMD” in run command and hit enter. In command prompt window write “java -version“. If Java is installed properly and all enviornment variables are configured correctly it will show version of Installed version. Information should be like

C:UsersJbt>java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)

Write First Java Program

Here we will learn to write first Java program. As usual first Java program would be “Hello World”. But we will change it to “Hello JBT!”.

If everything till now is configured properly then we can start writing first application. Open any editor and Write below code.

public class FirstProgram {
public static void main(String args[]) {
System.out.println("Hello JBT!");
}
}

Once finished edition save the file with name “FirstProgram.java“. Note name of the file should be same as given as it is public class. Once file saved open the command prompt and change directory where file is saved with cd command. And fire “JAVAC” command which is used to compile the java code as below.

C:UsersJBT>cd C:JBT
C:JBT>javac FirstProgram.java
C:JBT>

As java file is compiled properly compiler must have created a class file for the java source file in same location or other depending on package declaration. As there is no package declaration in given code so .class file will be create in same folder as java file.

How to Run Java Application

As java file is compiled with “JAVAC” command. We can now run the application. To run above program. Fire “JAVA” command as given below.

C:JBT>java FirstProgram
Hello JBT!
C:JBT>

Note*: here we are using only the class file name and not extension(.class). It is required to not use .class extension. Here we are done with Creating and running our first Java application. In next section we will learn what is the difference between JDK and JRE.



Related Videos