Before I begin explaining and demonstrating the first program I learned to code, I would like to say that by no means am I the best coder or even a good coder. I am still learning some of the basics of coding; however, I feel that it would be fun to show the first program I and a lot of other people coded. So, without further ado, this is the simple program known as Hello World. The language we will be using to write this program in is Java. Java is a language that is considered verbose, yet popular. The first step I was taught when learning this program was to title the entire project. To do this, the first line in the code will be "public class HelloWorld." This sets the title, "HelloWorld," to the class or project being created. The word "public" is used instead of "private" or "protected" because we are making the code open to other classes. Overall, for the first line of code, the program should look as the picture below looks. Next, I learned that when making a program in Java, open and close curly braces are needed in between each "block of text." Since we have just established the class or project, an open brace is needed. The companion close brace to the open brace inserted in the next line will be at the end of the entire program to enclose the entire code in the class. After that, the main method must be made where the actual printing of "Hello World" will take place. We call this, "public static void main (String [] args)." There are many words here that I did not know the meaning of when I first learned this, but essentially it is the main method of the class we called HelloWorld. So, after typing that out on the third line, the program looks as it does in the picture below. When learning this program, I realized that another open brace was necessary because the command to print, "Hello World," was going to be enclosed inside the method created above. Then, the actual command to print is written inside the method just created above. In order to print something, I was taught to start with, "System.out.print" and include open and close parenthesis right after. Inside the parenthesis, two quotation marks are needed inside the parenthesis. Finally, inside the quotation marks, the words, "Hello World" are typed. The product now is: To end the program, a final closed brace is needed to match with the first brace typed, enclosing the entire code in the public class HelloWorld. When the program is run, "Hello World' is output in green to the screen.
Although this program is considered simple, it is the basis for all other programming. Programmers that work on big games started with simple programs such as Hello World. Overall, this is how I learned to code my first program.
1 Comment
|
AuthorHi, my name is Daniel and I am a Junior in high school. This is my blog that I intend to use for my American Literature Class. Archives
May 2016
Categories |