Exeptions and Errors in Java

In the diagram below I present the hierarchy of most common Exceptions and Errors:

 |_ Throwable
    |_ Error
    |   |
    |   |_ AssertionError
    |   |
    |   |_ LinkageError
    |   |   |
    |   |   |_ ExceptionInInitializerError
    |   |   |
    |   |   |_ NoClassDefFoundError
    |   |   |
    |   |_ VirtualMachineError
    |       |
    |       |_ StackOverflowError
    |_ Exception

Test your Java experience for free – JavaBlackBelt

Recently I’ve come across another very interesting social service – JavaBlackBelt. Basically it gathers programmers who use Java language and related frameworks and aspects (OO programming, JSP, Struts, JSF, EJB). There are even exams on C#, Ruby, JavaScript, and AJAX but some of them are still beta versions.

Of course I’ve taken a couple of exams and this is my …

What happens if concate String value and int?

Can you predict the output/result of the following code?

String s = "A String ";
s += 12345;

The answer is: “A String 12345“.

The reason for that is described in the desciption of String class in Java 2 Platform SE 5.0 API:

The Java language provides special support for the string concatenation operator ( + ),

C#, java

Java vs. C#

From now on I’ll be doing much more in Microsoft .NET rather than in Java. Thus, it seems my preparation for SCJP exam will slow down now… Also, I presume there’ll be slightly less about Java on that blog from now on (at least for some time).

I learned about .NET framework and C# programming language at the univesity, but …

Using PUT and DELETE methods in AJAX requests with prototype.js

Whenerver I write JavaScript I use prototype.js. I find it brilliant, especially when you deal with AJAX. With this library it’s easy to create an AJAX request and process its response from the server.

To send an AJAX request you create a following HTML code:

a link
$('ahref').onclick = function() {
    new Ajax.Request('/some_url', {
        onSuccess: function(transport){

Collection classes in Java

Collections are very important on SCJP exam. It’s useful to remember the following…



  • ordered (index)
  • duplicates allowed


  • fast iteration
  • fast random access; as of Java 1.4 implements RandomAccess interface
  • slower instertion and deletion


  • the same as ArrayList but its metods are synchronized (therefore slower)


  • elements are doubly linked to one another; linkage adds methods that allow

Assertions in Java

assert Expression1 : Expression2;
  • Expression1 is asserted to be true; otherwise AssertionError (that shouldn’t be handled) is thrown
  • Expression2 allows to produce some additional information
  • Expression2 MUST result in a value – it generates a String message
  • allow testing during the development and debugging
  • are disabled at runtime by default
  • can be enabled using -ea or -enableassertions flags and selectively

Threds: multiple call to run() method

You can call run() method of a thread many times. However, not a single new thread will be started. This way JVM will only execute the code from run() method. And this will not probably be what you tried to achieve.

Remember: to start a new thread, you need to call start() method, which among others, will execute run() method …

Java: main method declaration

It’s good to remember that there are a few ways of defining the main() method in Java 5:

public static void main(String[] args) {}


public static void main(String args[]) {}


public static void main(String... args) {}

Sometimes, we don’t care and remeber of basic stuff, which can result in worse score on the exam icon_smile-5323953