Comments¶
String is a immutable class in Java. Extensive operations on strings (e.g.,
+in a big loop) is usually very slow before Java 7 (the+operator is optimized by the compiler automatically starting from Java 7). To avoid this problem (in older versions of Java), you can use theStringBuilder
BufferedReader in Java IO
Comemnt¶
- The methods
BufferedRead.readLineandBufferedRead.linesare very helpful for reading text Files.
public String BufferedRead.readLine¶
Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
public Stream\<String> BufferedRead.lines¶
Returns a Stream, the elements of which are lines read from this BufferedReader. The Stream is lazily populated, i.e., read only occurs during the terminal stream operation. The reader must not be operated on during the execution of the terminal stream operation. Otherwise, the result of the terminal stream operation is undefined.
Assert in Java
- Avoid using
assertin Java production code as assertion is not turned on by default. Throw exception instead (since assert is just a syntax sugar of throwing exceptions).
The most important thing to remember about assertions is that they can be disabled, so never assume they'll be executed.
Therefore keep the followings things in mind when using assertions:
Exceptions in Java
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
-
You can suppress warnings of unchecked exceptions by using
SuppressWarnings("unchecked")but generally speaking, you cannot suppress warnings of checked exceptions.
-
You can use more than one
catchblocks if necessary …
Get Resources in Java
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
-
getResourceandgetResourceAsStreamtries to find files in theresourcesdirectory undersrc/main/resourcesorsrc/test/resources(depending on whether you are running the application or tests for the …
A JNI Error Has Occured
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Error Messages
Error: A JNI error has occurred, please check your installation and try again
Caused by: java.lang.ClassNotFoundException: org.apache.spark.sql.SparkSession
Cause
Some dependencies (Spark in this …