Browsed by
Category: Java

okhttpclient get/post/form requests example:

okhttpclient get/post/form requests example:

okhttpclient get/post/form requests example: Maven dependency: <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>3.11.0</version> </dependency> okhttpclient with formbody example: public class App { public static void main( String[] args ) throws IOException { OkHttpClient client = new OkHttpClient(); RequestBody formBody = new FormBody.Builder() .add("client_id", "some_value") .add("client_secret", "some_value") .build(); Request request = new Request.Builder() .url("some_url") .post(formBody) .addHeader("authorization", "headers_here") .addHeader("cache-control", "no-cache") .build(); Response response = client.newCall(request).execute(); System.out.println("response => "+response); } }   okhttpclient with multipart form data request example: public class App { public static void…

Read More Read More

742 total views, no views today

Trim() not working with excel read apache poi in Java:

Trim() not working with excel read apache poi in Java:

Trim() not working with excel read apache poi in Java: While reading from the excel, you need to make sure you are considering this unicode value as well \u00A0 along with white spaces to handle all the possible inputs. Trim() does not help us for this, and below are the tries I made and got the solution, posted all here to help you with n number of possible use cases and solutions. Not working: Try 1: row.getCell(0).getStringCellValue().replaceAll("\u00A0", "");   Try 2:…

Read More Read More

750 total views, 2 views today

[Solved] The entity “le” was referenced, but not declared.’ itext pdf

[Solved] The entity “le” was referenced, but not declared.’ itext pdf

[Solved] The entity “le” was referenced, but not declared.’ Issue: If you used &le; then you will get this issue. Solution: You have to actually use &lt;=, currently it does not support &le; this can be done as &lt;= Hope this helps! 878 total views, no views today

878 total views, no views today

How to create a text/html file from java string ?

How to create a text/html file from java string ?

How to create a text/html file from java string ? try { File file = new File("ngd.txt"); // ngd.html for html file generation. FileWriter fileWriter = new FileWriter(file); fileWriter.write(html); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } 690 total views, no views today

690 total views, no views today

Arraylist to Array Using ToArray() in java

Arraylist to Array Using ToArray() in java

Syntax: <T> T[] toArray(T[] a) Eg : String[] y = x.toArray(new String[0]); T – the runtime type of the array to contain the collection Parameters: a – the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose. Returns: an array containing the elements of this list Throws: ArrayStoreException – if the runtime type of the specified array is not a…

Read More Read More

1,278 total views, no views today

hashMap Vs TreeMap Vs LinkedHashMap

hashMap Vs TreeMap Vs LinkedHashMap

════════════╦═════════════════════╦═══════════════════╦═════════════════════╗ ║ Property ║ HashMap ║ TreeMap ║ LinkedHashMap ║ ╠══════════════╬═════════════════════╬═══════════════════╬═════════════════════╣ ║ Iteration ║ no guarantee order ║ sorted according ║ ║ ║ Order ║ will remain constant║ to the natural ║ insertion-order ║ ║ ║ over time ║ ordering ║ ║ ╠══════════════╬═════════════════════╬═══════════════════╬═════════════════════╣ ║ Get/put ║ ║ ║ ║ ║ remove ║ O(1) ║ O(log(n)) ║ O(1) ║ ║ containsKey ║ ║ ║ ║ ╠══════════════╬═════════════════════╬═══════════════════╬═════════════════════╣ ║ ║ ║ NavigableMap ║ ║ ║ Interfaces ║ Map ║ Map ║ Map ║…

Read More Read More

1,227 total views, 4 views today

Why StringBuffer/StringBuilder should be avoided in HashMap?

Why StringBuffer/StringBuilder should be avoided in HashMap?

Why StringBuffer/StringBuilder should be avoided in HashMap?   This is one of the core java interview question under collections category. Generally in all the map manipulations we use string and avoid stringbuffer and stringbuilders, because both are mutable. What is the issue if is mutable ? If you are keeping your hashmap’s key/value as stringbuilder/stringbuffer then once after you inserted the value in the map, if any of the key/value modified then it actually affects inside the map as well,…

Read More Read More

743 total views, no views today

Generate angular + Java code using yeoman & Jhipster

Generate angular + Java code using yeoman & Jhipster

Generate angular + Java code using yeoman & Jhipster Ensure you have installed yeoman (yo when dealing with npm and yarn) and jhipster (generator-jhipster when dealing with npm and yarn). If not installed, have a quick look at,     Step 1: Run yo jhipster     It will ask around 10 to 15 questions, you can provide the sample values as per the above screenshot and proceed to step 2:   Step 2: Angular 5 & Java Codes are…

Read More Read More

982 total views, 1 views today

Core Java Programming Interview Questions

Core Java Programming Interview Questions

Core Java Programming Interview Questions: All these below are purely java programming interview questions collected from different attendees and different companies. Walk through all the programming questions and try to figure it out before checking the answers below.   Basics:   1.What is the output ? package in.javadomain; class Basics { public static void main(String[] args) { System.out.println("I am main method" + new Basics()); } Basics() { System.out.println("I am construtor!"); } }   Output: [plain] I am construtor! I am…

Read More Read More

733 total views, no views today

Java program to check whether the String is Pangram or Not

Java program to check whether the String is Pangram or Not

Java program to check whether the String is Pangram or Not: What is Pangram ? If a given sentence has all the alphabets then it is a valid pangram.   If the below sentence is given as input then it has to return “Pangram” The quick brown fox jumps over the lazy dog   If the below sentence is given as input then it has to return “Not a Pangram” The quick brown fox jumps over the dog Pseudo code…

Read More Read More

1,116 total views, no views today