Top 10 useful classes in JAVA

Sanjeev Kumar Rai
3 min readApr 30, 2021

In Java everything is encapsulated under classes. Codes cannot exist outside of a class (JShell, Its Different) . I have listed here top 10 Java classes which are the part of JDK itself. These classes are popular and useful for programmers to write clean and maintainable code. I have personally found these classes are useful, choices may vary with other programmers experiences.

  1. java.util.Objects: This class consists of static utility methods for operating on objects. These utilities include null-safe or null-tolerant methods for computing the hash code of an object, returning a string for an object, and comparing two objects, and checking if indexes or sub-range values are out of bounds.
  2. java.util.Arrays: This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.
  3. java.nio.file.Files: The Java NIO Files class (java.nio.file.Files) provides several methods for manipulating files in the file system. This class consists exclusively of static methods that operate on files, directories, or other types of files.
  4. java.util.Stream: Classes to support functional-style operations on streams of elements, such as map-reduce transformations on collections.
  5. java.util.Optional: A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value. Additional methods that depend on the presence or absence of a contained value are provided, such as orElse() (return a default value if value not present) and ifPresent() (execute a block of code if the value is present).
  6. java.util.concurrent.Executors: The Concurrency API introduces the concept of an ExecutorService as a higher level replacement for working with threads directly. Executors are capable of running asynchronous tasks and typically manage a pool of threads, so we don’t have to create new threads manually. All threads of the internal pool will be reused under the hood for revenant tasks, so we can run as many concurrent tasks as we want throughout the life-cycle of our application with a single executor service.
  7. java.util.concurrent.CompletableFuture: CompletableFuture is used for asynchronous programming in Java. Asynchronous programming is a means of writing non-blocking code by running a task on a separate thread than the main application thread and notifying the main thread about its progress, completion or failure.
  8. java.lang.StringTokenizer: The string tokenizer class allows an application to break a string into tokens. The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis.
  9. java.lang.Class: Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.
  10. java.lang.Collections: This class consists exclusively of static methods that operate on or return Collections. It contains polymorphic algorithms that operate on collections, “wrappers”, which return a new collection backed by a specified collection, and a few other odds and ends.

feel free to add your favorites in comment section.

--

--