31. Convert the encapsulated object to the basic data type: obj. xxxvalue (); obj is the encapsulated object, and XXX is
Basic data type.
32. Convert from string to basic data type: obj. parsexxx (string Str); obj is the object of the encapsulation class, and XXX is the encapsulated object.
The basic data type.
33. convert a string to an encapsulated object: obj. valueof (string Str ).
34. Convert the encapsulated object to a string: obj. tostring ().
35. Convert from basic data type to string: obj. tostring (xxx value ).
36. not equal :! =
37. The instanceof operator, such as V1 instanceof V2. Check whether V1 is an instance of class V2.
38. The formulas on both sides of the logical operator must be boolean. Unlike C ++, integers other than 0 in C ++ are regarded as true.
39. bitwise logical operators: &, V1 & V2. And, if the relative bits are both 1, then 1, otherwise 0
|, V1 | V2. Bit or. If the relative bits are both 0, the value is 0. Otherwise, the value is 1.
^, V1 ^ V2. Bit XOR. If the relative bit has the same value, the value is 0. Otherwise, 1 is returned.
~ ,~ V1. The complement of V1. 1 is changed to 0, 0 to 1.
V1 and V2 must belong to the integer type.
40. Java does not support operation overloading, and does not support the: And> and <operators of C ++.
41. Constant Designation: static final int num = 1.
42. array definition: int num []; or Int [] num; num = new int [15]; or Int [] num = new num [15]; or int
Num [] = {1, 2, 4, 5 };
43. If the length of the 2nd dimension of a two-dimensional array is different, because the array variable itself is a reference type, you can point the 1st dimension to another array.
44. Copy an array: void arraycopy (Object SRC, int srcposition, object DEST, int destposition, int
Length) or clone () for example int [] newa = (INT []) A. Clone ();
45. array operations provided by the arrays class, such as sorting and searching
Static void sort (datatype [] data): sorts the elements in the array data from small to large (using quicksort)
Static void sort (datatype [] data, int fromindex, int toindex)
Static int binarysearch (datatype [] data, datatype key): searches for array data using binary search
(The key must be sorted in advance. If it is found, the location of the key in data is returned. If it cannot be found, the return value is (-insert
Insert point is the first index with the element value to be searched.
Static void fill (datatype [] data, datatype Val): sets each element in the array to Val.
Static void fill (datatype [] data, int fromindex, int toindex, datatype Val)
46. In Java, char arrays and string classes do not end with '/0. The char array is not equal to the string object. The array is variable,
However, the string object remains unchanged.
47. Convert the char array into a string object. Char [] DATA = {'s ', 't', 'R',' I ', 'n', 'G'}; string STR = new
String (data );
48. Length () gets the length of a string, and length can be used to get the number of elements contained in an array.
49. Because the Java object is of reference type, string1 = string2 only compares whether the variables string1 and string2 point
The same address does not compare the content of strings.
50. Int compareto (string Str): s1.compareto (S2 ). If S1 and S2 are equal, 0 is returned. If S1> S2, the return value is greater
0; If S1 <S2, the return value is smaller than 0.
Int comparetoingnorecase (string Str): s1.comparetoingorecase (S2 ). Case Insensitive.
Boolean equals (Object OBJ): s1.equals (S2 ).
Boolean inclusignorecase (string Str): s1.20.signorecase (S2 ).
51. Search and read some strings:
Boolean startswith (string Str): checks whether STR is at the top of the string.
Boolean endswith (string Str)
Int indexof (char ch): obtains the location where ch first appears in the string. If it cannot be found,-1 is returned.
Int indexof (string Str)
Int lastindexof (char ch)
Back-1
Int lastindexof (string Str)
String substring (INT begin): generates a new string that contains all the original string positions from begin to the final end.
Character
String substring (INT begin, int end)
52. stringtokenizer (string Str): analyzes a string using the default delimiters: '', '/t','/N'
, '/R','/F '.
Stringtokenizer (string STR, string delimiter): analyzes strings using the specified delimiter.
53. The stringbuffer class is used to generate a string buffer, which is called a variable string. Default capacity of the stringbuffer object
It must contain 16 characters.
54. stringbuffer cannot directly assign a string to a stringbuffer object like a string object, for example, stringbuffer
Mystring3 = "this is worong ". The stringbuffer object must be generated using new.
55. The stringbuffer object has the capacity and length. The capacity remains unchanged and the length is variable. The length is less than or equal to the capacity, indicating the actual
The number of characters stored.
56. Int capacity (): returns the capacity of the stringbuffer object.
Int length (): returns the length of the stringbuffer object.
Stringbuffer append (datatype data): add data to the end of the stringbuffer object
Stringbuffer insert (INT offset, datatype data): insert data before the offset position
String tostring (): converts a stringbuffer object to a string object.
57. when the length of the stored string exceeds its capacity, the capacity will be changed to twice the original capacity plus 2. Pre-specified enough capacity is more efficient
58. Data members represent the variables declared in the class, which can be static (class variables) or non-static (instance variables)
59. Methods in the class are classified into static (class method) and non-static (instance method)
60. Each object has its own instance variable and variable value, which can be used to access instance variables.
61. Each class has only one class variable. objects belonging to this class share class variables. You do not need to use objects to access class variables.
62. A static method can only access static data of a class. A static method can only access static methods of a class.
Use this in the word method; a static method cannot be replaced by a non-static method.
63. The constructor does not return values. It must have the same name as the class in which it belongs. If the class used does not have a constructor, the Java compiler will automatically generate
A default constructor (excluding parameters ).
64. In Java, new cannot be omitted. Using New indicates that the memory of the variable is dynamically allocated, but you must remember to release it.
65. The value of the basic data type is stored in the stack, while the referenced data type is to reference it in the stack, but the referenced object is
Heap exists.
66. Java has reference data types and basic data types, but there is only one transmission method, that is, pass-by-value ),
Pass-by-reference is not passed ). The method receives a copy of the original value. For the basic data type,
The received data is a copy of the data value. For the reference data type, the received data is a copy of the reference value, instead of
Reference itself.
67. If you want to achieve the effect of passing through references like C/C ++ in Java, you can use arrays as parameters.
68. Except for data members declared as private, the class of the same package can inherit all other data members, while the class of other packages can
Inherits public and protected data members. These rules apply to all data members (class or instance variables) and
Method, but the constructor of the parent class is not inherited. Members defined as final cannot be inherited.
69. When method Overloading is used, the signature (Method Name, number of parameters, and parameter type) cannot be declared in the same class but the return value is different
Method.
70. Call the method overload static method binding or pre-binding. This is because the compiler determines the parameter type and quantity during compilation.
The method to call, rather than the method to be executed.
71. Many classes can be stored in the same file, but only one class can be declared as public. Other classes are called helper classes.
, The helper class can also contain main (), but will be ignored.
72. In the following cases, such statements must be Abstract:
This class has one or more abstract methods (declared but not defined methods)
This class inherits one or more abstract methods from an abstract class, but does not provide implementation methods for these methods.
This class implements an interface, but does not implement all the methods of this interface.
73. abstract methods cannot be declared as private because abstract classes are inherited by other classes. Cannot generate an abstract class
Object, but a variable of abstract type can be declared.
74. polymorphism (polymorphism) indicates that the same notation can be used to process multiple different types of data. Overload is a type of polymorphism called
Static polymorphism. The general polymorphism is dynamic polymorphism, which determines the behavior of a method based on the object during execution. This is a dynamic method binding.
Fixed (later binding ).
75. In C ++, polymorphism is implemented through virtual functions, and Java uses abstract classes to implement polymorphism.
76. The interface is used to indicate what a class can do, but not how it is done (the actual work will be done by the programmer who uses this interface)
Therefore, APIs are often used to develop class design protocols. The main spirit of Java API design is to integrate interfaces with actual classes.
Because different systems may have different implementation methods, but the methods used by users are the same.
Implant problems.
77. interfaces and classes can be used as data types, but they cannot be used to generate new objects like abstract classes.
78. An interface is a combination of a group of constants and abstract methods. constants in an interface are always public, static, and final (
, Sometimes we only use interfaces to store user-defined constants without any methods), while the methods are always public and
Abstract, even if not explicitly stated.
79. A class can implement an interface through the keyword implements, and a class can implement more than one interface.
80. The same as the class definition, one interface can inherit other interfaces through extends. The difference is that interfaces support multiple inheritance because
The method in the interface is not defined, and there is no problem of multi-class inheritance.
81. Unlike abstract, when a class implements an interface, this class must define the methods in all interfaces.
82. Combine interfaces with abstract classes. In addition to using interfaces for multi-inheritance, a common design method is to use interfaces.
Generate a new data type, but it is not restricted by the specific implementation method. This is similar to the basic data type and does not generate
Object. Abstract classes can also be used to define new data types, but will selectively implement common methods.
Of course, general classes can also be used to define new data types, but all methods are implemented. Therefore, when designing a more Scalable Data
Type, the interface is usually the top layer, and the abstract class is the middle layer, and the following is the general class.
83. Defining a class in another class is called an internal class.
84. An anonymous class is an internal class without a name and does not have a constructor. For example:
Button. addactionlistener (New actionlistener ()
{
Main program used to implement actionlistener
} // This object is only used in addactionlistener ()
)
85. in Java, the most common use of internal and anonymous classes is the GUI.
86. Because the Anonymous class has no name, the generated class file will be represented by numbers, such as outer $1. Class.
87. Garbage Collection: a better method is to set unused objects to null.
88. Force garbage collection: system. GC ().
89. Finalize () is executed before the object is released. It is a method inherited by all Java objects.
90. Generate a package: Add package {packagename} at the beginning of the defined class program and put it before import.
91. Package name: lowercase letters, domain names in reverse order.
92. The class in the package must be declared as public. Otherwise, the method that does not belong to this package cannot use it.
93. Use a jar file for easy maintenance and installation. A jar file usually contains multiple packages. The standard classes provided by Sun j2se are placed in rt. jar.
.
94. j2se provides tool software jar to generate jar files:
Jar CVF <JAR File> <class File>
Jar cmvf <manifest> <JAR File> <class File> use M to include a custom description (manifest) File
Manifest. MF.
95. Enter the created package in: Import com. mycompany. Shape. *; non-import com. mycompany. SHP;
This jar file is included in the class path. In Windows, you need to set: Set classpath =.; shapr. jar. Or you can use: Java
-Classpath <class path> <class File>
96. Because the variables related to the object belong to the reference type, use obj1 = obj2; obj1 only obtains a copy of The obj2 application, instead
The obj2 object itself.
97. Use clone () to copy an object. Clone () inherits from the object class. Obj1 = obj2.clone (); obj2 must be replicable
.
98. To make a custom Class Object reproducible, you must use the interface cloneable and declare a public method clone ()
To perform replication.
99. To complete deep copy (including the referenced object and its related objects), you must follow the hierarchical relationship between objects.
Copy them one by one.
100. Reflection is also called introspection because it allows Java programs in execution to perform self-check and get an object
It is a unique function of Java.
101. Reflection improves functions like function pointers, and dynamically improves the Class Object method name and
The parameter to be entered.
102 first, get a Class Object. There are two methods:
Use getclass () to obtain a class object from the existing class object, such as obj. getclass ();
Use class. forname (string classname)
103. Second, use the method provided by the class to obtain relevant data of the class.
String getname (); used to obtain the name of the class
Method [] getdeclaredmethods (); obtain the names of all methods declared in this class.
Method [] getmethods (); obtain all method names in the class, including methods inherited by the parent class
Method getmethod (string methodname, class [] parametertypes); get a method object
104. Finally, use the method provided to execute the method to be executed
Object invoke (Object methodobj, object [] parameters); generate
Invocatiotargetexception
105 when the reflection function is used to execute methods in the class, the input data type of the method is special. Syntax:
Typename. class, for example, int [] is int []. Class, Int Is Int. Class, and string is string. Class. The input parameter must be a pair
Object)
106 in order to know the execution efficiency of a Java program and provide methods for improving the program, Java provides the Java profiling function.
Java-xrunhprof: Help is used to query available options of Java profiling. For example, understand the execution time of various methods in the program
Proportion, you can use Java-xrunhprof: CPU = times classname. A java.hprof.txt file will be created.
107 throwable is the parent class for error handling in all Java programs. There are two classes: Error and exception.
108. Error: Indicates unexpected errors detected by the JVM. This is a serious error at the JVM level, causing the failure of JVM
Therefore, this operation cannot be captured and cannot be restored. At most, only error messages can be displayed.
109. Exception: Indicates recoverable exceptions, which can be captured. Therefore, when exceptions occur, You can take recovery actions.
110. Exception Handling Method: If you want to ignore exceptions that may occur in the program and submit them to other programs for processing, you can directly
Return the called program, and the called program must process these exceptions or return them to the called program.
111. method 2 of Exception Handling: If you want to directly process these exceptions in the program, you can use the try... catch (... finally)
Method.
112. Finally can be omitted. If used, the finally program will be executed and generally used for the final cleaning, as shown in
Disable the opened system resources.
113. Methods provided by throwable:
String tostring (): represents the string representation of the throwable object.
String getmessage (): Returns Error information related to this object.
Void printstacktrace (): displays the way exceptions are generated.
Void printstacktrace (printstream out): output to a printstream data stream.
Write to a file.
Void printstacktrace (printwriter out): output to a printwriter data stream.
114 try... catch is also a segmented architecture, and the visible range of sub-variables must follow the same rules.
When the catch (or finally) block can use variables in the try block, you must declare the variables outside the try... Catch Block.
115 when the program needs to capture several different exceptions, pay special attention to the order of these exceptions. It should be placed according to the class relationship between classes
The more basic the class needs to be placed in the catch () section.
116 an exception class must contain at least one default constructor (used to display the default information) and a string object as the parameter.
(Used to display User-provided custom information ).
117, C/C ++ can only provide byte streams. in Java, there are also byte streams and character streams.
118. byte stream: methods provided by outputstream:
Void write (int B): write data in one byte
Void write (byte [] buffer): writes data from the array buffer to the stream.
Void write (byte [] buffer, int offset, int Len): number of len bytes written starting from buffer [offset]
Data
Void flush (): forcibly writes data in the buffer to the stream.
Void close (): Close the stream
119. Methods provided by inputstream:
Int read (): reads a byte of data. If the data reaches the end of the file, the returned value is-1.
Int read (byte [] buffer): reads data of the buffer size. The returned value is the number of bytes actually read.
Int read (byte [] buffer, int offset, int Len)
Int available (): returns the number of bytes that can be read in the stream.
Long SKIP (long n): Skips n bytes of data. The returned value is the number of actually skipped data.
Void close (): Close the stream
120. streams. The methods provided in the reader and writer classes are the same as the byte streams, except that the byte [] in the parameter must be changed to Char []
121 stream functions can be divided into data sink stream (listener: memory, pipeline, file) and Process Stream
(Processing Stream)
122. before talking about Java stream classes, let's first talk about how to generate a file object, which is a class unrelated to the stream. File objects can be generated.
Objects related to files (and their paths) or directory structures. Because different systems may have different directory result representations
File can be used for system-independent purposes (using abstract path Notation ).
123 file object generation method:
File (string path): converts a string representing a path into an abstract path representation.
File (string parent, string child): parent indicates a directory, Child indicates a file, and child cannot be empty.
File (File parent, string child): parent represents the directory of a file object, child represents the file, and child does not
Can be empty
124 file provides some methods to test or check a file object:
Boolean exists (): returns true if the file or directory exists.
Boolean isdirectory (): returns true if it is a directory.
File [] listfiles (): obtains the array of file objects under the directory represented by this object. If this directory is not used, null is returned.
String [] list (): Same as above, but returns a String Array
Long length (): obtains the size of the file related to this object. If it does not exist, the return value is 0l.
String tostring (): obtains the abstract path representation.
String getparent (): Get the directory part of the abstract path representation (excluding the last part)
String getname (): gets the last part of the abstract path representation.
125 Method for changing a file object:
Boolean renameto (File newname): change the path name represented by the current file object to the path name represented by newname.
. If the change is successful, the return value is true.
Boolean mkdir (): generate a new directory. If the input succeeds, the return value is true.
Boolean mkdirs (): generates a new directory that contains non-existent subdirectories. If the call succeeds, the return value is true.
Boolean Delete (): delete the file or directory represented by the current file object. If it is a directory, it must be empty. If successful,
Returns true.
126 listfiles () without parameters will list all file names. Using file [] listfiles (filenamefilter filter)
Filter some special extensions or file names that contain certain characters. Filenamefilter is an interface that must generate a class to implement it.
Filters file names. This class must replace the unique method accept () of filenamefilter (). Boolean accept (File Dir, string
Name). If true is returned, the currently checked files are included in the returned array of listfiles.
127. constructor of byte stream:
Fileinputstream (string name): Open the file name to read data.
Fileinputstream (File file): Open the file associated with the file object to read data.
Fileoutputstream (string name): Open the file name to write data.
Fileoutputstream (File file): Open the file associated with the file object to write data.
Fileoutputstream (string name, Boolean append): Open the file name to write data. If the append is
True, the written data will be added to the original file.
128. constructor of byte array:
Bytearrayinputstream (byte [] buffer): generates an input stream of a byte array and specifies a byte array.
Buffer refers to the stream buffer of the input stream.
Bytearrayoutputstream (): generates an output stream of a byte array. The default buffer size is 32 bytes. If
The buffer size increases as needed.
Bytearrayoutputstream (INT size): Same as above, but the initial size of size bytes is allocated to the buffer.
129. Some common bytearrayoutstream methods:
Int size (): returns the size of the stream buffer.
Byte [] tobytearray (): generates a new byte array and copies the stream content to this array.
String tostring (): converts the stream content to a string object.
130. File merging: sequenceinputstream
Sequenceinputstream (inputstream head, inputstream tail): generate a new input stream, first read
Head, followed by tail
Sequenceinputstream (enumeration Enum): merges the streams in the enum into a new input stream in order.
It must be an inputstream object.
131. The vector function is like an array, but it can change the size as needed.
132 pipeline (PIPE) provides a method for inter-thread communication.
Message) or ITC (Inter-thread communication), but it cannot implement communication between different hosts.
133 an input pipeline is used to receive data written by an output pipeline. Therefore, a thread is responsible for sending
(Pipedoutputstream object), and the other thread is responsible for receiving (pipedinputstream object) the data.
134 data flow of an MPS queue is unidirectional. Another set of input and output MPs queues must be generated to transmit data in another direction.
Send.
135 if you want to send data from the output stream of the pipeline to the input stream of the pipeline, you can use
Pipedoutputstream (pipedinputstream pipein) or
Connect (pipedinputstream pipein)
140. Producer stream class: 1). bufferedreader is a filter (extends filterreader ). Filters
To process and output the stream data. The constructor is:
Bufferedreader (Reader in): generates a buffer character input stream. In is a reader.
Bufferedreader (Reader in, int size): generate a buffer character input stream, and specify the buffer size
Size
Common Methods:
String Readline (): reads a line of text (ending with/N or/r). The returned string object does not contain/N or/R. If
If the end of the stream has reached, null is returned.
When using the read () or Readline () of the buffer stream to read data, the system first tries to read data from the buffer.
Data, the data will be read into the buffer as much as possible to be read later.
141, 2), linenumberreader is also a filter, and it is also a buffer stream (extends bufferedreader), available
To record the number of rows read. Here, a row ends with/N or/R. Common Methods:
Int getlinenumber (): returns the current number of rows.
142, 3), printerwriter is also a filter (extendes filterwriter) that can be used to import the output to a certain device.
143. One feature of I/O streams is that they can be combined through stream links. Each stream class will execute special work and then upload the result
Next link, you can use the filter to link the stream together.
Bufferedreader inbuffer = new bufferedreader (New filereader (infile ));
When using stream links, you only need to close the link stream at the outermost layer. Other links will automatically close the stream. The link that can be used is the last stream (
Inbuffer). At this time, we cannot directly use the filereader stream. If it is written:
Filereader filein = new filereader (infile );
Bufferedreader inbuffer = new bufferedreader (filein );
At this time, filein still exists, which may cause two stream links to direct the same source (infile) at the same time due to Write Program negligence.
There is always potential danger.
144 Random Access: randomaccessfile, constructor
Randomaccessfile (File file, string mode): Where mode is used to specify the access mode, which can be R, W, or RW.
Randomaccessfile (string name, string mode): name indicates the name of the system-related file.
Common Methods:
Read: Boolean readboolean (); byte readbyte (); char readchar (); double readdouble
(); Float readfloat (); int readint (); long readlong (); short readshort (); string Readline ()
Write: void writebyte (byte V); void writebyte (string S); void writechar (char V); void
Writechars (string S); void writedouble (Double V); void writefloat (float V); void writeint (int
V); void writelong (long V); void writeshort (Short v)
Methods related to the current file location:
Void seek (long POS): Move the file pointer to the position of pos (which cannot be negative). This is the value relative to the initial position of the file (
The initial value is 0)
Long getfilepointer (): obtains the position of the current file pointer.
Long length (): Get the object length.
145. File compression and decompression methods: zipinputstream (extends inflaterinputstream) and zipoutputstream
(Extends deflateroutputstream)
146 to write a file into a zip file:
1) generate the zipoutputstream object associated with the zip file to be generated
2) a zip file usually contains more than one compressed file. We call each file to be added a ZIP entry.
Use zipentry (string filename) to generate these zipentry objects.
3) Use putnextentry (zipentry entry) to add this ZIP entry to the ZIP file
4) write the file content to this ZIP file
5) Use closeentry () to end the current ZIP portal and continue to the next zip portal.
147 steps to read a compressed file from a zip file:
1) generate the zipinputstream object associated with the zip file to be read
2) use getnextentry () to get the next ZIP entry
148. The object is stored in a stream called serialization. To complete object serialization
A stream is called serializing, while a stream reads objects as deserializing )).
149 the objects to be accessed must meet the following conditions:
Class must be public
Class must implement the serializable Interface
If any data is not serializable or does not need to be written, it must be declared as transient.
150. java. Io provides objectinputstream and objectoutputstream to access objects.
Dataoutputstream has a common interface, so they can also use the same method to read or write data. There are other methods:
Void writeobject (Object OBJ): used for objectoutputstream to write objects to the stream.
Object readobject (): used for objectinputstream to read objects from the stream.