Static
Static variables belong to the class
Common variables and methods belong to the object
Static methods are not allowed to use non-static methods
Normal variables can use static methods
Executes the static initialization block of the parent class first
Static initialization blocks are initialization classes
Package
Must be put in the first sentence
Java.lang is a core package
import--Import----The shortcut keys for auto-guided packages in Java are Ctrl+shift+o
The three main characteristics of object-oriented: inheritance; encapsulation; polymorphism
Inherited
Java interfaces can inherit multiple, Java classes are only single-inheritance
The subclass inherits the parent class and can get all the properties and methods of the parent class in addition to the parent class's constructor method
Java.lang.object is the ancestor class of all classes
Select Class Press Ctrl+t to open the inheritance tree directly to view the inheritance relationship
Instenceof operator
(Object instenceof Class)
Override (override) of the method (and overwrite)
Methods of the subclass that replace the parent class
To maintain the same method name and parameter list when overriding
Return value type subclass to less than parent class
Subclass has greater access than the parent class
Methods in the class of object
1.to String
2.equals method (right-click on the screen after clicking on source directly constructs the method)
Super is at the top of the construction method, and the super and parent methods are executed first when the constructor method is executed.
Null if the parent class is Object
High cohesion and low coupling are pursued during programming
Packaging
Access control characters
A total of four:
1.private: Only You can use it, it means private only can access
2.default: Indicates no modifier adornments, only classes of the same package can access
3.protected: Indicates that it can be accessed by a subclass of the same package and other packages
4.public: Indicates that it can be accessed by all classes in the project
Polymorphic (polymorphism)
Refers to a call to the same method may behave differently due to different objects
Three prerequisites for polymorphism
1. Inheritance
2. Method overrides
3. Parent class reference to child class object (* * * * *)
Final modifier constants, variables, methods, classes.
Modifier variable: Once the final modified variable is immutable, it cannot be re-assigned once the initial value is assigned
Modification method: The method cannot be overridden by a quilt, but can be overloaded
Decorated class: A decorated class cannot be inherited
Abstract classes: Keywords (abstract)
Method: Declaration Plus implementation
Abstract methods must be defined in an abstract class.
You can define common methods and common properties in abstract classes.
Classes with abstract methods must be abstract classes
Abstract classes cannot be instantiated, and abstract classes cannot be instantiated with new
An abstract class can contain property/method/constructor methods, but the constructor method cannot be used to use the new instance only for the quilt class invocation
Abstract classes can only be used for inheritance.
Abstract methods must be implemented by the quilt class.
Interface (interface)
For example: The interface can be seen as the company's rules, and the class is the company's employees, to accept a variety of
The constraints of the specification, and the class can implement the functions of multiple interfaces.
You can build a interface directly inside the package.
Only constants and abstract methods in the interface
Separation of design and implementation facilitates division of labor
Use when collaborating with multiple people
Interfaces can describe things that are more abstract
Make a more abstract definition
A class can implement multiple interfaces
Through implements to achieve
Interface supports multiple inheritance
Callback (CallBack)
Application of polymorphism
superinterface
(1. Hyper-Interface
l a member inherited from a direct hyper-interface (superinterface).
blog.csdn.net| based on 18 pages
2.
Super interface
3.
Super interface
All messages must conform to this interface, corresponding to serializable. )
Inner class
Role:
1. The inner class provides a better package. You can only have the external class "direct access." Do not allow the same
The other classes in the package are accessed directly.
2. The inner class can access the private properties of the outer class directly, and the inner class is treated as a member of its outer class.
External classes, however, cannot access internal properties of the inner class.
Object-oriented and process-oriented
Object-oriented is to look at the problem with a design vision (object)
Object is a block of memory in memory
Some variables and methods are put in the object
Class can be thought of as an abstraction of an object's template called an object
Pull out a similar section to define a class
Create a class from an abstraction, and the program will then produce the object through the class
Objects (object) (instance)
Properties and methods in a class
Properties represent static characteristics, and member variables
Method defines how the "modifier" method returns a value method name () {}
There are also constructor methods in the class that act as initialization objects.
Create object: Class Name Object name =new class name ();
Class name Object name;//Create a tired object
Scanner
Get the data you entered, use the import Java.util.Scanner before you need it;
The wrapper class corresponds to the basic data type in a total of eight
Packaging class is located in the Java.lang package
Example: Integer object =new Integer (1000);
Wraps 1000 as an object.
Integer extends number class
Integer.tohexstring (): Change I to 16 binary
Integer.parsein (): Convert a string to a number
Automatic unboxing is done by the compiler
Array:
File class
Separator: Delimiter
An exception mechanism that, when encountering a null pointer's exception mechanism, adds an IF condition statement to let the exception disappear.
One of the methods of handling exceptions
Catch Exception (tyr,catch,finally)
Try: Format: try{
Statement one;
Statement two;
Statement three;
}catch (Exceptione e) {
Statement four;
}finally{
Statement five;
}
The exception handling mechanism typically puts subclasses in front of them, with the parent class behind.
Shortcut keys when writing Try-catch statements right-click the selected surround with and select Try/catch Block
Exception handling mechanism is added automatically
Supplemental content: Try/catch/finally/return Order of execution:
1. Execute Try/catch, give return value
2. Execute finally
3.return
The second method of declaring an exception throw handling exception
Add a thrown declaration
It's read.close to turn off Try/catch.
How to view hierarchies--right-click to find the Open call Hierarchy
Shortcut keys are--ctrl+alt+h to view hierarchies
Collection (container) (also called set frame)
Examples are as follows: Package cn.wk.collection;
Import java.awt.List;
Import java.util.ArrayList;
Import java.util.Collection;
Import Java.util.Iterator;
public class Collection_demo {
public static void Main (string[] args) {
collection<string> coll01 = new arraylist<string> ();
Coll01.add ("BBBBBB1");
Coll01.add ("Bbbbbb2");
Coll01.add ("Bbbbbb3");
Coll01.add ("Bbbbbb4");
Coll01.size ();
System.out.println (COLL01);
//Use of iterators 1
Iterator it=coll01.iterator ();
For (Iterator it1=coll01.iterator (); It1.hasnext ();) {
string str= (String) it1.next ();
System.out.println (str+ "");
}
System.out.println (Coll01.size ());
boolean b1=coll01.remove ("Bbbbbb2");
System.out.println (B1);
System.out.println (COLL01);
//Add a collection
Collection coll02=new ArrayList ();
Coll02.addall (COLL01);
System.out.println (coll02);
}
}
Enhanced for Loop
The code is as follows:
for (int m:a) {
System.out.println (m);
}
The element used to iterate through the array.
IO stream
Concept: A stream is a set of bytes that have a sequence of starting and ending points,
is the generic or abstract of the data transfer. That is, the transmission of data between two devices is called a stream.
The essence of a stream is data transfer, which abstracts the stream into classes based on data transmission characteristics.
Convenient and more intuitive data manipulation.
IO Stream Classification: Based on the processing data types are divided into: character stream and Byte stream;
It is divided into: input stream and output stream according to the data flow.
Use process
One
Establish contact
File object, source
Two
Select a stream
File input stream InputStream Fileoutstream
Three
Action Write () +flash
Four
Release Resources off
Please see the website in detail: http://www.cnblogs.com/oubo/archive/2012/01/06/2394638.html,
Two top-level parent class for character streams
1.Reader, Writer
Subclasses of these systems are suffixed with the parent class
And the prefix of the subclass name is the function of the object.
Text is a string using the character stream closest to his relationship
Cases:
Requirements: Store some files in a file on your hard disk
Remember: If you want to manipulate text data, it is recommended that you prioritize character streams.
and to write data from memory to the hard disk, use the output stream in the character stream. Writer
The law of the flow
Conversion Flow:
InputStream: A byte-to-character bridge. Decoding
OutputStream: The character-to-byte bridge. Coding
Flow Operation Law:
The reason to understand this rule, because the flow too much, do not know which
Four clear
1. Clear source and purpose (sinks)
Source: Input Stream Reader
Purpose: Output stream writer
2. Clear whether the data is plain text.
Source: is plain text data: Reader
No: Input stream
The purpose is: writer
No: Output stream
Here you can clearly specify which system to use.
3. Clear the specific equipment.
SOURCE Device: Hard disk: File
Keyboard: System. Inch
Memory: Array
Network: Socket stream
Purpose Equipment:
Hard disk: File
Console: System. Out
Memory: Array
Network: Socket stream.
4. Whether additional feature stream objects are required.
1. Whether you need to be efficient (buffer)
Yes, just add buffer.
Java Basics at a glance (will continue to add)