Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 90 - 2617_JSSPS_C-7
P. 90

    The program code must be simple and object-oriented.
                      The program code should execute with high performance.

                  STRUCTURE OF A JAVA PROGRAM

                  The curly brackets ({ }) are used to start and end the body of the class. The HelloWorld class has one
                  method named main(). The main() method is declared by using three Java keywords, which are public,
                  static and void. The main() method must look like:

                                             public static void main(String args[])
                  In the main method:

                      public means the method is accessible from outside the class.
                      static means the method belongs to the class rather than to instances of the class.

                      void means the method does not return a value.
                  The only term that you can change in the syntax of the main() method is the name of the parameter args,
                  which can be any valid identifier name. The array of strings (String args[]) will contain the command-line
                  arguments, if any, when the program is executed from the command prompt. In BlueJ, we can also use
                  main() method without any argument. The main() contains a single statement:

                                           System.out.println("Hello from Touchpad");
                  This statement is used to display the message “Hello from Touchpad” on the output screen. System.
                  out represents the standard output of the device where the program is running and the println()
                  method displays the given string along with a line feed.
                  Notice the semicolon at the end of the System.out.println() statement terminates the line. It is also
                  known as the line terminator. The Java compiler ignores all whitespace and indenting, so it is necessary
                  to use a semicolon to denote the end of all statements in Java.

                  DATA TYPES

                  A data type is an attribute of data which tells the compiler or interpreter how the programmer intends
                  to use the data or value. It specifies the size and type of values that can be stored in an identifier.
                  Different data types allow you to select the type appropriate to the needs of the application. Data types
                  in Java are classified as shown below.

                                                                         DATA TYPE

                                                  Primitive Type                             Non-Primitive Type

                              Boolean      Character      Integer          Real/Decimal                  Arrays

                                             Char                byte                                     Class
                                                                          float   double
                                                                short                                   Interface

                                                                 int                                      String

                                                                 long

                            Premium Edition-VII
                     88

| 85 86 87 88 89 90 91 92 93 94 95 |