If you are the new for java then you must learn the concept given below. First go through the following example and than you will be able to understand the basic logic the JAVA program .
First program in java..
Class A
{
public static void main(String arg[])
{
System.out.println("java is a very interesting language");
}
}
Logic behind the public method in JAVA
The public keyword is an access specifier, which allows the programmer to control
the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared. (The opposite
of public is private, which prevents a member from being used by code defined outside of its class.) In this case, main( ) must be declared as public, since it must be called by code outside of its class when the program is started.
Logic behind the static keyword in the above code.
The keyword static allows main( ) to be called without having to instantiate a particular instance of the class. This is necessary since main( ) is called by the Java interpreter before any objects are made.
Logic behind the void keyword in the above code.
The keyword void simply tells the compiler that main( ) does not return a value.
Logic behind the void keyword in the above code.
In JAVA , main( ) is the method called when a Java application begins. Be careful that Java is case-sensitive. Thus, Main is different from main. It is important to understand that the Java compiler will compile classes that do not contain a main( ) method. But the Java interpreter has no way to run these classes. So, if you had typed Main instead of main, the compiler would still compile your program. However, the Java interpreter would report an error because it would be unable to find the main( ) method.
Logic behind the String arg[] in the above code.
In main( ), there is only one parameter. String args[ ] declares a parameter named args, which is an array of instances of the class String. (Arrays are collections of similar objects.) Objects of type String store character strings. In this case, args receives any command-line arguments present when the program is executed.
Logic behind the System.out in the above code.
System is a class.
Out is a static object.
Println() is the method of PrintStream class.
System.out refers to the standard output stream.
Wednesday, March 25, 2009
Subscribe to:
Post Comments (Atom)
thanks a lot for your effort . i am waiting for your further posts, i am a starter in this field of java.
ReplyDeletenais
ReplyDeletethanks a lot for posting this article
ReplyDeleteReally great explanation... Nice one. Thanks, as i was learning Java by self study and having no previous programming experience, I had great difficulties in understanding OOPs concept. This expalined a lot about Why the main() method is necesary and how it was used? and the explanation of system.out.println() method also very nice. I was using it without complete understanding of it.
ReplyDeleteThanks again and keep it up such nice work.
Regards,
SM Raj
its very nice...keep it up in helpin the ppl...awesome explanation...
ReplyDeletesrinivasaraju
how can i run in cmd
ReplyDeletewoww....u explained really well....thnks for sharing vth us....hope u cm up vth such nice work....do u have any id aaa
ReplyDeletethank you so much for nice explanation
ReplyDeleteHey thanks, thats nice explaination. Am waiting for ur next post since am a beginner in java to start my career with it. So it will be very usefull for me and guys like me.
ReplyDeletereally fantastic..........
ReplyDeletegood post man :-)
ReplyDeleteGood so clear. Thank you
ReplyDelete-kris meesala
i need help.. mujhe java nhe aata hai.. aur in my company jither mein training kar rha hoon.. vo bool rhe hai JAVA sekhu... ab mujhe aate nhe hai.. toh main kya karu.. aaap bta sakte hoo..??
ReplyDeleteThis comment has been removed by the author.
ReplyDelete