Category: Java

  • SpotBugs Static Analysis Tool For Java Developers

    SpotBugs is a software tool for static analysis of Java programs, which is free to download, use,  open-source and can be used in various ways. It can be installed as Eclipse Plugin, configured with Maven build as plugin and Gradle builds as a plugin. It is very handy while being used as an Eclipse plugin […]

  • Best Way to Keep Java Code Clean and Organized Using Eclipse

    Eclipse IDE Java Editor Save Actions option should be used by all developers as it helps to keep code clean and organized. Eclipse is the most widely used IDE for Java programming as it provides a lot of features and it has the support of many free and paid plugins. Most important it is free […]

  • Merge Two list in Java in Efficient Way

    While doing development many times we need to merge two or more collections in Java. Sometimes we need simple concatenate two or more lists or sets or merge two or more lists by removing duplicates and sometimes we need to do this is sorted order. Here is one example to merge two lists, this can […]

  • Best way to remove duplicate items from ArrayList in Java

    Removing duplicate items from ArrayList in Java can be done in some very efficient ways using Java 8 or Guava lib for Java. Guava lib provides many efficient util classes to perform different operations on collections like creating, sorting, reversing, partitioning, etc. Removing duplicate using Guava API Here is the most efficient way to remove […]

  • Create, Partition and Reverse Array List Using Guava Lists

    Guava Lists is part of the Guava core java library. It is used to perform many frequently used operations on an array lists like creation, partition, reversal, and many more. Java Guava lib is collection of very safe and handy libs for working with collection types (such as list, multimap, bimap, and multiset), immutable collections, […]

  • Quickest way to append text to a file in Java

    In Java, there are several different ways to append text in a file. For file operations, Java provides several classes. To appending text quickly you can use Files class. Append text to file example: try { Files.write(Paths.get(“file1.txt”), “text to append”.getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { // To exception handling here } But above method […]

  • How does Java for-each loop works?

    Loops in programming languages used to iterate over collections like for loop, while .. do etc. In Java iterating over collections looks very ugly. Consider method in the following example which uses for loop to iterate over a collection. public static void main(String[] args) { List fruitList = new ArrayList(); fruitList.add(“mango”); fruitList.add(“banana”); fruitList.add(“apple”); printFruits(fruitList); } […]

  • Apache HttpClient with CookieStore (cookie support) in Java

    In java many time we need to make a request with cookies support. For example, if a REST service is configured to manage session using cookie session or cookie-based session key then we need to use HTTP client with cookie support. For this Apache HttpClient client provides HttpClientBuilder Class, CookieStore interface and BasicCookieStore. Using these […]

  • Manually Closing connection of Apache HttpClient in Java

    While Using Apache HttpClient library to make Http requests, we should always release connection immediately after completion of the operation. For making HttpRequest Apache HttpClient library provides CloseableHttpClient and CloseableHttpResponse classes which implements java closable interface. By calling the close method of a closeable object in finally block we can close or dispose of connection […]

  • Apache HttpClient Response Hadling in Java

    Apache HttpClient library provides the ResponseHandler interface. By implementing ResponseHandler you can handle HTTP responses in a clean way. Using the response handler is the recommended way of executing HTTP requests and processing HTTP responses. This approach of handling response enables the caller to concentrate on the process of digesting HTTP responses and to delegate […]