Maruthi Krishna has Published 870 Articles

Why do we get ClassNotFoundException when the class exists in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 24-Apr-2025 15:30:50

4K+ Views

Whenever we try to load a class, ClassNotFoundException occurs when the application tries to load a class at runtime using methods like Class.forName() or ClassLoader.loadClass(), but the JVM cannot locate the class in the classpath. The following are the reasons of ClassNotFoundException occurence and they are - ... Read More

Can we change method signature in overriding in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 24-Apr-2025 12:34:06

2K+ Views

No, you cannot change the method signature while overriding. Changing the method signature becomes method overloading, not overriding. Now, let's understand why - Method Signature In Java, a method signature consists of - Method name: It ... Read More

Difference between constants and final variables in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 24-Apr-2025 11:00:25

13K+ Views

In Java, both constants and final variables are used to define variables that cannot be changed after initialization. But they have some differences. In this article, we will learn how they are different. Final Variable A final variable in Java means you cannot reassign it after it has been initialized. ... Read More

Can we override only one method while implementing Java interface?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:31:34

1K+ Views

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or make a contract specifying how the methods and fields of a type should be, you can define an interface. When a class implements an interface, it should provide concrete implementations for all ... Read More

How to Sort a String in Java alphabetically in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:29:01

90K+ Views

Sorting a string alphabetically means rearranging its characters in order, from A to Z. For example, the string "java" becomes "aajv" after sorting. Different ways to sort a String Alphabetically There are two ways to do this in Java using different approaches - ... Read More

In how many ways you can retrieve the elements of a collection in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:25:46

3K+ Views

In Java, the collections framework provides various classes like ArrayList, HashSet, and LinkedList to store groups of elements. But once data is stored, how do you access or retrieve it? Java provides multiple ways to retrieve elements from collections, depending on whether you're reading values, modifying them during traversal, or iterating forward ... Read More

How many ways are there to convert an Array to ArrayList in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:23:59

351 Views

When working with collections in Java, you might need to convert an array to an ArrayList. This is useful because ArrayList offers more flexibility, such as dynamic sizing and built-in methods for adding, removing, and searching elements. Need for Converting an Array to an ArrayList Arrays in Java have a ... Read More

Remove all non-alphabetical characters of a String in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Apr-2025 11:22:42

2K+ Views

When you are working with strings in Java, you may want to keep only the alphabetic characters (A-Z, a-z) and remove everything else, like numbers, punctuation, and symbols. Java gives you multiple ways to do this for different cases or scenarios. Removing non-alphabetical characters from a string There are ... Read More

Why can\\\'t a Java class be both abstract and final?

Maruthi Krishna

Maruthi Krishna

Updated on 21-Apr-2025 16:24:01

3K+ Views

In Java, both abstract and final are class modifiers but they are completely opposite to each other. That's why Java class cannot be both abstract and final. Abstract class An abstract class in Java is a class that may contain both abstract methods (without implementation) and concrete methods (with ... Read More

How to run a JAR file through command prompt in java?

Maruthi Krishna

Maruthi Krishna

Updated on 21-Apr-2025 15:21:33

4K+ Views

A JAR file is like a ZIP file but for Java code. For the packaging of multiple class files, Java provides a file format known as JAR (Java Archive). Typically, a JAR file contains .class files, images, text files, and libraries in a single file that are required to execute the ... Read More

Advertisements