Saturday, January 21, 2012

Quick way to join array of String in Java without third party libraries

As you probably know Java SE doesn't include such useful method as String join. Even old good JavaScript has this nice method:
JavaScript join() Method
Definition and Usage
The join() method joins all elements of an array into a string, and returns the string. The elements will be separated by a specified separator. The default separator is comma (,).
How to implement the similar stuff in Java SE? The easiest what came to my head is:
 /**
  * Join String arguments into one String separated by comma (",")
  * @param args input Strings
  * @return joined String
  */
 public static String join(String... args) {
  if(args.length <1) throw new IllegalArgumentException();
  
  String joined = Arrays.toString(args);
  String result = joined.substring(1, joined.length()-1);
  return result;
 }
Usage is pretty trivial:
import static com.blogspot.HalypHUtils.join;

...

String joinedString = join("Banana", "Orange", "Apple", "Mango");
And as you've already noticed this join uses comma (",") separator only.

Monday, January 09, 2012

What is the best book for SCJP/OCPJP exam preparation?

There are two major books for the exam preparation:


SCJP Sun Certified Programmer for Java 6 Exam 310-065, by Katherine Sierra, Bert Bates


A Programmer's Guide to Java SCJP Certification: A Comprehensive Primer (3rd Edition), by Khalid Mughal, Rolf Rasmussen

I've read both books and must admit that "SCJP Sun Certified Programmer for Java 6 Exam 310-065, by Katherine Sierra" is the best. You can also have a look into

OCP Java SE 6 Programmer Practice Exams (Exam 310-065) (Certification Press), by Bert Bates, Katherine Sierra
I can say it's like a companion book there are a plenty of nice mock exam questions.

I can say that you shouldn't use "A Programmer's Guide to Java SCJP Certification: A Comprehensive Primer (3rd Edition), by Khalid Mughal, Rolf Rasmussen" because:
  • there too many unnecessary info which is totally useless on exam
  • book written style isn't perfect, it's really hard to follow the main idea
  • explanation of some ideas is very complex and bloated, it can be simplified
  • book typographic style is really ugly in comparison with "SCJP Sun Certified Programmer for Java 6 Exam 310-065, by Katherine Sierra" 
Your can simplify your exam preparation if you stick to one book. Keep in mind your goal is optimize the exam preparation and avoid the redundant reading.