In this tutorial today we will learn to create first program in java.Here we will display a text i.e print some text as an output.
- Follow the steps given below to learn to create first program in java :
- First of all download Eclipse in your machine in which you will be developing your java programs.
- Once you get the Eclipse file downloaded in zip format just extract it.
- Now open the eclipse application .
- You will have the following window :
- Now go to File -> New ->Maven Project as shown below :
- After clicking on the Maven Project you will get the following dialog box :
- Just make a TICK on Create a simple project and click on the next button as shown in the image below :
- After clicking on next button a new dialog box will appear as shown :
- Enter the Group Id , Artifact Id and your project Name for example as MyProject
- Also enter some description about your project ..it can be anything related to you project i.e it will be a clue for you to identify about what this project is ?
- Hence after adding all this information your dialog box will appear as shown in the image.
- Now click on the Finish button.
- After clicking on the finish button your project will be created as shown in the image :
- Now double click on the MyProject and you will have the following expansion :
- Now lets create a package for our program :
- Now right click on src/main/java ->New ->other->General->Folder and click on the next button:
- When you select Folder and click on the next button you will have the following dialog box :
- Enter a package name here for example org and click on finish button :
- After clicking on the finish button your package will be created under your src/main/java as shown in the image .
- Now lets create a new package inside the current package .
- So right click on the org package org->New->Package as shown below :
- Thus you will have the following dialog box where you have to enter the new package name as shown :
- After clicking on the finish button your package will be created under your org package .
- Now lets create a new class , so right click on the package i.e org.intro->New->class
- After you click on the class you will get the following dialog box , enter the class name as shown :
- Click on the Finish button .
- Thus you will have your class generated :
- Now you can modify your code :
- Write the following code to display the entered text as an output :
- Here is the screen shot for it :
- Now select your class and run it you will have the following output:
- To run you java program from command prompt follow the steps given below :
- First of all save your program with java extension .
- For example lets save the same program in D drive .
- Now open your command prompt window
- Now navigate to your D drive because we have saved our program in D drive .
- Now enter the following command as :
- Now we are ready to compile our program , the command is :
- Now run it simply by entering the command as :
- Thus you will have the following output :
- Thus we have successfully learnt to create first program in java.
public class Lesson1 { //creating the main method public static void main(String[] args) { //syntax for printing System.out.println(" WELCOME TO JAVA PROGRAMMING "); } }
set path= “ copy the path upto bin folder of java and paste it here ”
javac Lesson.java
Java Lesson