Define Multiple Methods with the Same Name in Java

Vivek Verma
Updated on 14-May-2025 13:11:32

8K+ Views

Yes, we can define multiple methods in a class with the same name. But if we have two methods with the same name, the compiler should be able to differentiate between the two methods. Therefore, in Java, "we can define multiple methods" with the same name in a single class, as long as each method has a different set of parameters. When we invoke a method, the compiler executes the respective body (code) based on the arguments passed.This concept is known as method overloading. Method Overloading in Java In Java, method overloading is a type of compile-time polymorphism. Polymorphism is one ... Read More

Sort a String Without Using Predefined Methods in Java

Vivek Verma
Updated on 14-May-2025 12:39:37

7K+ Views

The java.lang.String class represents an immutable sequence of characters and cannot be changed once created. We need to instantiate this class or assign values directly to its literal to create a string in Java. The String class does not provide any built-in method to sort the contents of a string. To sort a String, we need to convert it into a character array using the toCharArray() method and sort the array. To sort a character array, we can either use the Arrays.sort() method or use sorting algorithms.  Since the given task is to sort a string without using any predefined methods, we ... Read More

When to Call Thread.run Instead of Thread.start in Java

Vivek Verma
Updated on 14-May-2025 12:15:29

2K+ Views

This article will briefly discuss the run() and start() methods, and also explain when to call run() instead of the start() method. Calling run() Method Instead of start() Usually, to execute a thread, we will call the start() method, and the start method calls run() implicitly, and the contents of the run() method will be executed as a separate thread. We can also call the run() method explicitly instead of the start() method. If we do so, we will be executing the contents of the run method in the current thread but not in a separate one. In this case, the ... Read More

Print All Capital Letters of a Given String in Java

Vivek Verma
Updated on 14-May-2025 11:57:53

6K+ Views

The Character class is a subclass of the Object class, and it wraps a value of the primitive type char in an object. An object of type Character class contains a single field whose type is char. We can print all the capital letters of a given string using the following approaches - Using isUpperCase() Method Using ASCII Comparison Using isUpperCase() Method The isUpperCase() is the method of the Character class. It accepts a character as a parameter and returns true if it is an uppercase letter and false if not.To ... Read More

Check Memory Used by a Program in Java

Vivek Verma
Updated on 14-May-2025 11:18:07

3K+ Views

This article will discuss "how to check the memory used by a program" in Java, including a brief introduction of the process for calculation and an appropriate example that correctly checks the memory usage by the program. Understanding Memory Usage in Java Programs A Java code that takes a long time to execute, makes heavy use of dynamic memory. In such scenarios,  we may end up with Out-of-Memory errors (due to a memory shortage of the heap space). We can calculate the memory space (heap) used by a Java program using the methods provided by the Runtime class.If the heap space is ... Read More

Can Main Function Call Itself in C++?

Ravi Ranjan
Updated on 13-May-2025 19:34:44

2K+ Views

The main() function can call itself in C++. This is an example of recursion, i.e., a function calling itself. In recursion, a function calls itself over and over again with modified arguments until it reaches its base case or the termination condition, where the recursion stops. In this article, we will go through three C++ examples where the main function calls itself. Counting Numbers up to N To count numbers up to 'n', we will recursively call the main function until it reaches 'n'. Example The following example calls the main() function recursively to print the numbers from 1 ... Read More

Meaning of Prepended Double Colon in C++

Ravi Ranjan
Updated on 13-May-2025 19:34:31

8K+ Views

The prepended double colon (::) is also known as the scope resolution operator. The scope resolution operator serves various purposes in C++. In this article, we will discuss the applications of the scope resolution operator in C++ with example codes of each application. Uses of Scope Resolution Operator in C++ The scope resolution operator serves various purposes in C++. We have listed below 5 applications of the scope resolution operator: The scope resolution operator is used to define a function outside the class. It is used to access a global ... Read More

C++ Static Member Variables and Their Initialization

Ravi Ranjan
Updated on 13-May-2025 19:34:21

6K+ Views

The static member variables in C++ are defined using the static keyword. The static member variables in a class are shared by all the class objects as there is only one copy of them in memory, regardless of the number of objects of the class. All static data is initialized to zero when the first object is created, if no other initialization is present. In this article, we will understand the static member variables and their characteristics, and go through various examples explaining the characteristics of static member variables. The characteristics of the static keyword are mentioned below: Characteristics ... Read More

iswalnum Function in C++ STL

Farhan Muhamed
Updated on 13-May-2025 19:31:26

251 Views

The iswalnum() function is an extension of isalnum() function to support character identification of all languages. In this article, we will learn how to use the iswalnum() function from the Standard Template Library (STL) in C++. What is iswalnum()? The iswalnum() function is used to check whether a given wide character is alphanumeric. An alphanumeric character is either an alphabet letter (a-z, A-Z) or a digit (0-9). Wide character means, the larger set of characters, which include the characters from all the languages. The iswalnum() function returns true if the input character is either a letter from any language ... Read More

Implement Set Union in C++ using STL

Farhan Muhamed
Updated on 13-May-2025 19:31:14

751 Views

The Set Union is an operation used to find all elements that are present in either of the sets or in both. In this article, we will learn how to use the set_union algorithm from the Standard Template Library (STL) in C++ to find the union of two sets. What is Set Union? The set union is an arithmetic operation performed between two sets to find all elements that are present in either of the sets or in both. In C++, we have set_union which is a built-in algorithm provided by C++ STL that computes the union of two ... Read More

Advertisements