Java Basics:Getting Started with Java

Here we will discuss some basics topics related to Java.

  1. Where to download Java.
  2. How to install Java.
  3. Setting up the Environment Variables.
  4. Our First Java Program.
  5. How to compile a Java application.
  6. How to run a Java Application.
  7. Difference between important terms in Java (JDK vs JRE or J2SE vs J2EE..).


How to Download Java

The latest version of Java can be downloaded from Java Website.

Java Installation

There are no special requirements when installing Java.  Be sure that you have suitable permissions on your computer to install software. It can be installed like any other software (.exe).

Setting up the Environment Variables

After installing Java there are some environment variables that need to be set.

  • CLASSPATH: This environment variable points to the location of the JDK home directory. It also contains the address of folder from where jars get loaded by ClassLoader (For more details of ClassLoader visit here)
  • JAVA_HOME: This environment variable will point to the location of the Java home directory.

How to set an environment variable in different platforms

Windows XP

To set up environment variables in Windows XP right click on the “My Computer” icon and select Properties. In the  Property window select the “ADVANCED”  tab and click on “ENVIRONMENT VARIABLES”. A window will appear where you can enter a new environment variable under System Variables by selecting New button.

Windows Vista / 7

To set up environment variables in Windows Vista / 7  right click on “Computer” and select Properties. In Property window select  “ADVANCED SYSTEM SETTINGS” and then select “ADVANCED” tab and click “ENVIRONMENT VARIABLES”. A window will appear where you can enter new environment variable under User/System Variables by selecting New button.

How to Check if Java is Installed

To check if your Java is installed properly open Command Prompt. To open command prompt write “CMD” in run command and hit enter. In the command prompt window write “java -version“.  If your Java is installed properly and all environment variables are configured correctly it will show the version of Java installed. Information reflected on the command prompt will be like

C:\Users\Jbt>java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) Client VM (build 25.51-b03, mixed mode, sharing)

If there is any problem while installing or in setting up the environment variable, the output on the command prompt will be as shown below.

'java' is not recognized as an internal or external command,
operable program or batch file.

How to check if Java is up to date

To know if the Java installed on your system is up to date Click Here.

Our First Java Program

Though the popular first program to write in Java is” Hello World !! “, here we will write a program to print ” Hello JBT !! “. 🙂

Open an editor and write the below code.

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

Save the file with the name “” in folder “c:\jbt”. Please note that name of the file should be same as the name given to public class(For more details regarding class file rules click here). Once the file is saved, open the command prompt and change the working directory to “c:\jbt”, where your file is saved. Write “javac to compile the Java code as below.

C:\Users\JBT>cd C:JBT



If the java file is compiled properly the compiler will create a class file for the source java. It will be saved in the same location as the source file. Since no package is declared in the given code the .class file will be created in the same folder location.

Notice the difference for Java files using package declaration. Let’s create another Java file as below.

package com.jbt;

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

Save this file as “” to “c:\jbt”. Now go to the command prompt and execute the below command.

javac -d .

It will create the class file in a corresponding package(com.jbt).

Now that you know how to compile Java file with a package and without a package, the next step would be run these class files.

How to Run Java Application

Now that your  Java file is compiled we can execute the application using the “java” command as below.

Without Package

C:\JBT>java FirstProgramme
Hello JBT!


With Package

C:\JBT>java com.jbt.FirstProgrammeWithPackage
Hello JBT!


C:\JBT>java com/jbt/FirstProgrammeWithPackage
Hello JBT!


Note*: The “java” command uses the class file name without its extension(.class).

With this, we are done creating and running our very first Java application.

In the next section, we will learn the difference between JDK and JRE.

<< History of java jdk vs jre vs jvm >>

175 Comments Java Basics:Getting Started with Java

    1. J Singh

      package is way of organizing java classes inside a project. You needs to have unique class name inside a package name. But class with same name can exist in different packages.

  1. Komal

    This tutorial is very helpful as I have just started learning ,I am getting things in correct manner ,and by following steps that are mentioned in the article, I’m getting things very easily and definitions are also very clearly understood.. 🙂

    Thanks & Regards,

  2. Vivek

    can i start learning java core even if i dont know C language or any basic concepts of c
    like even loops or syntex or even 0.% knowledge of c

  3. Prabhavathy. S

    I am graduated in finance and know nothing about computer programming. But I am so interested in becoming a software engineer. Can you please tell me if learning java will help me for the same?

    1. J Singh

      Hi Prabhavathy,

      I really don’t know the answer of this question. Just knowing java will not solve all your problem. But it will help you definitely. And learning java is not difficult unless you have good teacher.


    2. Srinivasa Tupurani

      I would like to share my real time experience here. I would say if you love programming go for it. Learning Java, gives you strong foundation for any IT professional line you desire. There are so many opportunities in IT like Business Analyst, Quality Assurance where one would expect to bring programming skills and Java is one among them. Within QA there are Automation programming tools like selenium. You can take this knowledge (Programming skills) and apply these skills in learning any other tool or building a Programming career (Entry level). Hope this helps!

  4. Srinivasa Tupurani

    I accidentally landed on your page while I am googling for Java Tutorial for my nephew.
    I have gone over this blog. The Tutorial was been built with very good thought process.. I would say If one spends their time, they certainly end up with strong foundation level in JAVA which I feel many of the IT professionals certainly need.

  5. Qlems

    Am a student of medicine who is trying to learn JAVA and belief you me , your tutorial is exceptional . I really love the systematic explanation.
    On point. We need people like YOU to help us understand software environment.


Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.