Below is a complete, structured explanation of the main built-in classes in Core Java, with what they do, where they belong, and simple examples 👇
🧩 1️⃣ java.lang — Fundamental Classes (Auto Imported)
Contains classes that are automatically imported in every Java program.
| Class | Description | Example |
Object | Superclass of all Java classes | toString(), equals(), hashCode() |
String | Immutable sequence of characters | "Hello".length() |
StringBuilder | Mutable string (non-synchronized) | new StringBuilder("Hi").append("!") |
StringBuffer | Mutable string (thread-safe) | new StringBuffer("Hi").append("!") |
Math | Mathematical functions | Math.sqrt(9) → 3 |
System | Access to system input/output and properties | System.out.println() |
Thread | For creating and managing threads | new Thread(runnable).start() |
Runnable | Interface for threading | public void run() |
Throwable, Exception, Error | Base classes for exception hierarchy | try { ... } catch(Exception e) |
Integer, Double, Float, Long, etc. | Wrapper classes for primitives | Integer.parseInt("10") |
Enum | Base type for all enumerations | enum Color {RED, BLUE} |
Class | Represents class metadata at runtime | obj.getClass() |
Package | Represents a Java package | Package p = obj.getClass().getPackage(); |
🧩 2️⃣ java.util — Utility and Collection Framework
Contains the Collection Framework, date/time, random number, and other helpers.
| Category | Important Classes | Description / Example |
| ✅ Collections | ArrayList, LinkedList, HashSet, TreeSet, HashMap, TreeMap, Vector, Stack | Store and manipulate groups of objects |
| ✅ Interfaces | Collection, List, Set, Map, Queue, Iterator, Iterable | Define collection types and traversal |
| ✅ Date/Time (old) | Date, Calendar, TimeZone | new Date() |
| ✅ Utility | Random, Scanner, Objects, Optional, Collections (class with static methods) | e.g., Collections.sort(list) |
| ✅ Properties & Resource | Properties, ResourceBundle | Store configuration or localization data |
Handles reading and writing data (files, streams).
| Class | Description / Example |
File | Represents a file or directory |
FileReader / FileWriter | Read/write character data |
BufferedReader / BufferedWriter | Efficient character I/O |
FileInputStream / FileOutputStream | Byte-level file handling |
ObjectInputStream / ObjectOutputStream | For serialization |
PrintStream | Easy output (used by System.out) |
InputStreamReader / OutputStreamWriter | Convert between bytes and characters |
🧩 4️⃣ java.nio — New I/O (Buffers & Channels)
More modern, faster I/O for files and networks.
| Class | Description |
Path | Represents file/directory path |
Files | Utility for file operations (Files.readAllLines()) |
ByteBuffer / CharBuffer | Buffers for data |
FileChannel | Channel-based file access |
StandardOpenOption | Options for opening files |
🧩 5️⃣ java.time — Modern Date and Time API (Java 8+)
More powerful and thread-safe date/time classes.
| Class | Description |
LocalDate, LocalTime, LocalDateTime | Represents date, time, and both |
ZonedDateTime | Date/time with time zone |
Period / Duration | Difference between dates/times |
DateTimeFormatter | Formatting/parsing dates |
🧩 6️⃣ java.math — High Precision Math
| Class | Description |
BigInteger | Integer of any size (arbitrary precision) |
BigDecimal | Decimal numbers with high precision (financial calculations) |
🧩 7️⃣ java.net — Networking
| Class | Description |
URL | Uniform Resource Locator (web link) |
URLConnection | Connection to a resource |
Socket / ServerSocket | Client/server socket programming |
InetAddress | Represents IP address |
🧩 8️⃣ java.sql — Database (JDBC)
| Class / Interface | Description |
DriverManager | Manages JDBC drivers |
Connection | Represents DB connection |
Statement | Execute SQL queries |
PreparedStatement | Precompiled queries |
ResultSet | Holds query results |
SQLException | Handles DB errors |
🧩 9️⃣ java.util.concurrent — Multithreading & Concurrency
| Class | Description |
ExecutorService | Manages threads efficiently |
Callable, Future | Return results from threads |
ReentrantLock | Advanced synchronization |
CountDownLatch, Semaphore, CyclicBarrier | Thread coordination tools |
ConcurrentHashMap | Thread-safe map |
🧩 🔟 java.awt & javax.swing — GUI (Graphical User Interface)
| Class | Description |
Frame, Button, Label, TextField | AWT basic UI components |
JFrame, JButton, JLabel, JPanel | Swing components |
EventListener | Handles UI events |
🧩 11️⃣ java.security — Security and Encryption
| Class | Description |
MessageDigest | Used for hashing (like SHA-256) |
KeyPair, Signature | Cryptography utilities |
SecureRandom | Generates secure random numbers |
🧩 12️⃣ java.lang.reflect — Reflection API
| Class | Description |
Class | Represents class metadata |
Method | Represents a class method |
Field | Represents class fields |
Constructor | Represents constructors |
Modifier | Access modifiers info |
🧩 13️⃣ java.util.regex — Regular Expressions
| Class | Description |
Pattern | Compiles regex |
Matcher | Matches regex patterns |
| Example | Pattern.matches("[a-z]+", "abc") |
| Class / Interface | Description |
Stream<T> | Represents sequence of elements |
Collectors | Used to collect results |
IntStream, LongStream, DoubleStream | Specialized streams |
| Example | list.stream().filter(x -> x>10).forEach(System.out::println); |
🧩 15️⃣ java.util.function — Functional Interfaces (Lambda Support)
| Interface | Description |
Function<T,R> | Takes one input, returns output |
Predicate<T> | Returns boolean result |
Consumer<T> | Consumes input, no return |
Supplier<T> | Returns a value, no input |
| Example | Predicate<Integer> p = n -> n > 10; |
⚡ Quick Summary Table
| Category | Package | Purpose |
| Core classes | java.lang | Fundamental classes |
| Collections | java.util | Data structures |
| File I/O | java.io | Read/write data |
| Date/Time | java.time | Modern time handling |
| Database | java.sql | JDBC |
| Network | java.net | Networking |
| Math | java.math | Precision math |
| Concurrency | java.util.concurrent | Multithreading |
| Regex | java.util.regex | Pattern matching |
| Streams | java.util.stream | Functional data processing |
| Functional | java.util.function | Lambdas and functional interfaces |
| Reflection | java.lang.reflect | Inspect classes at runtime |
| GUI | java.awt, javax.swing | User interface |
| Security | java.security | Encryption, hashing |