Java Learning Path (iv) method

Source: Internet
Author: User

Java Learning Path (iv) method

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, see what results, and then call a few more classes of methods, see the results of the operation, so very intuitive to the class to learn, and memory is very deep. Then you should not be satisfied to put the code to pass, you should think about if I do not write this, another way, try again trial not. Remember which tall man said that learning programming is a destructive process, the book examples, their own learning documentation written examples in the run through, and constantly try to use different methods to achieve, and constantly try to destroy the structure of the code, see what the results. 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 understand why the main method must define public static void main (string[] args), can not write this? Including when I was just studying Java, there was this kind of doubt. Do you want to know the answer? Very simple, you have to change the main name to run, to see what errors, and then based on the error message analysis, the main public to take off, in the try, report what error, static remove 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 also change the args to another name, see how the results of the operation.

I did this when I learned Java, the Hello World program repeatedly changed seven or eight times, constantly running, analysis of running results, finally thoroughly understand why the main method is so defined.

In addition, I do not understand the staic,public,private,exception,try{}catch {}finally{} and so on, and so on, all the examples of reference books run successfully, and then began to destroy it, Constantly according to their own heart of the question to rewrite the program, to see if it can run, run out what it looks like, whether you can get the expected results. This is a time-consuming process, but one example of this is repeated destruction several times. I have learned a thorough knowledge of the relevant information. Sometimes it is even intentional to write some wrong code to run and see if you can get the expected run error. So the mastery of programming is profound.

It is particularly noteworthy that the JDK has a very good debugging function,-verbose

Java–verbose

Javac–verbose and many other JDK tools have this option

-verbose can show how the JVM loads the class in sequence as the command executes, and with these valuable debugging information, it helps us to analyze what the JVM has done in the course of execution.

In addition, in the course of their own learning, write a lot of this destruction routine, should have the consciousness of the categories of preservation, in the work of the accumulation of typical routines should also be regularly collated, accumulate, and have a code base. In the case of similar problems, it is good to Copy & Paste, Search & Replace in the code base, greatly improving the development speed. Ideally, some of the general routines themselves can be abstracted to form a common class library, which is packaged well. Then reusability is even stronger.

so I think it is not particularly need routines, the destruction of their own routines is the best example, if you really do not worry about the code you write, I highly recommend you look at the JDK base Class library Java source code. Under the JDK installation directory there will be a src.zip, to be able to fully see the entire JDK base Class library, that is, Rt.jar Java source code, you can refer to how Sun wrote Java program, specification is what it looks like. When I am learning Java library, when some places do not understand very clearly, or want to understand the details of the operation more clearly, often open the source code of the corresponding class, by looking at the source code, all the problems will be swept away.


        Please respect others ' work success, reprint please indicate reprint place. Thank you!



Java Learning Path (iv) method

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.