New classes added in Collections API for Java 1.6

June 6th, 2008 by Boogie

While going through Whizlab’s questions for Collections & Generics, I found quite a few of questions with NavigableSet, NavigableMap, ConcurrentSkipList, etc.

So I decided I will learn those also for the exam. A good way to start is this link:

http://www.javabeat.net/articles/4-what-is-new-in-java-60-collections-api-1.html

Posted in SCJP, IT | No Comments »

Generics understanding - very concise

June 3rd, 2008 by Boogie

You can find a very concise article about Java Generics on IBM’s website :

http://www.ibm.com/developerworks/library/j-jtp01255.html

 It explains quite nicely why Generics are the way they are. It touches type erasure, covariance, T type contructor, and others ( still reading :) ).

Posted in SCJP, IT | No Comments »

Date, numbers and currencies

April 21st, 2008 by Boogie

Some code snippets for constructing objects of Date, Calendar, DateFormat, NumberFormat, Locale:

Date d = null;

Calendar c = null; DateFormat df =

null;

out.println(“java.util.Date”);

out.println(“java.util.Calendar”);out.println(“java.text.DateFormat”);

 

NumberFormat nf = null;Locale l =

null;

out.println(“java.text.NumberFormat”);

out.println(“java.util.Locale”);

 

d = new Date();

//d = new Date(”2008-08-08″);// at Runtime produces IllegalArgumentException

out.println(“Date contructor With String argument is Deprecated”);

d = new Date(1123923842L);

out.println(“Date contructor With long argument is not deprecated”);

 

//c = new Calendar();// won’t compile

c = Calendar.getInstance();

//c = Calendar.getInstance(new Locale(”"));// at Runtime produces IllegalArgumentException

 

l = new Locale(“ro”);

l = new Locale(“xyzt”);// works, no runtime exception

out.println(“Because a Locale object is just an identifier for a region, \n” +

” no validity check is performed when you construct a Locale”);

l = new Locale(“ro”, “RO”);// language, country

l = new Locale(“ro”, “RO”, “XXX”);// language, country, variant - vendor and browser specific

 

//df = new DateFormat();// won’t compile

df = DateFormat.getInstance();

df = DateFormat.getDateInstance();

//df = DateFormat.getDateInstance(123L);// won’t compile

//df = DateFormat.getDateInstance(123);// at Runtime produces IllegalArgumentException

df = DateFormat.getTimeInstance();

df = DateFormat.getDateInstance(DateFormat.LONG);

df = DateFormat.getTimeInstance(DateFormat.SHORT);

df = DateFormat.getTimeInstance(DateFormat.SHORT, new Locale(“xyz”));// with Locale also

 

//nf = new NumberFormat();// does not compile

nf = NumberFormat.getInstance();

nf = NumberFormat.getNumberInstance();

nf = NumberFormat.getCurrencyInstance();

nf = NumberFormat.getInstance(new Locale(“ro”));

nf = NumberFormat.getNumberInstance(new Locale(“ro”));nf = NumberFormat.getCurrencyInstance(new Locale(“ro”));

Posted in SCJP | No Comments »

Flow control, exceptions and assertions

April 20th, 2008 by Boogie

I got a very low score on the test for flow control, exceptions and assertions. So now I am taking a better look on it and making some  small test programs.

I’m posting them below, maybe somebody else can find them useful.

You are free to use them for your own personal development, but note that all content on this site is copyrighted.

  • For statement

//for (int i = 1, int j = 1; true;){}// does not compile

 

for (int i = 1, j; i < 1;){i++;}// j is not initialized it’s OK, it is never used !!

 

for (int i = 1, j = 1; i < 1;){}

 

int a=2;

for (int i = 1, j = 1; a < 1;){}// the test can operate on different variables

 

for (int i = 1; i<1;);

 

for (int i = 1, j = 1; i < 1 ; out.println(“The increment part” + ” can do something else”)){}

 

for (;;)out.println(“All parts can be omitted!”);

  • Switch statement

byte b = 2;

switch (b){

case 1: break;

//case 128: break;// does not compile !

}

 

int c = 2;

switch (c){

case 1: break;

case 128: break;// OK

}

 

switch (5){// OK

case 1: break;case 128: break;

}

 

switch (5){

case 1: break;

//case 1: break;// does not compile !

}

 

switch (new Integer(5)){// OK

case 1: break;

}

 

switch (new Byte((byte)5)){// OK

case 1: break;

//case 128: break;// does not compile !

}

 

switch (5){

case 1: break;

case 5: out.println(“5 … & falling through”);

default: out.println(“not in here”);

case 6: out.println(“6″);}

  • While statement

//while (boolean b = false){}// does not compile, has to be declared before !

 

boolean b;while (b = false){}// OK

Posted in SCJP | No Comments »

Test results from SCJP for Java 5 Study Guide - first pass

April 17th, 2008 by Boogie

  

SCJP Sun Certified Programmer for Java 5 Study Guide is the book I am working with. I went through it once, made some annotations and did the tests at the end of each chapter.

 Here are the tests results:

chap I :        6 /  9            67 %    Declarations and access control

chap II :       6 / 14            43 %    Object Orientation

chap III :      7 / 14            50 %    Assignments

chap IV :     7 / 10            70 %    Operators

chap V :      5 / 16            31 %    Flow control, Exceptions & Assertions

chap VI :     3 / 15            20 %    Strings, I/O, Formatting & Parsing

chap VII :    3 / 16            18 %    Generics & Collections

chap VIII :   9 / 12            75 %     Inner Classes

chap IX :     8 / 17            47 %     Threads

Looks like I have to put serious work, the pass score for this exam is 65 % !

Posted in SCJP | No Comments »

On my way to SCJP 1.6

April 17th, 2008 by Boogie

SCJP or Sun Certified Java Programmer is an exam which certifies that the one holding it has a good understanding of the Java programming language. It is focused on the standard edition of Java and Sun’s specifications.

It is not an easy exam but by no means the one holding that certification can be considered a Java expert.

For me, acquiring this certification is a personal goal, something I’ve been puting aside for far too long.

Quick review of where I come from: I have always been involved with computers, programming mostly. Basic, QBasic, Pascal, C, Java, these were the main programming languages I’ve been working with over the years.

The first time I wanted to pass the SCJP I was student in my 4th year in the Computer Science Faculty. It was named SCJP 1.4 back then. Then I got employed, working in Java as a newbie. I convinced people at my company to order Kathy Sierra’s and Bert Bate’s book , for SCJP 1.5. ( version 5 had come out by then).

I went through that book and at after I read it all once I stopped, with some changes coming in my life.

Another two years passed and I decided it’s time.

About two months ago I started preparing for SCJP 1.6. I still have the 1.5 book SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) (Certification Press Study Guides), but I think I’ll manage only with this one.

My goal is that somewhere around the middle of May I want to be SCJP 1.6 . Currently I’m working on it.

Posted in SCJP | No Comments »