Simple Java object-oriented knowledge summary

Class, object constructors

Class defines the properties, methods, abstract, written in the java file extension of.

Object is a class entity, is specific.

Constructor: the class name and method name consistent, no return type, can override can not be rewritten. Called when the object is created. Use new call to achieve the purpose of allocating memory space.

Access specifier

Access control

This class

The same packaging

The classes

Other packages

Neutron class

Other packages

The classes

public

Ö

Ö

Ö

Ö

private

Ö

×

×

×

protected

Ö

Ö

Ö

×

default

Ö

Ö

×

×

Object-oriented features:

  Package

Packaging class: speaking properties and methods together into a class.

Package properties: get, set method with private property privatization, and then provide access to the public.

 

  inherit

Class inheritance is single inheritance, extends keyword, followed by subclasses can use the properties and methods of the parent class inherit directly.

Inheritance rules:

  Category and class is single inheritance

         All classes inherit directly or Introduction to object

         Subclasses can override method (coverage) of the parent

         private modification can not be overridden

         Constructor can not override

         The final modification can not be overridden

 

  Polymorphism

Implement polymorphism in Java by overloading and rewritten.

Overloaded: a class, the same method name, a list of the different parameters of the method called overloading method is essentially completely okay.

Method overrides (covering method): occurs in two classes and two classes require inheritance relationship, the same method signature method called method overrides.

Methods rewrite rules:

The method signature must be the same (method name, parameter list)

Modifiers rights can not only be large decreases

Only a small no more abnormal

The return type is not only smaller increases

Common categories:

Random- generates a random number

Many properties and methods System- control system level are placed inside the class

Class time basis Date-

String class String-

Math- math, mathematical constant, are static        

interface:

  In the JAVA programming language is an abstract type, is a collection of abstract methods, usually the interface declared interface. Interfaces inherit a class manner, thereby inherit the abstract interface methods.

Interface rules:

  It can be inherited between interface and is multiple inheritance.

  The relationship between classes and interfaces are achieved, not inherited, can achieve more than.

  Internal interfaces are abstract and static constants.

 

Abstract class:

         Modification using the abstract class may contain abstract methods, it can not be instantiated.

         It is made to be inherited, can not be modified with a final class, an abstract method, but the method can be modified with specific final.

    An abstract class is class, class of regulatory compliance, such as single inheritance.

Java file structure:

The first line is the package statement package path.

The second part is a plurality of import to 0 for the leader packet.

The third part is the one or more class.

Only one class can be modified public, the other must be a default. public Modified class class name must be exactly the same file name.

Common Package description:

java.lang class contains basic Java program requires (default import)

java.util    contains a wealth of common tools, such as frame set, the date and time

java.math class comprising performing precision math functions

java.awt comprising creating graphical interface program message handling class and

java.io provide a data stream, target sequence and input / output class

java.net contains class network program

java.sql contains the API to access the database using java

java.text process comprising text, date, number, and message classes and interfaces

 

I 流:

Byte stream: InputStream and OutputStream byte input and output streams, is an abstract stream class.

Character stream: Reader and Write character input and output streams, it is an abstract stream class.

Common implementation class:

FileInputStream class

Such read data bytes from a file.

ByteArrayInputStream

Create a class byte array buffer memory, stored in the byte array buffer data read from the input stream.

ObjectInputStream class

Such objects from the input stream, reads object information.

FileOutputStream

Such bytes to write data to a file.

BufferedOutputStream

BufferedOutputStream output stream is buffered. It inherited FilterOutputStream.

BufferedOutputStream role is to provide another output "buffer function" Flow

ObjectOutputStream

Object class information is written to the output stream.

InputStreamReader

Such bytes are read from a data source and decodes it using a specified character set characters.

FileReader class

This class inherits from InputStreamReader, character class for reading files, such as text files.

 BufferedReader

This class is used to buffer the data read in units of characters.

FileWriter class

This class inherits from OutputStreamWriter class. The class to write data to a file character by character class.

 BufferedWriter

This class is used to write text characters output stream, buffering characters so as to provide efficient writing of single characters, strings and arrays.

Abnormal system:

Throwable class is the largest, the following two sub-categories: Exception, Error 

Exception exception type that can be processed, Error is a system-level error, the event can not be repaired. So we deal with in the normal means of Exception abnormal range.

Two types of abnormal under Exception: Abnormal and examination of abnormal operation. I know only Run Run abnormal when the need for treatment, checked exception in the preparation of the code must be considered mandatory exceptions for processing.

Exception handling:

      Capture and handle exceptions: try-catch-finally

      Can not handle Throws: throw (one line of code executed, an exception is thrown behind example), throws (declared on the method, a plurality of exception thrown back type)

Common exceptions:

Arithmetic exception classes: ArithmeticExecption

Null pointer exception classes: NullPointerException

Type cast exception: ClassCastException

Cross-border abnormal array subscript: ArrayIndexOutOfBoundsException

End of file an exception: EOFException

File not found an exception: FileNotFoundException

String into a number abnormalities: NumberFormatException

Operation database exception: SQLException

Input and output Abnormal: IOException

Method is not abnormal to find: NoSuchMethodException

Collections Framework:

Collection Interface

Collection is the most basic set of interfaces, a Collection represents a group of Object, the Collection element that is, Java does not provide directly inherited from the Collection classes provide only sub-interface (such as List and Set).

Collection interface storing a set of non-unique, unordered objects.

List Interface

List interface is an ordered Collection, use this interface to precisely control the inserted location of each element, the element can be accessed by an index List (List elements in position, similar to the array index), a first index element is 0, and allows the same elements.

List interface memory a set of objects is not unique, ordered (insertion order).

Set

Set Collection has exactly the same interface, but on different behaviors, Set duplicate elements are not saved.

Set interface to store a set of unique, unordered objects.

Map

Map interface storing a set of key objects, there is provided key (key) to a value (value) of the map.

Common Keyword:

members of the abstract class or method show abstract properties

One of the basic data types boolean, boolean

break advance out of a block

One of the basic data types of byte, byte type

case used in the switch statement, which represents a branch of 

catch in exception processing for capturing an abnormal

One of the basic data types char, character type

class class

continue back to the beginning of a block

default default, for example, used in a switch statement, indicating that a default branch

It does used in the do-while loop structure

One of the basic data types double, double precision floating point type

else used in a conditional statement, indicating that when the branch condition is not satisfied

enum Enumeration

extends indicate a type is another type of subtype common types There are classes and interfaces

final for explaining the final attribute that identifies a subclass of the class can not be derived, the method can not be covered or member 600 or members of a domain can not be changed

Finally statement block for processing exceptions, to declare a substantially certain to be performed to

One of the basic float data types, single precision floating point type

Words for guiding an endless structure

Guide word if conditional statement

implements show that a class implements the given interface

To access the show import the specified class or package

instanceof used to test whether an object instance of the object type is designated

One of the basic data types int, integer type

interface Interface

One long basic data types, long integer type

It is used to declare a native method is implemented by a computer-related language (e.g., C / C ++ / FORTRAN language)

new to create a new instance of an object

package wrapped

An access control private: private mode

An access control protected: Protected Mode

An access control public: common mode

return data from return members process

One short basic data type, short integer type

static show with static properties

show super type reference current parent object or parent type of construction method, the parent can use content

Guide word switch branch statement structure

this reference refers to the current instance of the object, the current contents of the object different from the super

throw throw an exception

throws member method statement currently defined exceptions thrown in all required

try a possible attempt to throw an exception block

Current members declared void method does not return value

while loop structure used in the

Guess you like

Origin www.cnblogs.com/kittybunny/p/10987758.html