Simplest way to read JSON from a URL in Java

This might be a dumb question but what is the simplest way to read and parse JSON from URL in Java? In Groovy, it’s a matter of few lines of code. Java examples that I find are ridiculously long (and have huge exception handling block). All I want to do is to read the content … Read more

How to fix “error: bad operand types for binary operator ‘||’ ” in java

To answer your question about the while loop condition directly (are the two conditions equivalent?): No, they aren’t equivalent, but it’s only a small change needed. The following two conditions are equivalent by DeMorgan’s Law. So basically you have to add a ! before your second while loop condition to make them equivalent (assuming it really was a … Read more

Java double.MAX_VALUE?

Double.MAX_VALUE is the maximum value a double can represent (somewhere around 1.7*10^308). This should end in some calculation problems, if you try to subtract the maximum possible value of a data type. Even though when you are dealing with money you should never use floating point values especially while rounding this can cause problems (you will … Read more

What does Scanner input = new Scanner(System.in) actually mean?

Alright, let’s elaborate with some simplified explanation about the Scanner class. It is a standard Oracle class which you can use by calling the import java.util.Scanner. So let’s make a basic example of the class: Now when you call Scanner input = new Scanner(System.in); you make a new object of the Scanner class (so you make a new “Scanner”) and you store … Read more

What is the default initialization of an array in Java?

Everything in a Java program not explicitly set to something by the programmer, is initialized to a zero value. For references (anything that holds an object) that is null. For int/short/byte/long that is a 0. For float/double that is a 0.0 For booleans that is a false. For char that is the null character ‘\u0000’ (whose decimal equivalent is 0). When … Read more

Difference between a HashMap and a dictionary ADT

In terms of Java, both the class HashMap and the class Dictionary are implementations of the “Map” abstract data type. Abstract data types are not specific to any one programming language, and the Map ADT can also be known as a Hash, or a Dictionary, or an Associative Array (others at http://en.wikipedia.org/wiki/Associative_array). (Notice we’re making a distinction between the Dictionary class and the Dictionary … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)