Common Java Libraries |
\n\nJava provides a rich set of libraries. Below are some of the most commonly used classes.
\n\n1. Core Java Libraries
\nThe Java Standard Library provides a rich set of built-in libraries. Here are some commonly used core libraries:
\n\n| Category | \nLibrary Name | \nMain Function | \n
|---|---|---|
| Collection Framework | \njava.util.ArrayList | \n Dynamic array implementation | \n
| \n | java.util.LinkedList | \n Doubly linked list implementation | \n
| \n | java.util.HashMap | \n Map implemented with a hash table | \n
| \n | java.util.Vector | \n Implements a dynamic array | \n
| \n | java.util.HashSet | \n Set based on a hash table | \n
| \n | java.util.Scanner | \n Captures user input | \n
| \n | java.util.regex.Pattern | \n Regular expressions | \n
| \n | java.util.regex.Macher | \n Regular expressions | \n
| IO/NIO | \njava.io.File | \n File and directory operations | \n
| \n | java.nio.file.Files | \n Utility class for file operations | \n
| \n | java.io.InputStream | \n Base class for byte streams | \n
| \n | java.io.OutputStream | \n Base class for byte streams | \n
| Multithreading | \njava.lang.Thread | \n Thread operation class | \n
| \n | java.util.concurrent.ExecutorService | \n Thread pool management | \n
| Date & Time | \njava.time.LocalDate | \n Date handling | \n
| \n | java.time.LocalDateTime | \n Date and time handling | \n
| \n | java.time.ZonedDateTime | \n Date and time with timezone | \n
| \n | java.util.Date | \n Current date | \n
| \n | java.text.SimpleDateFormat | \n Date/time formatting | \n
| \n | java.util.Calendar | \n Handles date and time | \n
| \n | java.util.GregorianCalendar | \n Implements the Gregorian calendar | \n
| \n | java.time.Instant | \n Represents an instantaneous point on the timeline | \n
| \n | java.time.ChronoUnit | \n Standard units for measuring time | \n
| \n | java.time.Period | \n Represents a time interval between two dates | \n
| \n | java.time.Duration | \n Represents a time-based duration (hours, minutes, seconds, nanoseconds) | \n
| Network Programming | \njava.net.URL | \n URL handling | \n
| \n | java.net.Socket | \n Socket programming | \n
\n\n
2. Common Third-Party Libraries
\nHere are widely used third-party libraries in the Java ecosystem:
\n\n| Category | \nLibrary Name | \nMain Function | \nOfficial Website | \n
|---|---|---|---|
| JSON Processing | \nJackson | \n JSON serialization/deserialization | \nhttps://github.com/FasterXML/jackson | \n
| \n | Gson | \n Google's JSON library | \nhttps://github.com/google/gson | \n
| Unit Testing | \nJUnit | \n Java unit testing framework | \nhttps://junit.org/junit5/ | \n
| \n | Mockito | \n Mock testing framework | \nhttps://site.mockito.org/ | \n
| Logging | \nLog4j | \n Logging framework | \nhttps://logging.apache.org/log4j/ | \n
| \n | SLF4J | \n Logging facade framework | \nhttps://www.slf4j.org/ | \n
| Web Development | \nSpring Framework | \n Enterprise application framework | \nhttps://spring.io/projects/spring-framework | \n
| \n | Spring Boot | \n Rapid application development framework | \nhttps://spring.io/projects/spring-boot | \n
| Database | \nHibernate | \n ORM framework | \nhttps://hibernate.org/ | \n
| \n | MyBatis | \n SQL mapping framework | \nhttps://mybatis.org/mybatis-3/ | \n
| Build Tools | \nMaven | \n Project build and dependency management | \nhttps://maven.apache.org/ | \n
| \n | Gradle | \n Flexible build tool | \nhttps://gradle.org/ | \n
\n\n
3. How to Choose the Right Library
\n\n3.1 Evaluation Criteria
\n- \n
- Functional Requirements: First, clarify what features the project needs \n
- Community Support: An active community means better support and documentation \n
- Performance: Requires special consideration for performance-sensitive applications \n
- Learning Curve: Consider the team's learning cost \n
- Maintenance Status: Check if the project is still actively maintained \n
3.2 Version Selection Recommendations
\n- \n
- Prioritize LTS (Long-Term Support) versions \n
- Avoid using versions that have reached end-of-life \n
- New projects can consider newer stable versions \n
\n\n
4. Usage Examples
\n\n4.1 Processing JSON with Jackson
\n\nExample
\nimport com.fasterxml.jackson.databind.ObjectMapper;\n\npublic class JsonExample {\n\npublic static void main(String[] args){\n\n ObjectMapper mapper =new ObjectMapper();\n\ntry{\n\n// Object to JSON\n\nString json = mapper.writeValueAsString(new User("Zhang San", 25));\n\nSystem.out.println(json);\n\n// JSON To Object\n\n User user = mapper.readValue(json, User.class);\n\nSystem.out.println(user);\n\n}catch(Exception e){\n\n e.printStackTrace();\n\n}\n\n}\n\n}\n\n4.2 Unit Testing with JUnit
\n\nExample
\nimport org.junit.jupiter.api.Test;\n\nimport static org.junit.jupiter.api.Assertions.*;\n\nclass CalculatorTest {\n\n @Test\n\nvoid testAdd(){\n\n Calculator calc =new Calculator();\n\n assertEquals(5, calc.add(2, 3));\n\n}\n\n}
YouTip