Top 10 most commonly used Java classes
Here’s a list of the Top 10 most used Java classes (with short examples) — mainly from the java.lang, java.util, and java.io packages.
🧩 1. java.lang.String
Represents and manipulates text — used everywhere.
String name = "Sagar";
String greet = "Hello, " + name.toUpperCase();
System.out.println(greet); // Hello, SAGAR
✅ Common methods: substring(), replace(), split(), equals(), trim()
⚙️ 2. java.lang.Object
The root class of all Java classes — every class extends it.
✅ Common methods:
toString()equals(Object obj)hashCode()clone()getClass()
Example:
Object obj = new String("Java");
System.out.println(obj.getClass().getName()); // java.lang.String
🧮 3. java.util.ArrayList
Dynamic list — most used collection.
List<String> list = new ArrayList<>();
list.add("Java");
list.add("Python");
System.out.println(list.get(0)); // Java
✅ Common methods: add(), remove(), get(), size(), contains()
🔑 4. java.util.HashMap
Stores key–value pairs — used in caching, config, etc.
Map<String, Integer> map = new HashMap<>();
map.put("Apple", 3);
map.put("Banana", 5);
System.out.println(map.get("Apple")); // 3
✅ Common methods: put(), get(), containsKey(), keySet()
📅 5. java.time.LocalDate / LocalDateTime
Represents dates and times (Java 8+).
LocalDate today = LocalDate.now();
LocalDate nextWeek = today.plusDays(7);
System.out.println(nextWeek);
✅ Common methods: now(), plusDays(), minusDays(), isBefore(), format()
📦 6. java.util.Collections
Utility class for working with collections.
List<Integer> nums = Arrays.asList(3, 1, 2);
Collections.sort(nums);
System.out.println(nums); // [1, 2, 3]
✅ Common methods: sort(), reverse(), shuffle(), max(), min(), unmodifiableList()
🧾 7. java.lang.Exception
Base class for all exceptions — core for error handling.
try {
int x = 10 / 0;
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
✅ Derived classes: IOException, NullPointerException, ArithmeticException, SQLException
🧠 8. java.util.Scanner
Used for input (especially in console programs).
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
String name = sc.nextLine();
System.out.println("Hello, " + name);
✅ Common methods: nextInt(), nextLine(), hasNext()
⚡ 9. java.lang.Thread
Used to create and manage threads.
Thread t = new Thread(() -> System.out.println("Running thread"));
t.start();
✅ Common methods: start(), join(), sleep(), isAlive()
💾 10. java.io.File
Represents files and directories.
File file = new File("data.txt");
System.out.println(file.exists());
✅ Common methods: exists(), createNewFile(), delete(), listFiles(), getAbsolutePath()
💡 Bonus frequently used classes:
| Class | Purpose |
|---|---|
StringBuilder | Efficient string manipulation |
Arrays | Utility for array operations |
HashSet | Unique element collection |
Optional | Handle null safely |
System | For I/O and system-level utilities |
Stream | Functional programming and data processing |
FileInputStream / BufferedReader | File reading |
Logger / LogManager | Logging |
| ExecutorService (Thread Pooling) | Manages multiple threads efficiently — avoids creating new threads each time. |
| CompletableFuture (Async Programming) | For building asynchronous, non-blocking tasks with callbacks. |