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.

175 thoughts

  1. Hi get this error after run the command
    Error : could not find or load the main class FirstProgramme

    please answer.

    the same ^ just answer what should we do so in the future people not need to wait abswer

  2. problem solved just set(or type) in cmdpromt.. setpath= C:Program FilesJavajdk1.7.0_10bin or where are ever you saved your jdk file i hope thats help you

      1. seting path is simple…
        follow these instrucitons in ur command prompt…
        1. cd
        2. cd java
        3. cd jdk1.6.0_03
        4. set path=c:javajdk1.6.0_03bin
        5. cd bin

        to enter any file inside ur bin folder follow this..

        6. cd foldername
        ex: cd threads

    1. Hi,

      Thanks for your response. I will update the article asap. Meanwhile before you compile source code check if path of javac is in the class path. To check it execute the command “javac” in command prompt.
      If response is
      ‘javac’ is not recognized as an internal or external command,operable program or batch file.

      It means path is not set currectly. To set the pat go to enviornment variable section of computer properties.From there set the path of javac.”C:Program FilesJavajdk1.7.0_10bin”.
      Note this will be permanent and you don’t need to do the same thing of setting path again and again.

      Thanks Max again for pointing this.

    1. Hi Bharat,

      #1 You have to set path as C:j2sdk1.5.0_04bin and class path as
      #2 Open cmd and hit this target “java -version”, it shows
      java version “1.6.0_17”
      Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
      Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)
      #3 On cmd hit this target “javac”, it shows
      Usage: javac
      where possible options include:
      -g Generate all debugging info
      -g:none Generate no debugging info
      -g:{lines,vars,source} Generate only some debugging info
      -nowarn Generate no warnings

      Now run the programme as per Above …………….
      Hope this is help you guys …………… 🙂

  3. Hello Sir,
    I am a beginner of core java. Tutorials are helping me a lot. but can you tell me, Where can i have exercise for practice. How one can develop a logic in programming?

    1. Hi Kamlesh,

      Soon i will upload the list of assignment that you can take help from and start developing the code.


  4. hey admin 🙂 its a rly cool site wanna know if this would help me to pass oracle jse 7? and anther thing if there any video tutorial ? to it thx alot 😀

    1. Yes, You can develop or run Java application in any major platform including Linux. You just need to download JDK specific for Linux. And you can start developing application. Click Here for different versions of JDK version for different platform.
      You can also download Eclipse for Linux from here


  5. hey iam a beginner..i jus wanna learn from these ol tutorials..soo after writin a program n savin dat what should we do for compiling???i mean whatz d next step…???i immeditly writin d program i jus got to cmd n did what yu said but the error JBT cant be recognised by an internal or external command,z plz suggest me a solution admin…

  6. my javac not working when i run my program with javac it give statements javac is not recognized external &enternal then what should i do for compiling java program

    1. Hi Garg,

      It seems like JDK is not installed in your system. Please install the same and check if javac is working or not(JDK and not JRE). If you have already installed then check if path for bin is already added in environment variable or not.

      It should resolve your problem.


  7. where i can see my jdk file.? in bin folder i seen jre file. when i can set the path it shows javac is not
    recoginsed as an internal or external command. whats the reason? please tell me

    1. Hi Kalpana,

      You must download and install JDK from Oracle website and not JRE. Once you install JDK folder instide JDK should be like below


      If everything is installed properly you should see javac executable(javac.exe) file in bin folder.
      If it is not therer then you have not installed JDK properly. If you confirm that JDK is installed properly then add path till bin to classpath /path in enviornment variable. Then only windows will be able to recognise this command.


  8. kumud,
    i found error like ,Class names, “Example”, are accepted only if annotation processing is explicitly request
    please suggest me for this error

  9. hello sir,

    my programm doesnt compile.i was install jdk properly.i also set path but still its give me an error like ‘javac’ is not recognize as an internal or external command,
    operable programm or batch file.
    pls give suggestion

    1. Hi Sneha,

      Sorry for the late reply. As you can system is throwing an error of knowing command. In simple way you can say that your operating system(Windows) doesn’t know where this javac command(path).

      So to make OS understand you have to add path of javac in path in enviornment variable in My Computer.

      To know how to set path in windows you need to search on google or you can search article written by me.

      Hope this help.


  10. Hi,

    when i type javac it gives me all the options properly and i cud see java -version also.after compiling i cud see a class file created in the folder.but when i type java says ‘Could not find or load main class FirstProgramme..pls help me where im gng wrong

    1. Hi babbu,

      There seems to be some problem with your source code. Java seems to be installed properly. Please share the source code i ll check and let you know what is the problem..


  11. Hi,

    Below is the code i was trying,same as u have mentioned ..pls check
    public class FirstProgramme {
    public static void main(String args[]) {
    System.out.println(“Hello JBT”);

    1. Hi Babbu,

      I don’t see any issue with given code. I am able to compile and run the application without any problem.

      I hope you have executed below command in sequence

      java FirstProgramme

      I am able to execute the command without any problem and output get displayed properly.


  12. The code is getting compiled but while running the .class file it is showing the following error.
    Please look into the matter.

    java.lang.ClassNotFoundException: FirstProgram$ Source) Method) Source)
    java.lang.ClassLoader.loadClass(Unknown Source)
    sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    java.lang.ClassLoader.loadClass(Unknown Source)

    1. Hi Amriteya,

      If class file is create properly and java is not working then it might be the case that current folder is not in path(Enviornment variable) of your OS.
      Please check all you path, classpath in enviornment variable. It should contain . as . represent current folder in windows OS.

      For your reference you can check my path entries.

      .;%M2%;%JAVA_h%;C:Program FilesJavajre7lib

      Here i have added . so it will compile and run wihout any problem.


  13. Thanks to Mr. Vivekanand Gautam.
    I truly appreciate your time and effort to make this Website.. It’s wonderful & easy to learn 🙂

  14. i have downloaded JRE7 from the link mentioned above .So, i want to know whether i have to download JDK or nor.

  15. Hi,
    am begineer to this java. i have downloaded and installed the java s/w but i couldn’t find shortcut key to open and run the s/w. actually wats the problem with it? could you plz provide java programming tutorial?
    thank yu

  16. i have successfully installed java and i have checked it also in cmd… then i wrote the program in notepad and saved it as .java (and file name same as in the 1st line of programme). then in the next step again in cmd to change the file destination when i am writing the given codes, its says error “cant specify path file”.. plz help me out.

  17. My teacher say make ur first love java … i think now its possible…this site is awesome to learn things in very deep..
    Thanku sir…

  18. hi
    u just stopped after clicking on the new button. what to after clicking on the new button, its showing two blanks areas what i have to enter

    1. Hi Kavi,

      I think you are talking about Environment variable settings. When you click on New button a window will be opened. In that window provide the environment variable name and value for the same.

      Variable Name : JAVA_HOME
      Variable Value : C:Program FilesJavajdk1.7.0_15

      Hope this helps


  19. Dear sir

    Please help me.

    I have installed the java software as to told at above, its installed successfully but when I test it then it shows the problem(‘java’ is not recognized as an internal or external command,
    operable program or batch file.)

    Please help suggest me what should I do.

    1. You have to set the path variable for java..
      Right click on My Computer and select properties.
      Select advanced system settings.

      Click on environment variables tab.
      Now under user variables section , add a new variable with it’s path being the installation directory of java.

    2. Try editing the Enviroment variables, make sure you include the semicolon before you write the path of where your JDK was installed, or it will not work. if you did install it in the same directory as the tutorial, your path should be:

      and your path variable should look like (On the end of it):

      if that doesn’t work, try making a folder in the jdt folder, that should work as long as you specify the directory.

    3. Did you install the Java JDK and also check the version you have installed if the latest version is not supporting then try to install the lower version.

  20. Dear sir

    Please help me,

    I have installed the java two time as you instruct above but after successfully installed the software it shows the problem (‘java’ is not recognized as an internal or external command,
    operable program or batch file.)

    Please suggest me what should I do.

  21. I know the java basic and im using netbeans , i want to learn run in core java means netbeans is enough or any other tool want to download ?

  22. hiiii sir,

    Please help me i m the beginer and dont know anything about java plz send me the notes on my mail id..

  23. This is good website to learn programming language …… thanks admin for supporting us to learn different programming language easily …..

  24. Hi Admin,

    I followed your steps to install Java from the link provided. While setting the environment variables I saw that there are only bin and lib folders, there is no jdk folder. Please let me know why I might be facing this problem.

  25. Hi Sir

    I am a php developer and trying to get the basic java understanding, I am using Eclipse and create the java application .but its very terrible it to run in eclipse.
    Please Give direction For Eclipse


  26. I think your page has the missing link. I couldnot find the page which contains the difference between JDK vs JRE …..

  27. Please tell i can’t understanding this kind of error, Program is ex cute but out put like this tell me Sir.


    C:UsersacerDocumants>java FirstProgramme
    Error: Could not find or load main class FirstProgramme

    1. Hi Poola,

      Sorry for late reply. Probably you have not used Public Access modifier with class name. Please check the same and update
      the class name accordingly and compile and run program again.

  28. Dear Vivekanand,

    Your site was recommended to us by out QA teacher in California. I love your site. Thank you for your time and hard work.


  29. Thank you Sir but now i worked different way i have use on-lee PATH Sir I’m not use CLASSPTH. this is cure-ct way. tell me Sir.

    1. i think u have to set CLASSPATH variable.. and that should refer to your file’s class path

      ex : dir/ ….. after compilation ….. dir/Firstprogram.class

      CLASSPATH -> C:/dir

  30. Hi Sir,
    Very good work but you try to explain about each and every word and line sir.
    I mean like what is use of using the word PUBLIC,ARGS,[]…..
    everything then everyone would come to know the use of the words written in java program.


    1. Hi Avi,

      You just need to understand eclipse have different build release for different languages.

      There is no specific version just pick the java specific build and it will work for Java.

      Here you can see different build to download. Select only java specific to download for different platform(Windows/ Unix)

      Hope it help.

      Vivekanand Gautam

  31. This is very good website..
    Sir, can you give me any idea about Or Java is good for future..??

  32. i have NEWLY installed JDK1.8.0 and netBeans 8.0.2version
    Problem:i have run below program getting run time error my coding below
    import java.sql.*;

    public class jdbc
    public static void main(String args[]) throws IOException

    try {
    Connection con = DriverManager.getConnection(“jdbc:odbc:ba”);
    Statement select = con.createStatement();
    ResultSet result = select.executeQuery(“select * from test”);

    System.out.println(“Got results:”);
    while( { // process results one row at a time
    String val = result.getString(2);
    System.out.println(“User_Id = ” + val);

    catch( Exception e ) {
    System.out.println(“connecting error”);


    set path:JAVA_HOME=C:Program FilesJavajdk1.8.0_40
    PATH=C:Program FilesJavajdk1.8.0_40bin;

    while running time error meg like below
    connecting error
    java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(
    at jdbc.main(

    please advise how run the above program please advise me

  33. You are the Best MR.Authors. You work hard to help people.Thanks a lot for you Mr.Author and

    Gautam.You are the Best…….

  34. hi sir i have planning to try for job with 1 yr exp in java , i have sound knowledge on j2se,j2ee,hiberate is it enough or want to learn anything pleas help me

    1. When I was trying to get new job, I viewed online job postings and read the requirements to know exactly what I should know. It allowed me to research/learn the things that I didn’t know, and I was able to get the job. Hope that helps you!

  35. I am new to JAVA. While executing the said script it is showing the below error. Wht should I do further
    C:Program FilesJavajdk1.7.0_71bin>javac C:UsersRekhaDesktopjava1.j error: illegal character: 8220
    System.out.println(ôHello JBTö);
    ^ error: ‘;’ expected
    System.out.println(ôHello JBTö);
    ^ error: illegal character: 8221
    System.out.println(ôHello JBTö);
    ^ error: not a statement
    System.out.println(ôHello JBTö);
    4 errors

  36. Hi,

    I have installed java successfully and also defined the ClassPath and Path in the system variables settings as follows
    JAVA_HOME C:Program FilesJavajdk1.8.0_40

    while executing C:UsersUserDesktop>javac
    C:UsersUserDesktop>java FirstProgramme
    Error: Could not find or load main class FirstProgramme

    Please help to fix this.


    1. @meghana

      Did you resolve your problem check your main block it should it should read :
      public static void main(){}

      not Main or its missing totally

  37. 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

  38. Sir, can u plz suggest me a bestest Java project which I can make and can make a great impact on everyone by showing that project

    1. When you change the environment variable with the JDK’s path. reload the command prompt and then type c:> javac -ver

      if you see the version of JDK. Then you are good to go

  39. hey..I have installed java using sudo apt-get install openjdk-7jdk. i am able to compile programs but not run any. if the program is error free it compiles successfully but when I try to run it, it says
    Exception in thread “main” java.lang.UnsupportedClassVersionError: client : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    Could not find the main class: client. Program will exit.
    please help me out as how i can solve this.

    1. Navya, you should java’s path in environment variable…
      Follow the following steps:
      Select Computer from the Start menu
      Choose System Properties from the context menu
      Click Advanced system settings > Advanced tab
      Click on Environment Variables, under System Variables, find PATH, and click on it.
      In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
      Reopen Command prompt window, and run your java code

    1. There is no direct linking between C++ and Java. So yes you can learn java without knowing C++. Knowing C++ will help you in java, as some concepts are common but that will give you starting advantage but still you can learn java from scratch.

  40. Hello Sir/Madam,
    Actually i am planning to move another project, for that management team asked me to learn Core JAVA, so is it possible to learn at least basic concepts of CORE JAVA within ten days?????
    Please suggest me ASAP,
    Would you please reply me at your earliest convenience so that i can address your suggestions?

    Thanks in advance!!!

    1. Hi Giri,

      There is no direct answer to this question. It all depends on where you are coming from. If you have learned C++ and then i might say you can learn a bit about Java. But in the end 10 is not enough to learn any language. But still in indian companies you don’t need to be rocket scientist to work on any project. So just start learning java soon you will learn enough to work.
      Best of luck for your new project.


  41. Hey ,
    Thank You for providing such awesome courses of core Java to students. You are doing a great work indeed.
    I got a suggestion for you.
    I have seen that there are a few untapped topics in this “Getting started with Java” tutorial , which I found are in the following article with the same topic.
    I would suggest you to add the matter here which will be beneficial for the students/readers.

    Thanks again you this awesome work. Hope you will take my words into consideration.

    1. 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.

  42. 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,

  43. 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

  44. 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. 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. 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!

  45. 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.

  46. 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 Reply

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.

Back to top Search