Monday, December 17, 2012

Whizlabs SCJP 6.0 Simulator "Error parsing question"

If you get an error message at the Whizlabs SCJP 6.0 Simulator saying "Error parsing question" at the start of an exame, ignore it and take the exame again.

If at the end of the exam, you have a message box that does not allow you to check you score, ignore it and go to the "Performance History". From there, you are able to check your score and review your questions.

Sunday, December 9, 2012

SCJP 6 Questions - Question 63

 class C {  
   public static void main ( String ka [ ] ) {  
     while ( false ) {  
       System.out.println ( "Value" ) ;  

What is the output?
1. compile time error
2. prints Value infinitely
3. Runtime Exception
4. None of the above

Thursday, September 27, 2012

SCJP/OCP Java 6 Resources

The Oracle Certified Professional (OCP), Java Standard Edition (SE) 6 Programmer certification is an entry-level credential that validates your skills in the Java programming language.

I'm studying for the SCJP 310-065 which stands for Sun Certified Java Programmer, for Java 6.0.
But, as you know, the Sun was bought by Oracle and the exam code has changed. Now, the official Oracle exam code is 1Z0-851: Java Standard Edition 6 Programmer Certified Professional Exam

I'm reading the Kathy Sierra and Bert Bates book SCJP Sun Certified Programmer for Java 6 Exam 310-065, from McGraw Hill,  and until now everything is clear as crystal - unless for some details that I don't work with in my daily job as a Java Programmer. But I'm learning all these details! From this book I recommend the "Two Minute Drill", that comes in the end of each chapter, that has all the details that you need to know from each chapter.

I also have the book OCP Java SE 6 Programmer Practice Exams (Exam 310-065) (Certification Press), also from Kathy Sierra and Bert Bates, for practicing (these are really hard exams!):

But... who are these two guys?
Why should I read and prepare with their books?

Kathy Sierra is a co-developer of the SCJP exam and Sun's practice exam. She is also a Sun Certified Java Instructor and the founder of the world's largest Java certification website,
Bert Bates is a Sun Certified Programmer for Java and has participated in the development of the SCJP exam and Sun's practice exam. He is the coauthor, with Kathy Sierra, of the previous editions of this book.

So, now you can see why these two books are very important for studying for the certification.

Besides these books, I intend to have some Mock Tests that are available online, before going to the exam:
Learning sources:
Schedule Exam at:
Other resources:


Thursday, July 26, 2012

Recuva - Undelete, Unerase, File and Disk Recovery

Recuva screenshot

There is an excellent freeware tool for recovering lost data called Recuva.
With this tool, you can recover accidentally deleted files, from your Windows computer for FREE!

It's simple and easy to use.

Wednesday, July 25, 2012

Are you looking for a Maven Repository? You've found it here!

A good Maven Repository, where artifacts can be searched, is
This site also shows the dependencies and the search also supports searching by description or group.

Thursday, June 7, 2012

Sonar or FindBugs Critical issue: Performance - Method concatenates strings using + in a loop

This issue arises when there is a String being built in a concatenation loop.
For each iteration, the String is converted to a StringBuffer/StringBuilder, appended to, and converted back to a String. This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.

Better performance can be obtained by using a StringBuffer (or StringBuilder in Java 1.5) explicitly.

For example:

// This is bad
String s = "";
for (int i = 0; i < field.length; ++i) {
   s = s + field[i];

// This is better - StringBuffer is synchronized
StringBuffer buf = new StringBuffer();
for (int i = 0; i < field.length; ++i) {
String s = buf.toString();

//Even better - better performance if synchronization is not an issue
StringBuilder builder = new StringBuilder();

for (int i = 0; i < field.length; ++i) {
String s = builder.toString(); 

Eclipse - Failed to load the JNI shared library

Eclipse started to fail during the opening of it, showing a pop-up window saying "Failed to load the JNI shared library". I did not know what was this and started to look on the web.

Eclipse failed to load the JNI shared library
Eclipse "Failed to Load the JNI shared library"

I've found out that this was a compatibility issue with jre/jdk 32 bit on a 64 bit machine.
I was running Eclipse 64 bit, with Windows 7 64 bit...
I remembered that I had installed a new software recently... and that installation added a jre 32 bit in the begining of my path. Due to this, Eclipse 64bit was being launched with a 32bit jre, causing that pop-up to appear.
Removed the jre 32 bit from the path, and then I was able to launch Eclipse again, like before!

Problem solved.

Wednesday, May 23, 2012

Sonar: Security - Array is stored directly

When we get this Sonar critical violation "Security - Array is stored directly", means that an array is being stored directly, e.g:

public void setInventoryClassId(String[] inventoryClassId) {
  this.inventoryClassId = inventoryClassId;

In order to solve this issue, we must do the following:

public void setInventoryClassId(String[] newInventoryClassId) {
  if(newInventoryClassId == null) {
    this.inventoryClassId = new String[0];
  } else {
   this.inventoryClassId = Arrays.copyOf(newInventoryClassId, newInventoryClassId.length);

Tuesday, May 22, 2012

Convert String to int

What is the best way to convert the String Object that represents a int value to the primitive type int? Just follow this suggestion, that takes advantage of the parseInt method of the Integer object:

String strValue = "1";
int intValue = Integer.parseInt(strValue);

Convert int to String

What is the best way to convert the primitive type int to a String object?

int intValue = 1;
String stringValue = Integer.toString(intValue);

Sunday, February 5, 2012


On the previous article, I've talked about AtomicInteger and AtomicLong.
Now I'm going to show you another Atomic object that can ben used independently of the type of the object, taking advantage of Java Generics: AtomicReference.
AtomicReference is also used for an object that may be updated atomically, but this time the object is generic.

Friday, February 3, 2012

AtomicInteger and AtomicLong

The most common usage for the AtomicInteger is for counters.
Before Java 5, counters had to be implemented by the usage of synchronized blocks, or methods, with volatile declaration for the counter (for multiprocessor good behavioring code).
The AtomicInteger is a Java 5 replacement for these two methods that must be used combined together in order to avoid race conditions and to have correct value propagation to memory, to make it available for all multiprocessor threads, joining the best of these two worlds.

Usage of the AtomicInteger as a counter:

public class Counter {
  private AtomicInteger count = new AtomicInteger(0);
  public void incrementCount() {
  public int getCount() {
    return count.get();

By the usage of the incrementAndGet, the operations read, increment and set of the value into memory are treated as an atomic operation, that cannot be interrupted by another thread.

The AtomicLong behaves exactly like the AtomicInteger, but for long values.