Code hosting Address: http://git.oschina.net/null_289/Java2016 Textbook Learning content Summary exception handling
• All errors in the try, Catch:java are wrapped into objects, you can try to execute the program and catch (catch) to represent the wrong object and do some processing. Using the try, catch syntax, the JVM tries to execute the program code in the try block, and if an error occurs, the executor jumps off the point of the error, and then executes the program code in the catch if it matches the type declared in the catch bracket, whether it conforms to the type of the wrong object being thrown.
• Exception inheritance Schema: Errors are wrapped as objects that can be thrown, so the design Error object inherits from the Java.lang.Throwable class, and Throwable defines the method of getting the error message, stack trace, and so on, which has two subclasses: Java.lang.Error and Java.lang.Exception. This paper briefly describes the difference between the error class and the exception class, and in Java for the more serious problem, it is described by the error class, and for the non-serious problem, it is described by the exception class.
Error: Error, in general, do not write targeted code for processing, usually the JVM occurs, need to fix the program
Exception: Exceptions, can be targeted to deal with the way
throws: Cannot process itself, used in method declarations. Used to throw an exception class, followed by the exception class name, can be followed by multiple, separated by commas.
Throw: Checked Exception is thrown in the method, the method declaration must have throws. Used to throw an exception object followed by an exception object, and the throw is used within the function.
Finally block: The finally code block defines code that is bound to execute, which is typically used to close a resource. For the exception of the part, if not done finally, then the program is flawed, each call to the resources and then release the resources is necessary, otherwise the pressure on each other's operation will be particularly large, so you can see the importance of finally. Finally is often used with the try, catch syntax.
If the process of writing returns first, there are finally chunks, and finally chunks are executed before the values are returned.
Collection and map
• Recognize the collection architecture:
The common behavior of the collection object is defined in collection. Since the object can be collected, but also to be able to get the object, this is the java.lang.Iterable definition behavior, it defines the iterator () method to return java.util.Iterator operand, you can get the object one by one.
The common classes in the list interface are: ArrayList and linkedlist,arraylist are thread insecure, but queries are fast, and using ArrayList like sorting is a feature that leverages its speed. LinkedList in the operation of the list interface, the use of a link structure, will not be consumed in advance memory, it is faster to delete.
Scanner Scanner = new Scanner (system.in);
comparable is defined inside the person class:
public class Persion implements comparable {.... Compare the size of person:},
Because the comparator has been implemented, our person is now a comparable size object, and its comparison function is exactly the same as the string, can be taken anywhere
Compare size, because person is now the size of the point. Collections.sort (personlist) can get the correct results.
Comparator
Comparator is defined outside the person, at which point the structure of our person class does not need to change, as
public class person{String name, int age}
MAP:
• Use HashMap: After the key values are established in the HashMap, the keys are unordered.
• Use TreeMap: If you use TREEMAP to establish a key value corresponding, the part of the key will be sorted if the object that is the key must operate the comparable interface, or an object that specifies an operation comparator interface when the TreeMap is created.
• Using the Properties:properties class to inherit from the hashtable,hashtable operation map interface, properties naturally also have map behavior.
Problems in code debugging and the resolution process
public class Main{ public static void main (String [] args){ try { int number = Integer.parseInt(args[0]); System.out.println(number++); }catch(NumberFormatException ex){ System.out.println("必须输入数字"); } }}
The final result shows Exception in thread "main" java.lang.arrayindexoutofboundsexception:0
Show ArrayIndexOutOfBoundsException Stack Trace
Experience
It's been five weeks since I've been learning java. I have found some learning methods for the Java language, but still not very skilled. Hope that their study in the future pay attention to learning methods and diligent hands-on, find bugs.
Learning progress Bar
|
Number of lines of code |
Study time |
Number of Blogs |
Learning experience |
| First week |
100/100 |
5/5 |
2/2 |
|
| Second week |
130/230 |
15/20 |
1/3 |
|
| Third week |
240/470 |
12/32 |
1/4 |
|
| Week Four |
500/970 |
18/50 |
1/5 |
|
| Week Five |
500/1470 |
18/68 |
1/6 |
|
| Goal |
4000 |
300 |
30 |
|
20145123 Liu Senming Java programming Fifth week of study summary