Wednesday, February 29, 2012

First JAVA program

     Hi! Welcome to magjavatayo.
     Hope you can easily learned and understand JAVA.
First, for you to be able to run a JAVA program, you will need JAVA application of course:), If you don't have one yet. You can easily search for downloads in google . And commonly, notepad for your codes.
OK Let's start!

                              1        //Halimbawa.java
                              2        //This program will print a line of text:)
                              3
                              4           public class Halimbawa {
                              5                public static void main (String args[])
                              6                {
                              7                     System.out.println("my name is Real Myn");
                              8                }
                              9          }
Discussion: For better understanding, this program will be explained line by line.
                                           Line1         //Halimbawa.java
                                           Line2         //This program will print a line of text:)
   Lines 1 and 2 doesn't have an affect to the program, there are called "comments". And comments will not be read by the compiler (like other programming languages). Comments can be put anywhere in the program as long as they have "delimiters". 

*comments are used for better program readability,usually at the beginning for you to be able to know what is the program for.
Examples: delimiters used
//this is a single line comment 
/*this is called the
   multiple line comment 
   can be splitted in lines*/

        Line3, white-space characters. Use also for program readability.
                                            Line4           public class Halimbawa{
       "public class" is a class definition for Halimbawa. Every program in JAVA must have atleast one class definition that is defined by you- (programmer). These classes are also known as programmer-defined classes o user-deefined classes. The "class"  keyword in Line4 is class definition in JAVA and must be followed by the class name. (Halimbawa) and should always in lowercase letters.  And the class name "Halinbawa", always begin in uppercase letters and the name of the class is called indentifier.

Note: Your class name must be identical to the file name of the program you saved and must have .java file extension.
      Left brace, the body starts here and coresponding right brace in Line9.
                                   Line5            public static void main(String args[])
      Line5 to Line8 was indented, white spaces used for programming readability only.
     Line5, public static void main (String args[]) indicate that main is a program building block called a method. and Line6 left brace .
                                  Line7             System.out.println("my name is Real Myn");
      This line instructs the computer to perform an action."System.out.println" and it is called standard output statement.  This will print anything inside thte ( ) parenthesis and  double quotations(" ") including white- space characters within, and the string in quotations is called an argument. Use to print the string of characters only. If a character only, single qoutation(' ').
Note: Every end of the line must end in semicolon(;), called statement terminator
And close brace at Line 8.

it must be look like this,

                                               my name is Real Myn

SHARE and LEARN!

No comments:

Post a Comment