Java Program

Java Program

  • Submitted By: mazeez32
  • Date Submitted: 03/08/2011 7:18 PM
  • Category: Technology
  • Words: 1046
  • Page: 5
  • Views: 471

MUHAMMAD AMMAR BIN JAAFAR
3091000901
DAKDP

The main method

The name main is distinguished in the name of the method which the Java interpreter will execute first,regardless of where it occurs in the program. The main ( ) method must be declared as a public and static. The public means the method is accessible from any other class. The static means the method associated with the class rather than any object of the class.
The main ( ) method accepts an array of strings of characters which are the command
line arguments to the program when it is interpreted. The result of executing the
main ( ) method is declared to be void because it doesn’t return a result such as an
integer or a boolean or a string.

1 public class One {
2 public static void main (String [] args ) {
3 int one;
4 one = 1;
5 System.out.println(“Java program” + one);
6 }
7 }

Line 3 declares an integer variable one which is assigned the value 1 on line 4.
Line 5 prints the string Java program 1 on the screen. The operator + is used to mean
several different things in Java. The plus symbol means denotes concatenation (joining together) of strings. Value 1 is retrieved from the variable one and then coerced into the
string "1" before the concatenation is performed.
Because the class One is declared public, Java requires that is is stored in a file
named One.java (this convention is good practice anyway). It is compiled with
the command javac One.java (the .java file name extension must be included). This
compilation produces a file called One.class which is executed with the command
java One (the .class file name extension must not be included).

Structuring in the large: packages

Java’s primary structuring construct is the notion of class, all programs are organised
as a number of classes. Several classes will be used together with some of them
defining classes of objects which are built upon by others. If these...

Similar Essays