-
JAVA TUTORIALS ▼
-
BASICS OF JAVA ▶
- Java Overview
- Download and Install
- Java Object Class and Method
- Boolean Operator And Array
- Java Program to Find Greatest Number
- Singleton in Java
- Constructor Supper and This Keywords in Java
- Method Overloading in java
- Inheritance in java
- Method Overriding in java
- Polymorphism in Java
- Topic 1ab
- Topic 1ab
- ADVANCE JAVA ▶
- JAVA INTERVIEW QUESTIONS ▶
-
BASICS OF JAVA ▶
- Python Tutorials ▼
Free online Manual, Java, Selenium , API Testing tutorials for beginners
MainMenu
Home
Java Overview
Maven Tutorials
☰
Tuesday, 14 October 2025
Friday, 26 September 2025
Wednesday, 30 April 2025
Utility class in java
Utility class in Java:
A Utility Class in Java is a class that contains only static methods (and sometimes static variables) which perform common, reusable operations. These are often helper classes that group together functions used throughout your codebase, such as string manipulation, file I/O helpers, date-time operations, etc.
Characteristics of a Utility Class:
1). All methods are static
2). It is not meant to be instantiated.
3). Mark the constructor private to prevent object creation.
Example :
public final class MathUtils {
// Private constructor to prevent instantiation
private MathUtils() {
throw new UnsupportedOperationException("Utility class");
}
public static int add(int a, int b) {
return a + b;
}
public static int max(int a, int b) {
return a > b ? a : b;
}
}
Subscribe to:
Comments (Atom)