Java Learning Path (iv) method chapter

Source: Internet
Author: User
Tags execution
Java as a programming language, the best way to learn is to write code. When you learn a class, you can write a simple example of the program to run it, see what the results, and then call several classes of methods to see the results of the operation, so very intuitive to learn the class, and memory is very profound. Then you should not be satisfied with the code, you should think about it if I do not write, another way, try again. Remember which high man said learning programming is a destructive process, the book example, their own learning documentation written examples in the running through, and constantly try to use different methods to achieve, and constantly try to destroy the structure of the code, to see what it will result. In this way, you will be thoroughly proficient in mastering Java.





, for example, we've all compiled Hello World
.




public class HelloWorld {


public static void Main (string[] args) {


System.out.println ("Hello World");


} }


Many beginners do not quite understand why the main method must define public static void main (string[] args), can you not write this? Even when I was learning Java, I had this kind of question. You want to know the answer? Very simply, you change the name of main to run, look at what the report error, and then based on the error information analysis; Take the main public off, in a try, report what error, static remove still can not run, do not know whether the main method must pass a string[] array, String[] Change to int[], or string to try, do not know whether to write the args parameter name, you can change the args to another name to see how the results of the operation.





I was doing this when I was learning Java, the Hello World program has been repeated seven or eight times, running, analyzing the results of the operation, and finally fully understand why the main method is defined.





In addition, I was not very understanding of staic,public,private,exception,try{}catch {}finally{}, and so on and so on, all of them are the example of the reference books to run successfully, and then began to destroy it, Constantly according to their own heart in the doubt to rewrite the program to see if it can run, run out what it looks like, whether can get the expected results. This may be time-consuming, but an example of a program that repeatedly destroys after several times. I have learned the relevant knowledge thoroughly. Sometimes even deliberately write some wrong code to run to see if you can get the expected run error. So the mastery of programming is profound.





It is particularly worth mentioning that the JDK has a very good debugging function,-verbose java–verbose javac–verbose and many other JDK tools have this option-verbose can be displayed in the process of command execution, Where the JVM loads classes in turn, this valuable debugging information helps us to analyze what the JVM has done in the process of execution. In addition, in the learning process, write a lot of this destruction routines, should be aware of the categorization of the preservation, in the work of the accumulation of typical routines should also be regularly sorted, accumulated over time, they have a code base. Encounter similar problems, to the code library inside Copy & Paste, Search & Replace, just fine, greatly improve the development speed. The ideal scenario is to abstract some common routines into one layer, forming a common class library, packaged. Then the reusability is even stronger.





so I think it is not particularly necessary routines, your own written destruction routines is the best example, if you are really not comfortable with the code you write, I strongly recommend that you look at the JDK base Class library Java source code. Under the JDK installation directory there will be a src.zip, you can unlock the entire JDK base Class library, that is, Rt.jar Java source code, you can refer to sun is how to write Java program, what the specification is like. I am learning Java class Library, when some places do not understand very clearly, or want to more clearly understand the operation of the details of the time, often open the corresponding class source code, by looking at the source code, all the problems will dispelled.








Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.