Scanner class Methods in Java

Writing First Program In Java- Hello World!

Hello World In Java

In learning programming, it is a ritual to print Hello World! first😇. It is quite simple and interesting way to start learning a new language. In this section, we will write a simple java program,later on I'll give a detailed explanation of program.Lets start!

Notepad

Keeping it easy and simple. I want you to begin with notepad. As a beginner , you should know how to run java on your computer. So, we'll be creating first program in Notepad.

Steps: 

  1. Open Notepad in you computer.You can search Notepad on Start.
  2. Create new file , Click File > New.
  3. Write the following program, as shown below, class is a  keyword, it must be written in small letters. 
    Writing First Java program in Notepad
  4. In the above program, we created a class named MyFirstProgram , this class contains a main method,which further contains print statement of java. You can understand each code statement in this detailed program explanation section.
  5. Save the file, Click  File > Save/Save As OR Press CTRL +S >Type Name for file > Add .java Extension at the end of File name > Click Save. Your file name must be same as class name.Saving a java program
  6. Remember the location of the file where you have saved it. Now, Open Command Prompt,    Click Start > Write cmd >Click on Command Prompt icon. Command prompt will get open.

    Open Command prompt
  7. Now, to go to the Location using command in command prompt. cd..   command is used to go to previous folder or location, here cd is followed by two dots. It you want to go to next folders the use cd foldername .After writing each command press Enter, You can understand this having a look at following image.It shows the way to reach Desktop folder in computer.
    Opening a folder in command prompt using cd command
  8.  javac command is followed by your filename and .java extension. javac is java compiler. This command compiles the program.You must write the command correctly otherwise it will display errors.
    Opening a folder in command prompt using cd command
  9. To execute java program java command is used. It is followed by file name only.Again use command correctly. Press Enter.Output of the program will appear.
    compile and run java program using javac and java command in cmd


Congratulation! You have successfully printed Hello World in java. Practice printing other things like,your name, class and whatever you want to show on your screen .


Comments