Java Basics _ Bi Xiangdong _java Basic Video Tutorial notes (5-10)

Source: Internet
Author: User
Tags define exception modifiers throw exception throwable

06 Days-05-Object-oriented (help document making Javadoc):
Java Document generation commands:
javadoc-d Filepatn demo.java-author-version (optional)
In a class, there is a constructor for an empty argument by default, and this default constructor has the same permissions as the owning class
The permissions for the default constructor change as the class changes.

06 Days-06-Object-oriented (static code block):
Static code blocks feature: loaded as the class loads, executed only once, for initialization of the class.
Non-static code block features: Allocates memory space initialization as instances of the class are established.
The characteristic of building blocks of code is that, as an instance of a class initializes, after a non-static block of code is initialized.
New Object procedure:
1. Load class files into memory; 2. Initialize static variables and functions of class; 3. Allocate heap memory address;
4. Create a unique property of the object in heap memory and initialize it by default; 5. Initialize the property display
6. Object Construction code block initialization; 7. Initializes the constructor corresponding to the object;
8. Assign the heap memory address to the instance variable of the stack memory object.

06 Days-09-Object oriented (singleton design mode):
Design Patterns: The most effective way to solve a class of problems

07 Days-01-Object-oriented (inheritance-Overview):
Inheritance extends: 1. Improved code reuse
2. There is a relationship between classes and classes, and with this relationship there is a polymorphic nature
Overloading: See only the parameter list of functions with the same name
overriding: The child Parent class method is identical
Inheritance: All constructors for subclasses that access the null parameter constructors in the parent class by default
Subclass Instantiation Process:
Subclass the first row of each constructor has an implicit super ();
When the parent class does not have an empty argument constructor, the subclass must manually specify access to the parent class constructor through the super statement
When the constructor of a subclass is the first row, you can also specify the this statement to access this class constructor indirectly access the parent class constructor

07 Days-07-Object-oriented (final keyword):
Final: Finally, as a modifier
1. You can modify classes, functions, variables
2. The final modified class can not be inherited, in order to avoid being inherited, quilt class overwrite function
3. The final modified method cannot be overwritten
4. The final modified variable is a constant can only be assigned once, can be a member variable or a local variable
5. When the inner class is defined at a local location in the class, only the local, final decorated local variables can be accessed

Features of abstract classes:
1. Abstract methods must be in the abstract class
2. Abstract methods and abstract classes must be decorated with the abstract keyword
3. Abstract classes cannot create objects with new because it makes no sense to invoke abstract methods
4. Methods in an abstract class are to be used, all abstract methods must be overridden by subclasses, and child class object calls are established
5. Abstract analogy the general class has more abstract functions, and can not be instantiated

Template Method Design Pattern:
When defining a feature, part of the feature is OK, but part of it is indeterminate, and the identified part
Using an indeterminate part, the indeterminate part is exposed and implemented by subclasses of that class

07 Days-12-object-oriented (interface):
Interface Definition Features:
1. Common definitions in interfaces: constants, abstract methods
2. Members in the interface have fixed modifiers, which can be omitted
Constants: public static Final method: Public abstract

Interface: is not to create objects, because there are abstract methods, need to implement the quilt class, sub-class docking port
After all the abstract methods are overwritten, the subclass can be instantiated, otherwise the subclass is an abstract class
Interfaces can be implemented in many classes and are not supported by multiple inheritance of classes
Classes and classes: Inheritance relationships, single inheritance
Interfaces and interfaces: Inheritance relationships, multiple inheritance
Classes and interfaces: Implementing relationships, multiple implementations

08 Days-01-Object-oriented (polymorphic-concept):
Polymorphism: A variety of forms that can be understood as the existence of things
Polymorphic representation: A reference to a parent class can point to an object of a subclass, and a reference to the parent class can receive its own subclass object
The premise of polymorphism: it must be a relationship between a class and a class, either inherited or implemented, and there is an overlay
The benefits of polymorphism: the appearance of polymorphism greatly improves the extensibility of the program
The disadvantage of polymorphism: increased extensibility, but only the members of the parent class can be accessed using a reference to the parent class

09 Days-01-Object-oriented (internal class access rule):
access rules for internal classes:
1. Inner classes can access members in external classes directly, including private. The
can access members of an external class directly because the inner class holds a reference to an external class:
Format features: external class name. This. Variable name
2. External class to access the inner class, you must establish an inner class object
3. When a static member is defined in an inner class, the inner class must be static class
When the inner class is in the member position:
The internal class access permission can be private, but the external class must be default or the public
intrinsic class access modifier can be static and has static properties
to access the inner class:
When the inner class is defined on the member location of the outer class, And not private, you can access the
when a static method in an external class accesses an inner class, the inner class must also be static
format: outer class name. Internal class Name Variable name = An external class object. Inner class object
In other external classes, direct access to static members of the static inner class
format: new the external class name. Inner Class (). Non-static members;
In other external classes, direct access to static members of the static inner class
format: outer class. Inner class. static member;
Inner class is defined at local time:
1. Cannot be decorated with member modifiers
2. You can access members in an external class directly, because you also hold a reference to an external class
but you cannot access the local variable it is in, and you can access only the final decorated local variables

09 Days-04-Object-oriented ( anonymous inner class ):
1. The anonymous inner class is actually the shorthand format for the inner class.
2. The premise of defining an anonymous inner class: An inner class must inherit a class or implement an interface
3. The format of the anonymous inner class: New parent class or interface () {Defines the contents of the subclass};
4. In fact, the anonymous inner class is an anonymous sub-class object
5. It is best not to have more than 3 methods defined in an anonymous inner class

09 Days-05-Object-oriented (exception)
Exception : The program is running in an unhealthy situation
The origin of the anomaly: The problem is also a specific thing in real life, can also be in the form of Java class
are described and encapsulated into objects. is actually the embodiment of the object after the description of the abnormal situation in Java
For the division of the problem: two kinds:
One is a serious problem, Java is described by the error class, generally do not write targeted code processing
A non-serious problem, Java is described by the exception class, using targeted code to handle
Custom exception: The custom class must be an inherited exception class
Inheritance exception Reason:
The exception system has a feature because both the exception class and the exception object are thrown, and they all have the ability to throw
This parabolic feature is unique to the throwable system. Only classes and objects in this system
Can be operated by throw and throws.

It is possible for an exception to be declared on the function by the throws keyword, where it is called
Try-catch deal with it or keep throwing it out.
Method Thorws Arithmeticexception,arrayindexoutofboundsexception

When a throw exception occurs inside a function, the corresponding processing action must be given
1. TRY-CATC processing within the function
2. It is either declared on the function to be thrown to the caller for processing

The difference between throw and throws:
Throw: Used inside a function, followed by an exception object
Throws: Use on functions, followed by the exception class, you can follow a number, separated by commas

There is a runtimeexception runtime exception in exception, and its subclasses have the following characteristics:
If the exception is thrown within a function, the function may not be declared, compiled by
If the exception is declared on a function, the caller can not process
Cause: The class exception is because it does not need to be handled by the caller. When an exception occurs, you want the program to stop,
Stop program from correcting code because there is no way to continue running
Custom exception: If the exception occurs, no further operations can be performed,
Let the custom exception inherit the RuntimeException class

There are two types of exceptions:
1. Exceptions detected at compile time
2. Exceptions that are not detected at compile time (runtime exception, RuntimeException, and its subclasses)

Finally, the statement is executed regardless of whether there are any exceptions, except System.exit (0) before return;

The exception is reflected in the child parent class overlay:
1. When the subclass overrides the parent class, if the method of the parent class throws an exception, then the child class overrides the method,
Only exceptions to the parent class or subclasses of the exception can be thrown
2. If the parent method throws more than one exception, the child class can only throw a subset of the parent exception when overriding the method
3. If no exception is thrown in the method of the parent class or interface, the subclass is not
can throw an exception. If the subclass method has an exception, it must be try-catch processed and cannot be thrown

Exception Summary: Exception is the description of the problem, the problem is encapsulated object.
Anomaly System: Throwable
--error
--exception--runtimeexception
Anomaly System features: All classes in the anomaly system and the objects being built have the ability to be parabolic,
That is to say can be thrown and throws keyword operation, and only the exception system has this feature.
The use of throw and throws:
A throw is defined within a function and is used to throw an exception object;
throws is defined on a function, used to throw an exception class, and can be thrown multiple separated by commas .
Note: When the function content has throw throws exception object, does not carry on the try processing, must be in the function
Otherwise, the compilation fails. Except for runtimeexception, it can be used without throws or try.
If the function declares an exception, the caller needs to process it, either throws or try
There are two types of exceptions:
the exception that was detected at compile time :
The exception is identified, which means that such exceptions can be handled.
At compile time, if there is no processing (no throw and no try), the compilation fails.
run-time exception (not detected at compile time):
This exception occurs, it is recommended not to process, let the program stop, need to modify the code
At compile time, no processing is required and the compiler does not check
Note: The most commonly defined in finally is a close resource , except for System.exit (0);

Custom Exceptions: Define exception class inheritance exception or RuntimeException
1. In order to allow the custom class to have the parabolic nature;
2. Let the class have a common method of manipulating exceptions, and encapsulate the exceptions in the program according to Java object-oriented thinking

Benefits of Exception: 1. Encapsulate the problem
2. Separate the normal process code from the problem-handling code for easy reading
Exception Handling principles:
1. There are two ways of handling:try or throws
2. When calling the function that throws the exception, throw a few on the handle.
3. multiple catch, the parent's catch is placed at the bottom
4.catch need to define the positive handling, do not simply output the Printstacktrace statement,
Also do not write, when the catch to the exception, this function can not be processed, you may continue to throw in the catch
Exception considerations: When subclasses override the parent class method, the
1. The exception thrown by the subclass must be a subclass or a subset of the exception of the parent class;
2. If the parent class or interface does not throw an exception, the subclass overrides the exception only try cannot throw out

This: represents this class of object, which object calls this function, this represents which object
final:1. Modifier classes, variables (member variables, static variables, local variables), functions
2. The modified class can not be inherited; 3. Modified functions cannot be overwritten
4. The modified variable is a constant and can only be assigned once

Polymorphic class Invocation: Member variable look to the left, function see which class is actually instantiated on the right

Note: When the throw is present alone, do not define the statement below because it cannot be executed.

Package Packages: Access between packages and packages, access to classes in packages, and members in classes require public retouching
Subclasses in different packages can also directly access members of the parent class that are decorated with protected permissions
There are only two types of permissions that can be used between packages and packages: public, protected
       Public protected Default Private
Yes Yes Yes in the same class
Yes Yes yes No in the same package
Subclass Yes Yes no no
In different packages Yes no no no

Java compilation:javac-d sourcefolder Classname.java. Or omit to indicate the current directory
Java Runtime:java package. ClassName

Java Packaging:jar-cfv packagefilepath.jar packa packb
View Package:JAR-TVF packagename >d:\jar.txt output details to Jar.txt

Java Basics _ Bi Xiangdong _java Basic Video Tutorial notes (5-10)

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.