Archive

What happens if concate String value and int?

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

String s = "A String ";
s += 12345;
System.out.print(s);

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 ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

Unreachable catch block

Always contruct try-catch blocks in a way that assumes catching Exceptions from more detailed to more generic.

Example

try {
    String [] tab = null;
    System.out.println(tab[3]);
} catch (Exception e) {
    System.out.println(”Exception”);
} catch (NullPointerException e) {
    System.out.println(”NullPointerException”);
}

The above presented snippet will cause compilation error:

Unreachable catch block for NullPointerException. It is already handled by the catch block for Exception

Solution

try {
    String [] tab = null;
    System.out.println(tab[3]);
} catch (NullPointerException e) {
    System.out.println(”NullPointerException”);
} catch (Exception e) {
    System.out.println(”Exception”);
}

This way, if you invoke this snippet you’ll get the following output on the screen: “NullPointerException”.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

AJAX Control Toolkit - Could not load file or assembly vjslib

I wanted to play around with ASP.NET AJAX Control Toolkit. There are a few steps to do before you can start using this tool. Among others, you need to build the Visual Studio Solution provided in the downloaded zip file.

When I tried to build the solution I got this error:

Error 1 Could not load file or assembly ‘vjslib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified. C:\Program Files\Microsoft ASP.NET\Ajax Control Toolkit\TemplateVSI\TemplateVSI.csproj 60 5 TemplateVSI

Solution

This is what AJAX Control Toolkit documentation says:

The TemplateVSI project has a dependency on vjslib.dll which is a part of the Visual J# Redistributable…

The above mentioned package can be found there. Installing it solved this problem, at least on my computer.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

Create a report with Reporting Services

If you want to create a report in 5 mins, you should follow this tutorial.

All requirement software can be found there. I installed the following:

The tutorial instructs you how to create the report (RDL file): how to define the data source, layout and how to preview the report.

Once you’re done, you can use Report Manager to deploy the report. In my environment Report Manager is available at http://localhost/Reports$SQLExpress and looks as below:

Report Manager

It is possible that Report Manager is available at a different URL on your machine. To check the URL go to Control Panel\Administrative Tools, then Internet Information Services (this is how to get this screen under Windows XP). On the window you get expand Internet Information Services\XXX (local computer)\Web Sites\Default Web Sites. You should see anything that is similar to Reports and ReportServer. As I described before, in my case those virtual directories were named with $SQLExpress suffix at the end.

Anyway, once you get to the Report Manger, click Upload File button. In the new screen choose the file to upload (RDL file you’ve created with the tutorial). Then in main screen of Report Manager select the report you’ve added. Now you should see the report. As the ouput is long, it is paginated so you can use Previuos Page and Next Page buttons to show different parts of the report. You can also choose the format in which the report is presented; by default you can view it in the following formats:

  • embedded in the website
  • PDF file
  • Excel file

That’s all. Now you can create any report you want.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

ASP.NET powered with AJAX

For those who develop web applications in ASP.NET and want to learn how to include AJAX I recommend a series of video tutorial on ASP.NET AJAX.

The series is created (from time to time new videos are added) by Joe Stagner and others from the Microsoft product team. It teaches the basic tricks and explanations of how things should be done.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

What if you extend an abstract class and implement an interface when both define a method with the same name?

Imagine you need to implement a class that extends an abstract class and implements an interface when both define a method with the same name - test().

Example


interface Implementable { public void test(); }
abstract class Superclass { public abstract void test(); }

public class Test extends Superclass implements Implementable {
    /* definition of load method(s)..... */
}

The following will not compile, getting (among others) duplicate method test() error:


interface Implementable { public void test(); }
abstract class Superclass { public abstract void test(); }

public class Test extends Superclass implements Implementable {
    public void Superclass.test() { }
    public void Implementable.test() { }
}

Solution

The correct implementation looks as follows:


interface Implementable { public void test(); }
abstract class Superclass { public abstract void test(); }

public class Test extends Superclass implements Implementable {
    public void test() { }
}

In such case, you need to define the body of test() method ONLY ONCE.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

Refreshing C# and ASP.NET skills

As a matter of fact I’ve been learning Java (for SCJP) and Microsoft .NET (because of project change) recently.

This week I attended two crash courses:

Those courses were fine; I refreshed a lot and learned some new stuff as well. Now it’s time to play around with this knowledge in real world ;)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

CV updated

I’ve updated my CV:see English or Polish version.
Appart from that, I’ve updated my LinkedIn profile.

It’s very up to date now. Feel free to read it if you’re interested :)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

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 it was a few years ago. Also, I’ve never been involved in a business project that used this framework. So, time to refresh the knowledge of .NET :)

Luckily, it seems there shouldn’t be much difficulties in switching from Java to C#. Of course, those languages differ but still they have a lot in common. This article should be helpful in understanding the differences between Java and C#. It’s well written and the theory is supported with code examples.

After refreshing C# there will be time to re-learn ASP.NET…

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail

MyBlogLog

I’ve just signed up to MyBlogLog service.

Look at my profile and my blog’s profile on MyBlogLog.
Continue reading ‘MyBlogLog’

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • bodytext
  • Technorati
  • Reddit
  • StumbleUpon
  • description
  • Wykop
  • Gwar
  • e-mail