Install jdk and write your first program


Today I am going to show you how to install jdk in your computer.

HOW TO INSTALL JDK ON (WINDOWS)?

  1. Click here to go to the download page of JDK.
  2. Find out the following image in that page and just click on "Accept License Agreement" and download the JDK according to your OS version.
  3. Now double click on the downloaded file to run the installation program.
  4. Keep clicking on Next or OK.
  5. Do not change the installation location for both jdk and jre.
  6. Memorize the location where you have installed jdk.
  7. If you did not change the download location then:-
      1. Go to this location C:\Program Files\Java\jdk1.8.0_101\bin
      2. Now copy the location.
      3. Go to My computer
      4. Click on System Properties.
      5. Click on Advanced System Settings.
      6. Click on Environment Variables.
      7. Now Find the variable called path in User Variables.
      8. Click on it then click edit.
      9. Now Do not delete anything written in Path.
      10. To update it just put a semicolon at the end (;) then paste the location you just copied.
      11. click on ok.
      12. Now open command prompt and type java
      13. if you find this then you are ready to go.
      14. IF YOU DO NOT FIND THE PATH VARIABLE THEN CLICK ON NEW AND THEN TYPE PATH IN THE VARIABLE BOX AND PASTE THE LOCATION IN THE VALUE BOX AND SAVE IT.

HOW TO INSTALL BLUEJ?

  1. Click here to go to the location.
  2. Download only the bluej and not oracle jdk from the site according to your os version.
  3. Install it.

HOW TO WRITE PROGRAM IN YOUR NOTEPAD?

  1. Open Notepad.
  2. Type your program.
  3. Save it as .java file by typing Filename.java and then selecting "All files" from the dropdown.
  4. Open Command prompt.
  5. go to the folder where you saved the file from command prompt. For example if you saved your file on desktop then type  "cd desktop"
  6. Type javac Filename.java
  7. If there is no error then type java Classname.

HOW TO WRITE PROGRAM IN BLUEJ?

  1. Open Bluej
  2. Click on file-> New project. (This step should be done only once. Only after installation you do this step. Do not do it always.)
  3. Click on new class
  4. Type a valid class name.
  5. A new window will open.
  6. Delete everything that is written in it.
  7. Type your program and click on compile.
  8. If no error is found then click on close.
  9. You will find that in the previous window a file is created that has your class name.
  10. Right click on it and then click on void main().
  11. Click on OK.
  12. The output will be displayed.

HOW TO WRITE HELLO WORLD PROGRAM?

Use any of the above two ways to write it:

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



Save this program and run it.

LINE 1

class is a keyword to show that the class starts there.
Hello world is the class name. Here "H" is in capital letters. It is a convention (good habit for programmers ) to write class name in capitals. 

LINE 2 AND LINE 7

{ and } braces denote the block of the class. Note that you need to write everything in this block.

LINE 3

public is an access specifier. It specifies that this function can be used by an other class using the concept of inheritance.
static is a keyword which means that no object needs to be created for this function.
void is the return type of the function. It means that this function is returning nothing.
main is the name of the function. Every program execution starts from main function. You need to have at least one main function in your program.
String is a non primitive data type.
args is an array of type String. An array can store multiple variables in it.

LINE 4 AND LINE 6

{ and } denote the block of main function.

LINE 5

System is a predefined class in Java package.
out is a static variable of class system.
println is a function of class System which is used to print anything.
.(dot) is an operator for accessing a sub element of an element.

Comments

Popular Posts