Many Java entry like only one sentence "system.out.println (" Hello World! ");" To guide beginners to get started, I think this is a bit wrong. Java is an object-oriented language Take the object-oriented thinking to guide them, not to guide them in the process. The following is a Hello World, I hope to learn from the Java Friends.
============================================================================================================================================================================================================= ======================== First Java program "Hello World" (The First Java Program) Author: Foxmx
A simplest Java program. He has born someone Tom in the world, he said in a saying: Hello World!
//Human.java//written by foxmx
Class human {public void say () {system.out.println ("Hello World!");} public static void main (string [] args) {human tom (); tom.say ();}
Two functions (also calling methods) are included in this Human class: Say () and main (). A good consciousness is not to treat Main () as a method in a class. Because it does not have any actual significance in addition to the entire program from here. We can think that this Human class has a behavior: Say (). To call this method, you must create an instance of a Human or a subject. In OOP, the instances of the class and the object are the same. The modification of the word public means that this method is available everywhere, as long as it is introduced into the class. Let us now look at the static keyword. If you declare a data member or function as Static, it is a static variable or function. Static, means that this function or variable can be called even if an instance is not generated. In addition, you must remember: Never directly access the non-statist member or function outside the function in the static function! It must be accessed by accessing its corresponding object. As in the above example, to access SAY (), you must first establish an object Tom before you can call SAY (). Either we simply define: public static void say (). In this case, Main () can write this: public static void main (String [] args) {SAY ();} Maybe you think static does not comply with object-oriented ideas. Yes, don't put too much static in your program. But it still has the value of existing, at least in the stage we also use it.