Coding, Q/A

Java Questions

Why Is Printing “B” Dramatically Slower Than Printing “#”?

I generated two matrices of 1000 x 1000: First Matrix: O and #. Second Matrix: O and B. Using the ...
Read More

Why Is Char[] Preferred Over String for Passwords?

In Swing, the password field has a getPassword() (returns char[]) method instead of the usual getText() (returns String) method. Similarly, ...
Read More

Creating a Memory Leak With Java

I just had an interview, and I was asked to create a memory leak with Java. Needless to say I ...
Read More

Read/convert an InputStream to a String

If you have java.io.InputStream object, how should you process that object and produce a String? Suppose I have an InputStream ...
Read More

Differences Between HashMap and Hashtable?

What are the differences between a HashMap and a Hashtable in Java? Which is more efficient for non-threaded applications? dmanxiii ...
Read More

Avoiding “!= Null” Statements in Java?

I work with Java all day long. The most used idiom (code snippet) I’m programming in Java, is to test ...
Read More

Is Java “Pass-by-Reference” or “Pass-by-Value”?

I always thought Java was pass-by-reference; however I’ve seen a couple of blog posts (for example, this blog) that claim ...
Read More

Why Is Subtracting These Two Times (In 1927) Giving a Strange Result?

If I run the following program, which parses two date strings referencing times one second apart and compares them: public ...
Read More

Java += operator

Until today I thought that for example: i += j; is just a shortcut for: i = i + j; ...
Read More

Why is processing a sorted array faster than an unsorted array?

Here is a piece of C++ code that seems very peculiar. For some strange reason, sorting the data miraculously makes ...
Read More

Subscribe now to receive more great content like this!