To compile and run java program you need JDK that is java development kit installed in your computer. You can download JDK from oracle website or from here by clicking the following link
After installing jdk you need to set variable path. In order to do that please follow the following steps:
- Goto C:\ drive and open program files and in that open java folder. In that you will see jdk1.8.0_20 folder. Open it. In this you will see bin folder open it up and copy its path.
- Now right click on my computer folder on desktop and go to properties. In that in the left hand side you will see Advanced System Settings. open it and a pop up will come. On advance tab click on environment variables. Click on new. On variable name you have to write "path" and in path copy that address of bin folder which we had copied in step one.
- Now select that new variable and click OK. Now the environment variable is set.
The following are the steps to write and run our first java program using notepad and cmd:-
- Open notepad and write the same code snippet and save it with name First.java
- Open command prompt(cmd) and write cd.. This command is used to change directory. Change it till you get it into that folder in which your First.java resides.
- Now write javac First.java. This will compile our program. Javac is for java compiler.
- Now write java First. It will run our program and you will see the output which is Hello World! in our case.
The following are the steps to run program in eclipse software:First you need eclipse software. You can download it by clicking on the link below:
- Open up this file and eclipse will be launched but if you are getting trouble then you have to download it from internet.
- Go to the file menu and point to new and then click on other . A pop up will appear. Write dynamic web project there and then specify the name of the project then click next and simply your project will be created.
- If it is asking for Java EE then click no.
- Now click on the project that you just created and on src folder right click and then point to new and then click on package.
- Then write package name generally we write like this package name:"com.company_name.project_name".
- Click on finish.
- Now a package is created in your src folder of project.
- Now right click on package and point to new then click on class.
- Now write class name of your wish which is First in our case and then click OK.
- Now write the whole code in this class and run it from top and you will get output below the program in console.
From now onwards we will be writing our programs mostly in eclipse.