Differences between C++, Java and C#
Wednesday 4 April 2007 @ 9:04 pm

Bjarne Stroupstrup, the inventor of the C++ programming language, has an interesting technical FAQ about C++. He has an example in the FAQ that inspired me to try this out in C++, Java and C#. Have a look at the following C++ code. What do you think this prints?

(NOTE: The C++ code looks a bit weird. I had to replace the angle brackets with ‘[’ and ‘]’ because the WordPress editor does not let me enter angle brackets properly, even if I edit the HTML code manually…).

 

 #include [iostream]   // NOTE: Use angle brackets here

class Super {
public:
    void method(int i) {
        std::cout [[ "method(int): " [[ i [[ std::endl; // NOTE: Use angle brackets here
    }
};

class Sub : public Super {
public:
    void method(double d) {
        std::cout [[ "method(double): " [[ d [[ std::endl; // NOTE: Use angle brackets here
    }
};

int main(int argc, char* argv[]) {
    Sub obj;

    // Which method is called for each of these statements, the int or the double version?
    obj.method(10);
    obj.method(3.2);

    return 0;
} 

Here is the Java version. What do you think this prints? Do you think Java works the same as C++ or not?

 

 class Super {
    public void method(int i) {
        System.out.println("method(int): " + i);
    }
}

class Sub extends Super {
    public void method(double d) {
        System.out.println("method(double): " + d);
    }
}

public class Main {
    public static void main(String[] args) {
        Sub obj = new Sub();

        // Which method is called for each of these statements, the int or the double version?
        obj.method(10);
        obj.method(3.2);
    }
} 

And lastly the C# version. What do you think - does C# work the C++ or the Java way, or is it the same - or different?

 

 namespace Example {
    class Super {
        public void method(int i) {
            System.Console.WriteLine("method(int): " + i);
        }
    }

    class Sub : Super {
        public void method(double d) {
            System.Console.WriteLine("method(double): " + d);
        }
    }

    class Program {
        static void Main(string[] args) {
            Sub obj = new Sub();

            // Which method is called for each of these statements, the int or the double version?
            obj.method(10);
            obj.method(3.2);
        }
    }
} 
— By Jesper de Jong   Comments (3)   PermaLink
Having fun with Spring AOP
Thursday 24 August 2006 @ 1:46 pm
Filed under:

Aspect Oriented Programming for me always has been something that is theoretically beautiful but in practice unfeasible to apply: A good idea that buried itself by bad examples and complex implementations. Until Google pointed me to this great article about AspectJ5 and its integration into the Spring Framework. Actually I was looking for some EJB3 related Spring material but I ended up reading probably one of the first articles that after finishing left me with a ‘yep, I really want to do AOP, even at home’-kind of feelings.

The whole idea is actually super simple. AspectJ has been extended with two very handy mechanisms: a run time (actually load time) weaving engine and support for aspects that are expressed in Java 5 annotations. Using AspectJ’s API we do not have to rely on a separate compiler but the process of aspect weaving can be initiated whenever we like. And that is exactly the trick Spring is using. Aspects are actually Spring managed instantiations that influence other spring managed beans. When Spring is loading bean classes, cross cutting aspects are weaved in like a breeze.So, I grabbed the latest Spring release (2.0), read some more background information and started right away. Within minutes an AspectJ based interception of a completely meaningless but spring managed hello world bean was up and running. Cool! Hello world never has been so enlighting. To make things a bit more practical, I tried to implement a typical architectural constraint like “Methods on classes belonging to the an applications data access layer may only be called through methods of classes belong to the service layer.”. Normally this constraint is written down by software designers in a plain ms-word or odf ‘thou shall not’-document,  but using Spring AOP it can be expressed in a bit of xml (yep, Spring ….) and a Java class. ( I am not going to argue the semantic practicalities and implications of this constraint, for me it is just an example to express the ‘aha feeling’.) Okay, here are some interesting pieces of the class I wrote. Full details can be found in this posts attachment (acsa.zip). @Aspect public class SystemLayeringAspect { // ……define the pointcuts to identify different layers @Pointcut(”within(com.logicacmg..*.service.*)”) public void inServiceLayer() { }@Pointcut(”within(com.logicacmg..*.dao.*)”) public void inDataLayer() { }

add some thread local sugar for administrative purpose private static ThreadLocal tlServiceCount = new ThreadLocal() {  protected Integer initialValue() { return 0; }

};

define the advice to register the usage of service method calls@Around(”inServiceLayer()”)public Object serviceUsage(ProceedingJoinPoint thisJoinPoint) throws Throwable {

  tlServiceCount.set(tlServiceCount.get() + 1);

  Object result = thisJoinPoint.proceed();

  tlServiceCount.set(tlServiceCount.get() - 1);

  return result;

}

and define the advice how to deal with data access calls @Before(”inDataLayer() && this(dao)”)public void dataUsage(Object dao) throws Throwable {

  if (tlServiceCount.get() == 0) {

    throw new ArchitecturalConstraintFailed(dao + ” can not be accessed directly”);

  }

}

Note, the difference in the advice types. The service advice needs to work around the actual method call, the dao advice does its job only upfront.That’s it. simply plug it into your Spring application context after the and off you go.  ApplicationContext context = new ClassPathXmlApplicationContext(”application-context.xml”);
ExampleService service = (ExampleService) context.getBean(”helloService”);
ExampleHelper helper = (ExampleHelper) context.getBean(”helloHelper”);

ExampleService service = (ExampleService) context.getBean(”helloService”);

ExampleHelper helper = (ExampleHelper) context.getBean(”helloHelper”);

 

service.doSomething();

try {  helper.helpABit();

} catch (ArchitecturalConstraintFailed afailed) {

  System.out.println(”yep catched ” + afailed);

}

In the example used to test the architectural constraint, a dao is called through a helper bean. Calling the helper directly will result in a runtime failure, calling it through the service is no problem. Seems aspect orientation has finally been made easy. Although, one should be aware of the behaviour that aspects are honoured only by java classes that are loaded through Spring. So be careful with the new operator. But besides that, all I can advice is to have fun and make good use of it.  

 

— By Okke van 't Verlaat   Comments (3)   PermaLink
Java podcasts
Wednesday 12 July 2006 @ 8:40 am

I have a new lease car. Like many other people, I have to go through the traffic jams that block up the highways here in the Netherlands every morning and every evening.I often listen to the radio while I’m in the car. The CD player in my new car has written “mp3″ on it with small letters - it can play MP3 files from CD-ROMs. This gave me an idea: I should find out how podcasting works, I could find some interesting podcasts, put them on a CD and listen to them while I’m in the car.

Podcasting works with RSS news feeds. The news messages in the RSS feed contain links to audio files. You can use a program like Juice to subscribe to RSS feeds and download the audio files, which you can then listen to on your computer, put on your MP3 player or on a CD.

So now I wanted to find some interesting podcasts. This article on O’Reilly’s OnJava website has links to some podcasts about Java.

So far I’ve downloaded a few of the podcasts from Java Posse (RSS podcast feed). There were a few interesting interviews, one with the product manager of Google who is responsible for the Google Web Toolkit, and one with some of the guys on the Swing team at Sun. They were talking about Aerith, a cool Swing demo program that they showed on JavaOne to demonstrate that you can make great looking applications with Swing (although it wasn’t easy to make a program like Aerith).

EclipseZone currently has a series of podcasts about the Eclipse Callisto release - it’s a series of ten podcasts, in which they’re interviewing people from each of the ten projects that are in Callisto.

If you know any other interesting podcasts, let me know!

— By Jesper de Jong   Comments (4)   PermaLink
Using Java could lead to death
Monday 2 January 2006 @ 5:12 pm

We all know that Microsoft doesn’t like Java. But did you know that Microsoft in their license agreement even warns users that Java technology is potentially deadly?

Yakov Fain discovered this when he was reading a Microsoft end-user license agreement:

The software product may contain support for programs written in Java. Java technology is not fault tolerant and is not designed, manufactured, or intended for use or resale as on-line control equipment in hazardous environments requiring fail-safe performance, such as in the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, direct life support machines , or weapon systems, in which the failure of Java technology could lead directly to death, personal injury, or severe physical or environmental damage.

See also the article on TheServerSide, one of the major J2EE community websites.

— By Jesper de Jong   Comments (10)   PermaLink
Results of the JavaPolis Rad Race
Thursday 15 December 2005 @ 12:23 pm
Filed under:

JavaPolisI am happy to announce that two of my fellow employees (from LogicaCMG) have entered and won the Rad Race at the JavaPolis. Congratulations go towards Pascal Alma and Pascal Prins who entered the contest with a toolbox filled with Oracle goodies. (Oracle JDeveloper, JHeadstart and ADF etc)

It is fair enough to mention that there are 2 other teams that have received the 1st price so congratulations also to the teams from Axi and Oracle.

It is interesting to see that 2 out of 3 winners have made it with the use of a Oracle product stack. Is this coincedence?

More details can be found on the website of JavaPolis.

— By Marco Pas   Comments (3)   PermaLink
Gates warns of ‘disruptive’ changes
Wednesday 9 November 2005 @ 8:24 pm
Filed under:

Today a memo from Bill Gates himself spread across the Internet. It talks about competitors that challenge Microsoft in the so called ‘online service’ age. Earlier memo’s from former Groove chief Ray Ozzie, talk about missed opportunities for Microsoft. Companies like Google, Adobe, Yahoo and Skype have met the growing need of speed, simplicity and loose coupling. In these
area’s Microsoft has not yet used its full potential and it is necessary to do this as it will change business as we know!

Some examples of missed opportunities:

  • Microsoft LiveMicrosoft knew that searching would be very important, but through Google’s focus they have gained a strong position despite the efforts of Microsoft.
  • Microsoft should dominate the AJAX space for their effort in OWA (Outlook Web Access), but again small players with more focus are in control.

Microsoft has a lot of opportunities if it can create a common succesfull service’s platform. The first efforts already look promising as Microsoft Live and Office Live have been announced and for some parts already are implemented.

We all like Microsoft bashing (why :? ) make sure and take a closer look, these guys are really putting out some nice stuff. Innovation is driven by companies and individuals with a strong focus. So let us focus on Java technology and keep innovating :) Maybe we will be ready to implement our own services! See you all in the service age :!:

>> Read the full article

— By Marco Pas   Comments (2)   PermaLink
Goodbye Palm Operating System?
Tuesday 27 September 2005 @ 9:34 am
Filed under:

Palm Has Designs on Microsoft Mobile

Palm Logo In a major shift in the PDA industry, Palm (Quote, Chart) is expected to announce today that its Treo 700 smartphone will be powered by the Microsoft (Quote, Chart) mobile operating system.

Palm President and CEO Ed Colligan, Microsoft Chairman and Chief Software Architect Bill Gates and Verizon Wireless CEO Denny Strigl are expected to make it official during a noon news conference at The Palace Hotel in San Francisco.

Read the full article here

— By Marco Pas   Comments (3)   PermaLink

Menu


Blog Categories

Browse by Date
September 2007
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930

Upcoming Events

Monthly Archives

Recent Comments

Links


XML Feeds Option


Get Firefox  Powered by WordPress

code validations
Valid RSS 2.0  Valid Atom 0.3
Valid W3C XHTML 1.0  Valid W3C CSS