Wednesday, January 18, 2017

Learn Java for Beginner easily ! part 2 : Let's make your first program with notepad !

First, I'm gonna need you to open your notepad.If you're using windows then you can easily press Win+R then type "notepad", after that we are ready to make the source code.
Next, I want you to type this source code in your notepad :



The first thing you will always need in java programming is a class.You can't do anything in java without any class because in java everything begin with a class.
The word "prog" after class is the name of the class, you can name it as how you want it but it can't be started with number. Examples, naming your class 69lover won't be allowed by java.

How about public ? Hmm actually it is okay if you don't type it, because it is just a simple program.
It means that this class can be used by another class, you guys will learn about it in the next tutorial.
The curly brackets shows the limit range of this class.This brackets also contains methods which is the lists of things to do.
 "public static void main" is a method and the brackets shows the parameters which is "string".
You know what ? Just type the program above and continue to the next step.I'm really sure that you will understand by doing it than reading it.
"System.out.println("Input text here");" is a keywords in java to print out text.
So you can put any characters and numbers in the quotation mark.


After that,save the source code to somewhere up to you as long as it is still on your computer but don't forget to save it into .java format. For example if you name your files "firstprogram" then save it as "firstprogram.java" just like the picture below.






In this example, I saved it in the drive (F:).

Like I said in Part 1, text files in java format can't be excecuted by your computer.So you need to compile it.This is how to compile it :



Go to the path where you saved your source code, because I saved it in (F:) so i move my cmd's path from (C:) to (F:) by typing "F:" without quotation mark.Then type "dir" to make sure that your source code is detected by the cmd.In the picture above my source code is detected, so let's go to the next step.


Next, i want you to type "javac firstprogram.java". javac means java compiler which is a keyword to compile your source code into class format which is executable for your computer just like the white arrow shows on the picture above. If your source code turns into class format and the name changes into its class name, then the compiling process is succesful.

You can simply run your first program by typing "java prog" on your cmd.Press Enter and it should be like the picture below.


So how is it ? is it that hard ? Of course no ! You already did it.
Congratulations on running your first program !




No comments:

Post a Comment