I recently was building an old application in eclipse and came across a hurdle while publishing my Spring MVC based java application on tomcat server. The error was nothing! That strange beacause tomcat was started in eclipse and in console it was showing server startup status. But when I hit localhost:8080 in my browser the … Continue reading Tomcat Started in Eclipse but showing Connection refused in browser – Error Solved!
Category: Java
Reversing a String: Java vs JavaScript vs Python
Reversing a String can be done in multiple ways, using functions, loops. Let us compare how it is done in Java, JavaScript and Python. Input: Hello, How are You? Output: ?uoY era woH ,olleH Java JavaScript Python
Dynamic String Conversion in JAVA
Input: 2B Output: 2000000000 Code : import java.math.BigDecimal; import java.util.Scanner; public class DyanamicConversion { public static void main(String args[]){ //Scanner scan = new Scanner(System.in); String a ="2M"; String[][] conversion = {{"K","1000"},{"M","1000000"},{"B","1000000000"}}; for(int i=0;i<conversion.length;i++){ if(a.endsWith(conversion[i][0])){ BigDecimal temp = new BigDecimal(a.substring(0, a.indexOf(conversion[i][0]))); temp.multiply(new BigDecimal(conversion[i][1])); a = temp.toBigInteger().toString(); System.out.println(a); break; } } } }
Sending HTTP GET Request to a REST API in JAVA
HTTP/HTTPS Get/Post request /response using JAVA below. For detailed visit here: https://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/ Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import javax.net.ssl.HttpsURLConnection; public class HttpURLConnection { public static void main(String[] args) throws IOException { String response = httpGet("https://services.groupkt.com/state/get/IND/all"); } public static String httpGet(String urlStr) throws IOException { URL obj = new URL(urlStr); HttpsURLConnection con … Continue reading Sending HTTP GET Request to a REST API in JAVA
Parsing JSON Output using JAVA
Use the JSONParser methods to parse a response that's returned from a call to an external service that is in JSON format, such as a JSON-encoded response of a Web service callout. Here is the code to parse the JSON string using JAVA: 1 2 3 4 5 6 7 8 9 10 11 12 … Continue reading Parsing JSON Output using JAVA