google Ads

Sunday, July 19, 2009

Structure of a Java program

Structure of a Java program


The structure of a java program is very different from traditional programming languages like C or C++. In java we have to declare a class however simple the objective of our program be. This is because java is pure object oriented language. Through difficult to start with, it is clearly one of the best programming paradigms.


Syntax of Java program

public class

{

public static void main (String [] arguments)

{


statemenst;


}

}





Example


Public class myprogClass ------------- Step1

{

Public static void main (String[] arguments) ------------- Step2

{

System.out.println(“Good Morning”); ------------- Step 3

}

}


The above program is inside a file called myprogClass.java

The above program prints Good Morning in the standard output screen

The above code has to be stored in a file, which has same name as the public class. So the source file should have a name myprogClass.java

Let us analyze this code step by step

In Step1 we declare a class called myprogClass (We have to declare this)

In Step 2 we make declare a method called main, which takes in an array of String objects. This is starting point of any program. We are not allowed to change the signature of this method.

In Step 3 we call System.out.println() method which is inside an object called out, which is in turn inside an object called System. We will learn more about these Objects and classes later, as of now remember this statement, as we will be using this quite often.

No comments:

Post a Comment