Using Java 1) Using StringBuffer class In this method, we use reverse() method of StringBuffer class to reverse the string. Here is the code snippet to reverse the string using reverse() method of StringBuffer class. 2) Using iterative methodIn this method, first we convert given string to char array using charArray() method. And then we …
Continue reading program to reverse a stringUncategorized
annotation @JsonInclude of Jackson library which helps in eliminating default, null, empty, etc values. For this post, we will focus on default values. Suppose we have an Employee POJO as below:- It may not be mandatory to pass values to all fields in a payload. For example, a “gender” field may be optional and you …
Continue reading @JsonInclude Annotation – Ignore Default Values In PayloadStatic members of a class When we use a “static” modifier with the declaration of a member of a class is called a static member of that class. It is also called a class member. We can use static with a variable, method, inner class, and blocks. Static members are associated with the class, not with …
Continue reading Reason for Static Import In RestAssuredUsing Java To find the number of occurrences of each character in a given string, we have used HashMap with character as a key and it’s occurrences as a value. First, we convert the given string to char array and check each character one by one. And update it’s count in HashMap.
Continue reading How To Count Occurrences Of Each Character In StringUsing Java Split the given inputString into words using split() method. Then take each individual word, reverse it and append to reverseString. Finally print reverseString. Below image shows code snippet of the same.
Continue reading How To Reverse Each Word Of A StringUsing Java calculate power of a number using for loop Here number is the base and p is the power (exponent). So we are calculating the result of number^p calculate power of a number using pow() function
Continue reading Program to Calculate Power of a NumberWhen JVM starts up, it creates a heap area which is known as runtime data area. This is where all the objects (instances of class) are stored. Since this area is limited, it is required to manage this area efficiently by removing the objects that are no longer in use. The process of removing unused …
Continue reading Garbage Collection in Javafinal keyword can be used along with variables, methods and classes. 1) final variable final variables are nothing but constants. We cannot change the value of a final variable once it is initialized. Lets have a look at the below code: Note: It is considered as a good practice to have constant names in UPPER …
Continue reading Final Keyword In JavaA class that is declared using “abstract” keyword is known as abstract class. It can have abstract methods(methods without body) as well as concrete methods (regular methods with body). A normal class(non-abstract class) cannot have abstract methods. An abstract class can not be instantiated, which means you are not allowed to create an object of …
Continue reading Abstract Class in JavaPolymorphism is one of the OOPs feature that allows us to perform a single action in different ways. For example, lets say we have a class Animal that has a method sound(). Since this is a generic class so we can’t give it a implementation like: Roar, Meow, Oink etc. We had to give a …
Continue reading Polymorphism in Java