I recently encountered an idiom I haven’t seen before: string assembly by StringWriter and PrintWriter. I mean, I know how to use them, but I’ve always used StringBuilder. Is there a concrete reason for preferring one over the other? The StringBuilder method seems much more natural to me, but is i…
Tag: java
String, StringBuffer, and StringBuilder
Please tell me a real time situation to compare String, StringBuffer, and StringBuilder? Answer Mutability Difference: String is immutable, if you try to alter their values, another object gets created, whereas StringBuffer and StringBuilder are mutable so they can change their values. Thread-Safety Differenc…
“java.lang.OutOfMemoryError: Java heap space” in image and array storage
I am currently working on an image processing demonstration in java (Applet). I am running into the problem where my arrays are too large and I am getting the “java.lang.OutOfMemoryError: Java heap space” error. The algorithm I run creates an NxD float array where: N is the number of pixel in the …
update attribute a element in arraylist on java?
I have a class extent fron class : Now in token i have arraylist token , i want to update attribute frequency of token in Texchunks when have more than one tokens same . For clearly a give a example : Texchunks :” in particular in domain and range in some ” So have 8 token : in,particular,in,domai…
How is a constructor executed?
I am making some revisions from the lecture slides and it says a constructor is executed in the following way: If the constructor starts with this, recursively execute the indicated constructor, then go to step 4. Invoke the explicitly or implicitly indicated superclass constructor (unless this class is java.…
How do I programmatically compile and instantiate a Java class?
I have the class name stored in a property file. I know that the classes store will implement IDynamicLoad. How do I instantiate the class dynamically? Right now I have Does the newInstance only load compiled .class files? How do I load a Java Class that is not compiled? Answer How do I load a Java Class that…
Why do people use bouncycastle instead of Java’s built in JCE provider? What is the difference?
Why do people use bouncycastle instead of Java Cryptography Extension? What is the difference? Answer BouncyCastle has many more cipher suites and algorithms than the default JCE provided by Sun. In addition to that, BouncyCastle has lots of utilities for reading arcane formats like PEM and ASN.1 that no sane…
Checking for a null int value from a Java ResultSet
In Java I’m trying to test for a null value, from a ResultSet, where the column is being cast to a primitive int type. From the code fragment above, is there a better way to do this, and I assume that the second wasNull() test is redundant? Educate us, and Thanks Answer The default for ResultSet.getInt …
How to extract CN from X509Certificate in Java?
I am using a SslServerSocket and client certificates and want to extract the CN from the SubjectDN from the client’s X509Certificate. At the moment I call cert.getSubjectX500Principal().getName() but this of course gives me the total formatted DN of the client. For some reason I am just interested in th…
Can we start the maven build from the point where it failed
Suppose, I am doing a full build on my large project which has 7 modules and on the 6th module, the build failed because a test failed. Is there any way by which I can start the build from the point …