Common Java APIs

Source: Internet
Author: User

Common Java APIs


Java.io.BufferedReader class (used to read a paragraph of characters from a file; owning kit: java.io)

1. Constructor BufferedReader (java.io.FileReader filereader variable) Description: Creates a new Bufferreader object.


2. Close method void Close () Description: Close the Bufferreader object.


3. ReadLine method java.lang.string ReadLine () Description: Reads a line of characters from a file. If NULL, the delegate reads to the end of the file.


Second, Java.io.BufferedWriter (write a character to the file.) Belongs to Kit: java.io)


1. Constructor: BufferedWriter (java.io.FileWrite FileWrite variable) Description: Creates a new Bufferwriter object.


2. Close method: void Close () Description: Close the BufferedWriter object.


3. NewLine method: Java.lang.string newLine () Description: Writes a line break to a file.


4. Write method: void Write (char character), void write (char[] character array), void write (string string), void write (char[] character array, start position in int array, int output length Description: Writes data to a file.


Third, Java.io.File (file for managing files or directories; Owned kit: java.io)


1. Constructor: File (java.lang.string path, java.lang.string file name) Description: Creates a Files object that represents a document or directory.


2, CanRead Method: (Boolean CanRead ()) to determine whether to read


3, CanWrite Method: (Boolean CanWrite) determine whether you can write


4. CreateNewFile Method: (Boolean CreateNewFile ()) Description: Create file, return true successfully, otherwise return false


5, Delete method: (Boolean Delete ()) Description: Delete the file or directory, the successful return true, otherwise return false.


6. Exist method: (Boolean exist ()) Description: Checks whether a file or directory exists.


7. GetName Method: (java.lang.string getName ()) Description: Gets the name of the file or directory.


8. LastModified method: (Long LastModified ()) takes out the last modification time.


9. Length method: (int length ()) Description: Gets the length of the file


10. Listfiles method: (file[] Listfiles ()) Description: Remove all files from the directory.


11, Isdirectory Method: (Boolean isdirectory ()) Description: Determine whether it is a file.


12, Isfile Method: (Boolean Isfile) Description: Determine whether it is a file.


13. Ishidden Method: (Boolean Ishidden ()) Description: Determines whether the file is hidden.


14, Mk Dir method: (Boolean mkdir) Description: Create directory, successfully return True, otherwise return false


Iv. Java.io.FileReader (FileReader for reading characters from a file; owning kit: java.io)


1. Constructor (FileReader (Java.lang.strig file path and name) Description: Establish a FileReader object for the file to be read)


2, Read method: (1) (int read ()) Description: Read a character from a file, the return value is an integer, the character code for the read string, and if the return value is-1, then the end of the file has been read. (2) int read (char[] chararray,int startpos,int length) Description: Starts from Startpos, reads the length character, saves to the Chararray array, the return value is the number of words read to, if return-1, Indicates that the end of the file has been read.


3. Skip method: (Long Skip (the number of characters in the int) Description: Direct the file reading pointer backward to move a few characters, so that the character is omitted to read);



V. Java.io.FileWrite class (used to write read characters to a file; owning kit java.io)


1, FileWrite (java.lang.string file path and name) filwrite (java.lang.string file path and name, Boolean append) Description: Establish a FileReader object for the file to be written, The parameter append indicates whether to add after the original file.


2. Write method: (void Write (char character), char[] character array, string string, char[] character array, start position in int array, int output length) Description: Writes data to a file.


VI. Java.lang.string Class (String class is used to handle the data type of the string; owning kit: Java.lang)


1, Charat method. (Syntax: char charAt (int index) Description: Returns the character at the specified position


2. Equals Method: (Syntax: Boolean equals (Object AnObject) Description: Determines whether the string is equal to the specified object) case: if (str.equals ("abc")) {out.print ("STR's value is ABC") ;}


3. Index of Method: (Syntax: int indexOf (char ch), int indexOf (string str) Description: Returns the position of the character or substring to find first occurrence in the string, and returns 1 if the character/substring is not found).


4. LastindexOf method (Syntax: int lastindexOf (char ch), int lastindexOf (string ch) Description: Returns the position of the character or substring to look for the last occurrence in the character. Returns 1 if the character/substring is not found)


5. Replace method: (Syntax: string replace (char Oldchar,char Newchar) Description: Replaces a character in a string, the return value is the replaced result. )


6. Substring method: (Method: String substring (int beginindex); string substring (int beginindex,int endIndex) Description: Gets the substring in the string. Example: String a= "AABB"; b=a.substring (1) The final result is "ABB" c=a,subsirng, and the final result is "AB".


7. Method of Case conversion (syntax: string toLowerCase (), String touppercase () Description: Case conversion of a string, return value is the converted result)


8. ValueOf Method (Syntax: String valueOf (Object obj) Description: Convert object to String, return value to converted result)



Vii. Java.net.URL Encoder (Description: Urlencoder class is used for URL encoding. Owning kit: JAVA. NET)


1. Encode method (Syntax: java.lang.string encode (java.lang.sring string to encode) Description: Returns the encoded string. )



Viii. Java.text.simpleDateFormat Class (Description: The SimpleDateFormat class is used to process the formatted output and input of the date data. Belongs to Kit: Java.text)


1. Constructor: (Syntax: SimpleDateFormat (JAVA.LANG.STRNG formatted string) Description: Generates SimpleDateFormat object based on specified format string)


2. Format method: (Syntax: java.lang.string format (java.util.Date date data) Description: Converts the date data to a string of the specified format. )


3. Parse Method: (Syntax: Java.util.Date parse (java.lang.sring string) Description: Converts a string to Date data. If the format is incorrect, an exception will be generated.






Ix. Java.spl.DriverManager Class (description: When the database driver is loaded into memory, the system automatically registers the loaded driver with the DriverManager class so that its status is available (available) belongs to the bundle: JAVA.SPL


1. Getconnection Method: (Syntax: getconnection (String data source name, string user name, string user password) Description: Open the database link. )



X. Java.sql.connection Class (Description: The connection class is used to process a link to a database. Belongs to Kit: java.sql)


1. Createstatement Method: (Syntax: java.spl.statement createstatement (int pointer type parameter, int data consistency parameter) Description: Establishes the statement object.



Xi. Java.sql.ResultSetMetaData Class (Description: The ResultSetMetaData class is used to obtain information about the recordset field. Belongs to Kit: java.sql.


1. getColumnCount Method: (Syntax: int getcolumncount () Description: Gets the number of fields in the Recordset)


2. getColumnName Method: (Syntax: java.lang.String getcolumnname (int column) Description: Gets the word name of the field. Where the field index value is the index value of the field in the recordset, the index value of the first field is 1, and the index value of the last field is the total number of fields.



12, Java.sql.Statement Class (Description: Statement class can execute SQL actions and query statements, to achieve the operation of the database. Belongs to Kit: java.sql).


1. Execute method: (Syntax: boolean execute (String sql) Description: Execute SQL action statements, such as INSERT, delete, modify, and so on. Example: St.execute ("delect from Table")//delete data from table tables.


2, ExecuteQuery Method: (Syntax: Java.sql.ResultSet executeQuery (String sql) Description: Execute SQL query statement, get the corresponding recordset. Example: Rs=st.execute ("SELECT * FROM table")//Extract data from the table.




13, Java.sql.ResultSet Class (Description: The ResultSet class is used to process a recordset. Belongs to Kit: java.sql)


1. Absolute method (Syntax: boolean absolute (int row) Description: Sets the location where the record pointer points to the record. )


2. Afterlast method: (Syntax: void Afterlast () Description: Moves the pointer after the last record. )


3, Beforefirst () Method: (Syntax: void Beforefirst () Description: Moves the pointer before the first record. )


4. First method: (Syntax: Boolean one () Description: Moves the record pointer to a record. )


5. Isafterlast Method: (Syntax: Boolean isafterlast () Description: Determine if the record pointer is pointing to the last record)


6. Isbeforefirst Method: (Syntax: Boolean isbeforefirst () Description: Determines whether the record pointer points before the first record.


7. IsFirst Method: (Syntax: Boolean isFirst () Description: Determines whether the pointer points to the first record)


8. Islast Method: (Syntax: Boolean islast () Description: Determines whether the record pointer points to the last record. )


9, field value Get Method (Syntax: Object get ... (string columnName); object get ... (int columnindex) Description: Remove the value of the field from the ResultSet object) Example: String name=rs.getstring ("use");


10, GetMetaData Method: (Syntax: Java.sql.ResultSetMetaData resultsetmetadata getmetadata () Description: Gets the ResultSetMetaData object corresponding to the ResultSet object. )


11, GetRow Method: (Syntax: int getRow () Description: Get the current record pointer to the location of the record)


12. Next method: (Syntax: Boolean next () Description: Move the pointer to the next bar)


13, Previous method: (Syntax: Boolean previous () Description: Move the pointer to the previous bar)




14. Java.util.Date Class (Description: Date class is used to process dates for this data type. Belongs to Kit: Java.util)


1. Constructor: (Syntax: date ();D ate (long milliseconds), date (int, int, int, int, int, int seconds) Description: Produces a Date object. This object is the given time. If there is no input parameter, the value of this Date object is the current system time. )


2. GetTime method (Syntax: Long getTime () Description: The time the object represents, the number of milliseconds from midnight January 1, 1970. )


3, Get Year Method: (Syntax: int getYear () Description: Gets the yearly value of the Date object, and the output value is based on 1900. )


4. GetMonth Method: (Syntax: Gets the month value of the Date object, the value of the output is 0 for 1, 1 for 2, the rest of the analogy)


5. GetMonth Method: (Syntax: int getDate () Description: Gets the day value of the date object)


6. Getday method (Syntax: Intday () Description: Gets the week value of the Date object. )


7. GetHours Method: (Syntax: int getHours () Description: Get the Date object's Hour value)


8. Getminutes Method: (Syntax: int getminutes () Description: Gets the score of the Date object. )


9. Getseconds Method: (Syntax: int getseconds () Description: Gets the second value of the Date object. )


10. Setyear Method: (Syntax: void setyear (int year) Description: Sets the Date object annual value, and the input value is 1900. ) Setting: Month\day\hours\seconds is used in this way.



XV, Javax.servlet.http.cookie (Note: The cookie class is primarily used to deal with the use of cookies.) Belongs to Kit: javax.serlet.http)


1. Constructor (Syntax: Cookie ("Data name", value) Description: Create a new Cookie icon. It is important to note that the only strings that can be saved to a cookie are those that need to be converted to other types of data. )


2. GetDomain method: (java.lang.string getdomain () Description: Obtain a Web site address that can access the cookie variable. )


3. GetName method: (Syntax: java.lang.string getName () Description: Gets the name of the data in the cookie variable. )


4, Getmaxage Method: (Syntax: Long setmaxage () Description: The effective time to obtain a cookie. Input valid time unit is seconds)


5, GetPath Method: (Syntax: java.lang.string getpath () Description: Access to the cookie variable)


6. SetDomain method: (Syntax void SetDomain (java.lang.string pattern) Description: Sets the Web site that can access cookie variables. )




16. Java.servlet.http.httpservletRequest Class (Description: The implicit object request in JSP is the object of the class. Used to process information related to browser requests. Belongs to Kit: javax.servlet.http)


1. GetAttribute Method: (Syntax: Object getattribute (java.lang.string variable name) Description: Remove the data stored in the Request object. This data is stored in the request object using the SetAttribute method.


2. GetBufferSize method: (Syntax: int getbuffersize () Description: Gets the current buffer size. )


3. GetCookies Method: (Grammar: javax.servlet.http.cookie[] getcookies () Description: Obtain the cookie related to the request.)


4. Getdateheader Method: (Syntax: Getdateheader (java.lang.string name) Description: Gets the header of the specified name, date type. )


5. Getintheader Method: (Syntax: a header that gets the specified name, integer type)


6. GetHeader Method: (Syntax: java.lang.string getheader (java.lang.string name) Description: Gets the header of the specified name. )


7, GetMethod Method: (Syntax: Java.lang.string.getMethod () Description: Get data to send the method (get or post))


8. GetParameter Method: (Syntax: java.lang.string getparameter (java.lang.string name) Description: Gets the value of the parameter name. The return value is string. Returns null if the argument does not exist. )


9. Getparameternames Method: (Syntax: Java.util.Enumeration getparameternames () Description: Gets all the parameter names.


10. Getparametervalue Method: (Syntax: java.lang.stirng[] getparametervalues (string name) Description: Gets the parameter value that all parameter names are name.


11. Getprotocol Method: (Syntax: java.lang.string getprotocol () Description: Access Agreement (http/1.1 or http/1.0)


12. GetQueryString Method: (Syntax: java.lang.string getquerystring () Description: Gets the requested parameter string (the method for sending data is get)).


13, Getrealpath Method: (java.lang.string getrealpath (java.lang.string virtual directory address) Description: Obtain the virtual directory corresponding to the disk address. )


14. Getrequesturl Method: (Syntax: java.lang.stirng getrequesturi () Description: URI to get request (not including request string))


15, Getremoteaddr Method: (Syntax: java.lang.string. GETREMOTEADDR () Description: Obtain the IP address of the user making the request/)


16. Getremotehost Method: (Syntax: java.lang.string getremotehost () Description: Gets the host name of the user who made the request and returns the user's IP address if the host name cannot be determined)


17. Getremoteuser Method: (Syntax: java.lang.string getremoteuser () Description: Gets the name of the user who made the request. )


18. SetAttribute Method: (Syntax: void setAttribute (java.lang.string variable name, object variable value) Description: Saves the data to the request object. )


19. Setbuffersize Method: (Syntax: void setbuffersize (int buffer size) Description: Sets the buffer size.


20. RemoveAttribute Method: (Syntax: void removeattribute (java.lang.stirng variable) Description: Deletes the data stored within the request object.




17. Javax.servlet.HttpSession Class (Description: The hidden object session in JSP is the object of this class, which is used to process information related to the current client session. Belongs to Kit: javax.servlet.http)


1. GetAttribute Method: (Syntax: Object getattribute (java.lang.stirng variable) Description: Remove the variable stored inside the Sesson).


2, GetCreationTime Method: (Syntax: Long getcreation Time () Description: Take out the establishment of this Sesson object)


3. GetID method: (Syntax: java.lang.string getID () Description: Remove the number of this Sesson object)


4, Getlastaccesssedtime Method: (Syntax: Long getlastaccessedtime () Description: Take out the last access time of this Sesson object)


5. Getmaxinactiovinterval Method: (Syntax: int getmaxinactiveinterval () Description: Gets the maximum time interval for the Sesson object currently set, in seconds. If the user exceeds this time interval without action, the Sesson object is invalidated)


6. Invalidate method: (Syntax: void invalidate () Description: Force End service side represents this online Sesson object)


7. IsNew Method (Syntax: Boolean isnew () Description: Determines whether the Sesson object is a newly created object)


8. SetAttribute Method: (Syntax: void setAttribute (java.lang.string variable name, object variable Value) Description: Save the data to the Sesson object)


9. RemoveAttribute Method: (Syntax: void removeattribute (java.lang.string variable) Description: Delete data saved in Sesson object)




18, Javax.servlet.jsp.jspWrite Class (Description: The implicit object out of the JSP is the object of the class. Belongs to Kit: javax.servlet.jsp)


1. Flush () Method: (Syntax: void flush () Description: Forces data in the output buffer. This method has similar effect to the Flushbuffer of HttpServletResponse Class)


2. GetBufferSize method: (Syntax: int getbuffersize () Description: Gets the current buffer size)


3. Getremaining Grammar: (Syntax: int Remaining () Description: Gets the remaining space of the current buffer. )


4. println Method: (Syntax: void println (java.lang.string output String) Description: output string. )

Common Java APIs

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.