Let's try to get the output as "Hello World" from Java and run on CMD




What do we need to do? well, you will need bellow list.

  1. should be installed JDK and should be made the path on your computer

  2. clear folder

  3. notepad


First of all, We have to create a new folder in Desktop. So, I created a new folder and rename it "java". You can give any name that you need. But it is better to give a simple and short name for the folder because we are going to run the java program in CMD. 


This is my folder

Then after that, you need to go inside your newly created folder. In my case, I will go to the java folder. Then in the white space, press the right-click button on your mouse. Go to "New" and choose "Text Document". This process will create a text file and it will be opened with the notepad app.



Once you have done like above, you will be having text file like below. 


Now, we can write java codes by opening the text file. I have given the code below. So you can type inside your text file. There are a few things that you should have remembered when you are writing some code.

  • It should be clean (doing this, will help you to understand clearly of java programming).
  • Be careful with lowercase and uppercase (Otherwise, you will be having some errors). 
  • Do not miss any symbols like below.

Keep this in mind  and Let's move to java code 


Step 1:

Open the text file using the Notepad app and type this in your text file also you can find this code on my GitHub link.






Once you are done typing, you need to save it in some special way. The steps are shown below. 



1. Click on the "File" tab
2. Click on "Save As"


Step 2:




3. In the "File name" field, you have to type any name that you want, but better to give a simple name          like "project1" or "test" or whatever you need. The extension should be given as "java".

4. In the "Save as type" field, click on the little down arrow to get the drop-down list

5. Then click on "All Files"


Step 3:




6. Then click on "Save"

After coming step 3, You will see there is a new file created in the folder. That file will contain java extension like below.




Step 4:


7. Go to the address bar and select all and do the next thing that I have mentioned below.


8. Then type "cmd" inside of the address bar and press the "Enter" key on your keyboard. This tip will         help you to open the command prompt (CMD) and It will open the location of the respective folder         by going inside of it.



Step 5:




9. After opening CMD, you have to type "javac" command. Then after that, press space key one time and type your newly created file name with extension. Then press the "Enter" key in your keyboard. If there are not any error, you will see the cmd window like this below. If you came to next command line without getting any error, it means you have written correctly your java codes in text file.

In my case, this will go like this, "javac project1.java" and press the "Enter" key. 

Little explanation of the process according to my activity

This "javac" command will compile your newly created file (project1.java) which is having the "java" extention. We call it as source code

However after pressing the "Enter" key, you will be having another new file with the "class" extension. We call it as Byte code. In my case, I got file which name is "MyFirst.class" as below.


Did you know that byte code came from?
Actually it came from with our class name. So, You might understand a basic concepts of java. 


Step 6:

10. Let's run our little java program. To do that, you have to type the "java" command and press the                 space key and type only name of the byte code. In my case, I type "java MyFirst" as below.



Finally, you will see on your cmd window that you expected result which is "Hello World" according to your java project.

The Output will be like this below



These simple 6 steps will guide you in a very easy mode with evidence of the process. So, you could simply understand from start to end by studying this post. This is a very simple project that we have shared with you. 


You can leave any feedback in the comment  

if you got any problem let us know in the comments or by email and we will help you as soon as possible.

Thanks for staying with us!