• 25 September

    List vs ArrayList in java

    In this post, we will see the difference between List and ArrayList in Java. List is an interface where ArrayList is concrete implementation, so List is more generic than ArrayList. You can instance an ArrayList in below two ways.You might have seen this code before. [crayon-662ae2b7d2e21996208614/] If you use 1st way, you can change the […]

  • 24 September

    How to convert List to Set in java

    In this post, we will see how to convert List to Set in java.We will convert ArrayList to HashSet. As HashSet does not allow duplicates, when you convert ArrayList to HashSet, all the duplicates will be discarded. You can simply use the constructor of HashSet to convert ArrayList to HashSet. [crayon-662ae2b7d4205170778397/] Here is simple example: […]

  • 24 September

    BigDecimal compareTo

    In this post,we will see about Bigdecimal‘s compareTo method.This method is used to compare two BigDecimals. Syntax [crayon-662ae2b7d43e1672457277/] Return type CompareTo method returns -1,0,1 -1 : First BigDeicmal is less than second BigDecimal 0 : First BigDecimal is equal to second BigDecimal 1 : First BigDecimal is greater than second BigDecimal BigDecimal CompareTo example Let’s […]

  • Java Runnable
    24 September

    Java Runnable example

    In this post, we will see Java Runnable example. As you might know, there are two ways of creating threads in java. Extending thread class Implementing Runnable interface. As you can extend only one class in java, it is not possible to extend any other class if a class extends thread class.You can also implement […]

  • 23 September

    How to invoke method using reflection in java

    In this post, we will see how to invoke the method using reflection in java. Let’s understand this with the help of the example. Create a class named Employee.java. We will invoke this class’s method using reflection. [crayon-662ae2b7d588d389448787/] Create a main method named EmployeeReflectionMain.java. [crayon-662ae2b7d5895340254148/] When you run above program, you will get below output: […]

  • 23 September

    Java Reflection tutorial

    Introduction Reflection, as we know from the common term, is an image of yourself or something else you see in a mirror or a mirrored surface. Java, being an object-oriented language draws heavily from real-life examples and so is the Reflection API of Java inspired from real life. In Java, the process of analyzing, viewing […]

  • 22 September

    Java program to Remove element from array

    In this post, we will see how to remove an element from array in java. Unlike Arraylist,Java Arrays class does not provide any direct method to add or delete element. As Array is fixed size in nature, you can not shrink or grow it dynamically. You need to create new array and copy all elements […]

  • 17 September

    Mockito Mock static method

    In this post, we will see about Mockito Mock static method. If you want to mock static methods, you need to use PowerMockito.PowerMockito is capable of testing private, final or static methods as it makes use of Java Reflection API. Let’s create a simple example to mock static method using powermockito. 1. Create a simple java […]

  • 17 September

    Mockito Mock Example

    In this lesson with Mockito, we will learn what is at the core of Mockito, which surprisingly is, mocks! Mock is an object that has predefined answers to method executions made during the test and has recorded expectations of these executions. Steps for creating Mockito TestNG example. Step 1: Create a simple java maven project. […]