Page 70 - Viva ICSE Computer Studies 8 : E-book
P. 70

Structure of Java Program

                    The Java program is made up of the following parts.

                    Comments: The text which is written between slash asterisk (/*....*/) or after double slash (//...)
                    is considered as a comment. A comment is ignored by the computer. A single line comment

                    begins with ‘//’ whereas multiline comment begins with ‘/*’ and ends with ‘*/’.
                    Class Declaration: A ‘class’ keyword indicates that you are about to create a new class and
                    declares the program’s name. The name of Java program must always match with the class
                    name. For example, ‘Presentation’ is the name of the class in the above program.

                    Main: It is the place from where the program execution begins when a class is executed.
                    The main() is defi  ned as ‘public static’ with a ‘void ‘ return type. In the program shown in the
                    screenshots the main method contains one statement that is system.out.println.

                    Public: The keyword public defi nes who can access the method. Public means that this method
                    can be accessible by anywhere inside or outside the class. Static is the keyword which identifi es
                    the class related things. This means the given method or variable is not instance related but class
                    related. Since main() method of Java executes only once throughout the program execution,
                    so its nature must be static. Keyword static indicates that a method remains the same for all
                    the instances of a class.

                    Void: The void is a keyword which means that the function will not return any value except the
                    text that we enter in the Print statements.

                    String [] args:  It is called command line argument, where args is a set of string objects
                    representing arguments or parameters passed on to the class at the time of execution.

                    System.out.println(): It is a statement that prints the argument passed. This statement prints
                    any message or result on the terminal screen. Any text written in double quotes is printed
                    as it is. Anything written without quotes is treated as
                    a program component and its value will be printed.                  Think and Discuss
                    To combine two or more values ‘+’ symbol is used.
                    System is the name of Java utility class. Out is an           After successful compilation of a
                    object which belongs to System class. println is a            program, which option should be
                                                                                  selected to run a program?
                    utility method name which is used to send any String
                    to the console.

                    Fundamentals of Java Language


                    Tokens

                    A token is the smallest element of a program that is meaningful to the compiler. Tokens are the
                    various Java elements. Tokens supported in Java include keywords like Int, For variables like
                    sum, diff , constants like 12,–22.6, special characters like ;,’ and operators like (+,-, etc.).






                     58
   65   66   67   68   69   70   71   72   73   74   75