Let’s learn program to find area of rectangle using inheritance in java. Program to find area of rectangle using inheritance in java We can calculate area of rectangle using inheritance. Here’s an example. class RectangleDimension { int length; int breadth; } class Rectangle extends RectangleDimension { int area; void findArea() { area = length *…

Read More Program to find area of rectangle using inheritance in java

Let’s learn java program to find area of circle and rectangle using interface. Java program to find area of circle and rectangle using interface We can use interface to calculate area of circle and rectangle. Here’s java program. interface FindArea { double pi = 3.14159265359; double calculate(double a, double b); } class Rectangle implements FindArea…

Read More Java program to find area of circle and rectangle using interface

Let’s learn java program to calculate area of circle rectangle and triangle using switch statement. Java program to calculate area of circle rectangle and triangle using switch statement We can use switch statement to calculate area of circle, rectangle and triangle. import java.util.Scanner; public class FindAreaUsingSwitchStatement { public static void main(String[] args) { Scanner sc…

Read More Java program to calculate area of circle rectangle and triangle using switch

Let’s learn to swap three variables in java without using temporary variable. swap three variables in java without using temporary variable In the below example we are using arithmetic operators to swap three variables without using temporary variable. public class SwapThreeNumbersWithoutTemp { static int num1, num2, num3; public static void main(String[] args) { num1 =…

Read More swap three variables in java without using temporary variable

Let’s learn how to convert string to date in Java 8. How to convert string to date in Java 8 Let’s see example in converting String to Date using LocalDate class and DateTimeFormatter class in Java 8. Syntax: LocalDate ld = LocalDate.parse(date, formatter); parse() method returns the parsed local date, not null. Let’s see convert…

Read More How to convert string to date in Java 8

Let’s learn difference between hashset and treeset in java. Difference between hashset and treeset in java HashSet TreeSet hashset do not maintain any order. sorted according to natural order. If not use compareTo() method. uses equals() method for comparison. uses compareTo() method for ordering two objects. hashset is implemented using HashTable. TreeSet is implemented using…

Read More Difference between hashset and treeset in java

Let’s learn how to sort treeset in descending order in java. How to sort treeset in descending order in java In this post lets sort treeset elements in descending order or decreasing order. For this we are using descendingSet() method. This method returns a reverse order view of the elements contained in this set. import…

Read More How to sort treeset in descending order in java