Friday, 1 December 2017

Java Progamming For Beginners Lesson 2: Write Your First Java Program

This is Lesson 2 of the Java Programming Tutorials for Beginners, and in this Lesson, you would write your first Java Program. This lesson follows from the Lesson 1 which is Introduction to Java and Installation of Netbeans. So If you have not taken Lesson 1, please take the lesson before you continue. You can find in the link:
Java Programming Tutorials for Beginners, Lesson 1: Introduction to Java

So lets get started!
Step 1: Open Netbeans (This is actually the last step of Lesson 1)
The Netbeans Window
Step 2: Click on File and Select "New Project". You would see the window below
Under Categories, make sure Java is selected and under Projects: make sure Java Application is selected exactly as is shown.


Step 3:  Click on Next. The window below appears


Step 4: In the Project Name box, delete what is there and write: MyFirstProgram (don't give spaces). Then you can click on Finish
If you have done everything correctly, the Java File opens where you can start writing programs. This is shown below.
Step 5: Take some time to observe the parts I labelled 1 - 6 as you can see in the screen below.


1. MyFirstProgram.java - This is the name of the file that you are currently looking at. Remember that Java file have the extension of .java.</div>

2. File Tab - Where you can see two folders. The Second folder is yours, Netbeans keeps all your file in this folder. Later, we would discuss the content.

3. Navigator Tab - Shows you the classes and functions in your program(don't worry about these, we would discuss them later)

4. This section is where you actually write your program. So we would start writting program under the text that begins with // TODO...

5. The name of the package. This is same name as the folder name in the Files tab. The package contains all your files.

6. The name of the Function. Every java program must have this Function called main.

Now on to Step 6.

Step 6: In Section 6 under the part that says //TODO....
Type the following line of code(don't copy and paste, type it)
        System.out.println("This is my First Program");
As you are typing, some pop-ups may appear, ignore them and just type exactly as you see here

Step 7: Run The Program by clicking on the Run button. The Run Button is highlighted in Red. It it a green play button.
Step 8: Wait for a few seconds and if you did everything correctly, the output of your program is shown as given below:

If you have come this far, you have successfully completed Lesson 2 of the Java Programming Tutorials for Beginners.
Congratulations!!If you have some issues, let me know in the comment box below, before I publish lesson 3.