How to make a singleton enum in Java?

Vivek Verma
Updated on 23-Jun-2025 12:13:12

3K+ Views

In Java, an enum is a special class used to represent a group of constants (that cannot be changed, like a final variable), such as Days: SUNDAY, MONDAY, TUESDAY, etc. Following is the syntax to create an Enum class in Java: enum ClassName { VALUE1, VALUE2, VALUE3, // ... VALUEN; } Where, enum is a reserved keyword in Java used to define an enum class, ClassName is the name of the enum, and VALUE1, VALUE2, VALUE3, ..., VALUEN are the ... Read More

How to read the data from a properties file in Java?

Vivek Verma
Updated on 23-Jun-2025 11:31:51

34K+ Views

Java supports file-handling; it provides various classes that provide various methods to read, write, update, and delete data from files in our local system. A properties file is a simple text file with a ".properties" extension that contains configuration data in the form of key-value pairs. It is mostly used in Java applications to manage settings such as database configuration, application messages, or environment variables. How to read Data from a Properties File in Java? To read data from the properties file, you can use the Properties class in Java. This is a subclass of the Hashtable class and it represents a persistent ... Read More

Importance of wait(), notify() and notifyAll() methods in Java?

Vivek Verma
Updated on 23-Jun-2025 11:05:39

16K+ Views

The threads can communicate with each other through wait(), notify(), and notifyAll() methods in Java. These are the final methods defined in the Object class and can be called only from within a synchronized context. The wait() method causes the current thread to wait until another thread invokes the notify() or notifyAll() methods for that object. These methods will throw an IllegalMonitorStateException if the current thread is not the owner of the object's monitor. The wait() Method In Java, the wait() method of the Object class allows threads to pause their execution and wait for a specific condition to be ... Read More

How can we get the name of the Enum constant in Java?

Vivek Verma
Updated on 23-Jun-2025 10:59:28

6K+ Views

In Java, an Enum is a class or special datatype that defines a collection of constants. It was introduced in Java version 1.5. When we need a predefined list of values that do not represent numeric or textual data, we can use an Enum class. Enums are constants, which means their fields are implicitly public, static, and final by default. The names of enum constants are written in uppercase letters. Following is the syntax to create an Enum in Java: Enum enumName{ CONST_VALUE1, CONST_VALUE2, CONST_VALUE3....CONST_VALUEN; } Retrieving Name of the Enum Constant The java.lang.Enum class provides various methods ... Read More

How To Check Whether a Number is a Mersenne Number or Not in Java?

Vivek Verma
Updated on 23-Jun-2025 10:40:19

2K+ Views

What is a Mersenne Number? A Mersenne number is a positive integer that is obtained using the expression M(n)= 2n-1, where 'n' is an integer. If you keep any value of n (e.g., 0, 1, 2, 3) in the above expression, the result will be a Mersenne number. For example, consider n = 2 and calculate the expression 22 - 1. The result is 3, which is a Mersenne number. Not all Mersenne numbers are prime (e.g., 24 - 1 = 15) is a mersenne number, which is not prime. Here are some other examples of Mersenne numbers: ... Read More

Add Two Numbers in Python

gireesha Devara
Updated on 20-Jun-2025 19:37:53

3K+ Views

Adding two numbers in Python is one of the most basic tasks, where we need to combine their values to get a total. In this article, we will see different ways to add two numbers in Python. Using Arithmetic Operator To add two numerical values in Python, we can use the addition operation, represented by the "+" symbol. It is one of the arithmetic operators in Python that performs the addition operation. Example Here is the basic example that adds the two numbers using the addition operator (+). # Assign values to the variables a = 7 b = ... Read More

How to copy files from one server to another using Python?

Niharikaa Aitam
Updated on 20-Jun-2025 19:31:03

9K+ Views

Transferring files from one server to another is a most common task in system administration, DevOps and development workflows. The tools such as scp and rsync are used for the file transfer. Python provides different methods and tools to transfer the files from one server to another using a third party libraries such as paramiko and SCPClient. Using Paramiko and SCP for Secure Transfers When we want to copy files securely from one server to another using Python, we can use the libraries Paramiko and SCPClient together. Paramiko is a Python library that helps to implement SSHv2 protocol. This is ... Read More

Check if both halves of the string have same set of characters in Python

Niharikaa Aitam
Updated on 20-Jun-2025 19:29:52

324 Views

In Python, a string is one of the data structures that is a sequence of characters enclosed within single quotes '' or double quotes "". It is immutable, i.e., once a string is created, it cannot be changed. When we want to check if both halves of the string have the same set of characters in Python, we can follow the steps below - First, based on the length of the string, we have to split the string into two halves. Next, convert each half into a set of characters using set() function. Finally, compare the two sets using ... Read More

Basic calculator program using Python program

Niharikaa Aitam
Updated on 20-Jun-2025 19:27:44

1K+ Views

In this tutorial, we are going to build a basic calculator in Python. As we all know that a calculator will give six options to the user from which they select one option and we will perform the respective operation. Following are the arithmetic operations that we can perform using a basic calculator - Addition Subtraction Multiplication Division Floor Division Modulo Steps in Developing the Basic Calculator Following are the steps involved in creating a basic calculator in Python - Defining Arithmetic Functions First, we are defining all the arithmetic operations that can be performed by using a ... Read More

Generate two output strings depending upon occurrence of character in input string in Python

Niharikaa Aitam
Updated on 20-Jun-2025 19:19:22

152 Views

In Python, a string is one of the data structures that is a sequence of characters enclosed within single quotes '' or double quotes "". It is immutable, i.e., once a string is created, it cannot be changed. When we want to generate two output strings based on character occurrence in Python, we have to follow the steps below - First, we need to initialize a dictionary or use the collections.Counter class to count the frequency of each character in the input string. Next, we have to go through the input ... Read More

Advertisements