More than a year ago i decided to do the Sun Certified Java Programmer. Shortly after i bought this book, the projects at work and at home were somewhat overwhelming and after all, i realized that a big part of the SCJP is about some weird, crazy and sometimes wrong design decisions of the Java language. Some of them i mentioned under this tag.
Last month i realized i had some spare time, signed up at Prometric and had a 2nd look at the book and on my good Java experience from the last 6 years.
First thing: The “Java 5 Study Guide” isn’t a bad book but the “MasterExam” software on the enclosed cd is a master piece of crap. Not only the gui is as shitty as it gets but some of the answers are just plain wrong.
Second thing: I bought the preparation kit from Whizlabs for 50€. This thing isn’t bad at all and helps you get prepared for the craziness thrown at you.
Third: Being good at something is always great
It rocks, really. Like single trail riding or music with electric guitars while driving open. It’s like drugs but not that unhealthy.
After about 2 weeks of preparing, I arrived 30 minutes early at “New Horizons” in Cologne, took the test certainly in english as i prepared with english material and finished somewhat 50 minutes later (you have officially around 3 hours to take the test). The nice proctor asked me if i wanted to use the toilet as she saw my report being printed: 90%, pass! Wooot!
I thought about this post at Jans. I really like the guy who wins a million dollars at Who wants to be a Millionaire and has the guts to call his dad but not ask for help and instead tells him he is going to win a million dollars. I can totally relate to that as i always had fun taking test and scoring at the upper limit
So today i’m gonna eat an extra portion of Cookies & Cream and leave you with the following piece of Java madness:
More…
Share This
Some days i ago, i decided to revamp my ambitions to get the scjp thingy done. What exactly for, i don’t know. But working to the self tests, i found the following:
class Ring {
final static int x2 = 7;
final static Integer x4 = 8;
public static void main(String[] args) {
Integer x1 = 5;
String s = "a";
if(x1 < 9) s += "b";
switch(x1) {
case 5: s += "c";
case x2: s += "d";
case x4: s += "e";
}
System.out.println(s);
}
}
Questions is: Some arbitrary output or a compilation error and if, on which line.
Answer: Compilation fails due an error on line 11. What the frag? The obviously totally retarded switch statement can only handle constant values in its branches. So what? x4 is declared final static, as constant as it can be in Java. But no… Because its a big difference between int and Integer and due to the auto boxing and unboxing in Java 5 and up, the object Integer isn’t constant opposed to the scalar int.
Summary: A big deal with the SCJP is to teach the contestants how to work around some brain dead things in Java. Don’t get me wrong, i actually like Java, but the more i do in Ruby and the likes, the more some concepts in Java seem and are just wrong, like the for example not being all things equally objects.
Share This
Someone must be hit really hard with some curly braces when he implemented the following behaviour:
public class Braindead {
public static void main(String[] args) {
Integer i1 = 10;
Integer i2 = 10;
Integer i3 = 128;
Integer i4 = 128;
compare(i1, i2);
compare(20, 20);
compare(i3, i4);
}
public static void compare(Integer i1, Integer i2) {
System.out.println("Comparing " + i1 + " and " + i2);
if(i1 == i2)
System.out.print("same ");
else
System.out.print("different ");
System.out.println("Objects");
if(!i1.equals(i2))
System.out.print("not ");
System.out.println("meaningfully equal");
System.out.println("---");
}
}
I’d expect the following output:
Comparing 10 and 10
different Objects
meaningfully equal
---
Comparing 20 and 20
different Objects
meaningfully equal
---
Comparing 128 and 128
different Objects
meaningfully equal
---
What you get is:
Comparing 10 and 10
same Objects
meaningfully equal
---
Comparing 20 and 20
same Objects
meaningfully equal
---
Comparing 128 and 128
different Objects
meaningfully equal
---
In order to save memory, two instances of the following wrapper objects will always be == when their primitive values are the same:
- Boolean
- Byte
- Character from \u0000 to \u007f
- Short and Integer from -128 to 127
So in order to save a handfull of bytes we present you some really inconvenient feature
Share This
So then, to generate some pressure:
Let’s get the party started…
Edit:
Just realized, that one of my new domains doesn’t work as java package name, damn it…
Just memorize: Valid identifiers starts with a connecting or text character, have no operator signs in them and are no keywords.
Share This