Total Pageviews

Monday, January 17, 2011

First Program

Ok now its time to write the fisrt program in the language. I will be using plain text editor (notepad in windows) to write my very first program.

public Class HelloWorld{
public static void main(String args[]){
System.out.println("Hello World");
}
}
We all know that the output of the program is Hello World. But have you ever tried to play with this basic program. Consider some of the few cases:
1.Make class HelloWorld as private/ protected and compile the program. Error occurs as "modifier private/protected" not allowed here".
2. Try removing public (default access specifier) and run the program. It turned out to be a surprise for me program compiled and ran successfully.
3. Try changing access type of main method to private/protected/default. Error message "Main method not public".
4. Change return type of main to int. Now here comes a surprise. The following method is compatible with java 1.3 and earlier versions. From version 1.4 onwards it gives error "java.lang.NoSuchMethodError".

Thats all for my first post.Do write reviews/comments. Further discussion will be highly appreciated.

PS: It is assumed in this blog that you are already aware of fundamentals of java.

No comments:

Post a Comment