java
Java 8 LocalDateTime is parsing invalid datetime
You just need a strict ResolverStyle. Parsing a text string occurs in two phases. Phase 1 is a basic text parse according to the fields added to the builder. Phase 2 resolves the parsed field-value pairs into date and/or time objects. This style is used to control how phase 2, resolving, happens. Sample code – … Read more
Exception in thread “main” java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z
In addition to other solutions, Please download winutil.exe and hadoop.dll and add to $HADOOP_HOME/bin. It works for me. https://github.com/steveloughran/winutils/tree/master/hadoop-2.7.1/bin Note: I’m using hadoop-2.7.3 version
Integer.toString(int i) vs String.valueOf(int i) in Java
In String type we have several method valueOf static String valueOf(boolean b) static String valueOf(char c) static String valueOf(char[] data) static String valueOf(char[] data, int offset, int count) static String valueOf(double d) static String valueOf(float f) static String valueOf(int i) static String valueOf(long l) static String valueOf(Object obj) As we can see those method are … Read more
How to build JARs from IntelliJ IDEA properly?
Instructions: File -> Project Structure -> Project Settings -> Artifacts -> Click + (plus sign) -> Jar -> From modules with dependencies… Select a Main Class (the one with main() method) if you need to make the jar runnable. Select Extract to the target Jar Click OK Click Apply/OK The above sets the “skeleton” to … Read more
How can I unescape HTML character entities in Java?
I have used the Apache Commons StringEscapeUtils.unescapeHtml4() for this: Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.
How to clear the console using Java?
Since there are several answers here showing non-working code for Windows, here is a clarification: Runtime.getRuntime().exec(“cls”); This command does not work, for two reasons: There is no executable named cls.exe or cls.com in a standard Windows installation that could be invoked via Runtime.exec, as the well-known command cls is builtin to Windows’ command line interpreter. … Read more
Why is subtracting these two epoch-milli Times (in year 1927) giving a strange result?
It’s a time zone change on December 31st in Shanghai. See this page for details of 1927 in Shanghai. Basically at midnight at the end of 1927, the clocks went back 5 minutes and 52 seconds. So “1927-12-31 23:54:08” actually happened twice, and it looks like Java is parsing it as the later possible instant … Read more
Why don’t Java’s +=, -=, *=, /= compound assignment operators require casting long to int?
As always with these questions, the JLS holds the answer. In this case §15.26.2 Compound Assignment Operators. An extract: A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once. An example cited from §15.26.2 […] the following code is … Read more
How do I avoid checking for nulls in Java?
This to me sounds like a reasonably common problem that junior to intermediate developers tend to face at some point: they either don’t know or don’t trust the contracts they are participating in and defensively overcheck for nulls. Additionally, when writing their own code, they tend to rely on returning nulls to indicate something thus … Read more