This is the 9th day of my participation in Gwen Challenge
What is the API
We’ve talked a lot about Java apis, but what is an API?
API stands for Application Programming Interface, which translates as Application Programming Interface.
Let’s say I write a class that can translate input text. This class is very stable and useful if you need one in your project. So you don’t have to write your own code, you can just use my class. But I don’t want people to see the internal implementation, and I want to protect copyright, so what do I do?
At this point, I can compile my class and come with a document that tells you how my class works and what methods it has, and you just have to follow the instructions. It saves your coding time and protects my copyright. For example, the method of text translation:
String translate(String text, String language)
Copy the code
This way of describing how classes are used is called an API.
The Java API documentation, such as Java SE 8:docs.oracle.com/javase/8/do…
The commonly used API
This section describes the apis commonly used in the Java core class library.
The package name | package | API | API specification |
---|---|---|---|
java.lang | Java core package, covering the basic classes of Java programming, JVM automatic import without manual guide package. | Object#equals(Object obj) | Determine if some other object is “equal” to this object |
Object#hashCode() | Gets the hash code value of the calling object | ||
Object#toString() | Gets the string form of the calling object | ||
String#length() | Gets the length of the string | ||
java.util | Java toolkit, covering collection classes and utility classes. | Date() | Constructs objects based on the current system time. |
Collection#add(E e) | Add objects to the collection | ||
List#get(int index) | Gets the specified location element from the collection | ||
Queue#offer(E e) | Adds an object to the end of the queue | ||
Set#iterator() | Gets an iterator object in the current collection, fetching each element | ||
Map#put(K key,V value); | The key-value pair is stored in the Map. If the set already contains the key, the value corresponding to the key is replaced, and the value corresponding to the original key is returned. If the set does not, null is returned (add and modify). | ||
java.io | Java I/O packages that provide input and output to the system through file systems, data streams, and serialization. | File(String Pathname) | Constructs the object based on the path specified by the argument |
File#createNewFile() | Use to create a new empty file | ||
java.net | Java Network package, covering network programming classes. | Socket#close() | Close the Socket |
java.sql | Java data API package that covers all classes and interfaces that operate on the database. | Connection#createStatement() | Create a statement that sends SQL to the database |
conclusion
This section introduces the concept of class libraries and the use of JAR files. It focuses on the concept, origin and function of three common Jars in Java. At the same time, it mentioned that the class loading mechanism of Java is the parent delegate mode. After reading this article, you should have a better understanding of the Java core class library.
Ok, share here, if you like my share, please be sure to triple, like, in view, favorites, follow me, it will be very helpful to me.
I’ll see you next time.