Shriansh Kumar has Published 324 Articles

Iterate TreeMap in Reverse Order in Java

Shriansh Kumar

Shriansh Kumar

Updated on 17-Apr-2025 10:48:26

1K+ Views

The TreeMap is a class of Java Collection Framework that implements NavigableMap Interface. It stores the elements of the map in a tree structure and provides an efficient alternative to store the key-value pairs in sorted order. In other words, it always returns the elements in ascending order. However, Java ... Read More

Java Program to check the beginning of a string

Shriansh Kumar

Shriansh Kumar

Updated on 17-Apr-2025 10:47:18

290 Views

You are given a String and your task is to find its beginning. Here, beginning means starting characters of the string up to a certain position. In Java, String is a class of java.lang package that represents a sequence of characters. These characters are enclosed within double quotes. ... Read More

Java Program to convert a String to int

Shriansh Kumar

Shriansh Kumar

Updated on 17-Apr-2025 10:42:52

478 Views

For a given String , our task is to write a Java program that converts it into an Integer. In Java, String is a class in java.lang package that stores a series of characters enclosed within double quotes. Integer is a primitive datatype that stores numerical values. Converting a String ... Read More

Java program to count words in a given string

Shriansh Kumar

Shriansh Kumar

Updated on 16-Apr-2025 19:40:29

33K+ Views

We are given a String and our task is to write Java programs that count its words. A string is a class in Java that stores a series of characters enclosed within double quotes. To count words of the given strings, check whether the character at the current index ... Read More

Can we overload or override a static method in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 16-Apr-2025 19:38:32

4K+ Views

In Java, you cannot override static methods but you can overload them. Overloading a static method is allowed because the JVM determines which method to call at compile time based on the method signature, rather than the object's type. However, overriding is not allowed for static methods because an overridden ... Read More

Can we inherit a final method in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 16-Apr-2025 19:07:50

926 Views

In Java, we cannot override a final method. Once a method is declared final, the Java compiler marks this method as non changeable. Therefore, behaviour of the final method will be the same throughout the application. Suppose you are building an payment application. There is a method that calculates transaction ... Read More

What are the differences between protected and default access specifiers in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 16-Apr-2025 18:59:58

11K+ Views

The protected and default access modifiers determine how a member of a class or method can be accessed. The modifiers are attached to the members at the time of declaration. Since Java follows the object-oriented programming paradigm, these access modifiers are used in encapsulation, polymorphism, and inheritance to control the ... Read More

Why multiple inheritance is not supported in Java

Shriansh Kumar

Shriansh Kumar

Updated on 14-Apr-2025 10:56:21

43K+ Views

Multiple inheritance is a type of inheritance where a single subclass inherits multiple superclasses. As the name suggests, inheritance is the ability of a class to inherit members of another class. The class whose properties are inherited is called a superclass, whereas the class that inherits a superclass is called ... Read More

Java program to compare two sets

Shriansh Kumar

Shriansh Kumar

Updated on 12-Apr-2025 16:31:57

2K+ Views

The given task is to write Java programs that compare two sets and check if they are equal or not. Here, Set is an interface of the Java Collection Framework that extends the Collection interface and stores unique elements. Set depicts the features of a mathematical set. Hence, it allows all ... Read More

How to Create Your Own Annotations in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 09-Apr-2025 19:35:54

826 Views

When we start learning Java, we often wonder about symbols like @override and @inherited. They are a special kind of tag termed as Annotations that can be applied to classes, methods, fields, parameters, and other elements of the code. Java provides support for some built-in annotations, however, we are allowed ... Read More

Advertisements