[KDE Dot News]
 faq
 flatforty
 contribute
 subscribe
 configure
 search
 rdf

 main


  Java Mania: An Interview With Richard Dale
Interviews Posted by Richard Moore on Tuesday 27/Feb/2001, @13:57
from the caffeinated-kde dept.
One of the most fascinating aspects of KDE is the speed with which new developments occur after each release. KDE 2.1 came out yesterday, and was celebrated in the traditional manner by adding lots of new features to the KDE development tree in CVS. For me, one of the most exciting things to arrive was a very large commit to the kdebindings module (used for bindings between KDE's C++ code and other programing languages) which added bindings for the KDE and Qt libraries to the well known Java language. The author of the code, Richard Dale, has kindly agreed to answer some questions so that readers of the Dot can get up to speed with this new addition to KDE.

1. What do QtJava and KDEJava actually do?

They wrap most of the classes in Qt and KDE so that they can be used to write Java programs, which look and behave identically to a C++ version. The Qt date, time, string and list classes are replaced with their Java equivalents.

2. What would you say are the best features of the binding?

It uses KDOC as the parser engine, so it has access to the documentation comments of the KDE methods. It translates these comments into Javadoc format, and has a go at translating the code snippets into 'cod java' - ie C++ with those funny symbols like '&', '*', '::' (that you never quite mastered ;-) ) replaced with java style '.'s.

3. What made you decide to write this, and how long did it take?

I wrote some code to patch KDevelop and KDOC 1.0 to use Objective-C for gnustep development in late 1999. After I'd done that, someone posted a question to comp.lang.objective-c asking about whether there were any Objective-C bindings for Qt. I thought that if I could do some bindings, I'd have a really nice complete Objective-C programming environment.

I started using Roberto Alsina's QtC for the C bindings and shell scripts for the Objective-C side (you can't call C++ directly from Objective-C, so you have to do two sets of bindings). I completed a prototype version good enough to run Qt Scribble in Objective-C in about 3 months. But the work was very labour intensive and I couldn't see how I could manage to get the whole Qt/KDE api done.

I wrote a patch to add Objective-C support to kdoc 2.0, so I got familiar with the Perl code. Mathieu Chouinard emailed me asking about how work on the Objective-C bindings was going. I told him I'd started to hack Roberto's Python scripts, but it was still taking a lot of work to get anything wrapped. Then it occured to me that it would be easier to make KDOC generate the same code as the python stuff, than it would be to make the Python parse as well as KDOC. After two months (less time than the prototype took), we had two KDOC-based converters, for C and Objective-C, for Qt 2.2 wrapped and working, and I was about to start on KDE 2.0.

But once I realised I could the same thing for Java/JNI at the end of October or so, I just downed tools on Objective-C and ran for it. Er.. 24 by 7. I haven't still been programming when the birds start singing since late 1988 or so! I got Qt 2.2 done before Christmas, then had six weeks off starting again in February. So KDE 2.0 has taken a bit less than a month to get this far.

Probably about a man year of 40 hour weeks for C/Objective-C/Java in total.

4. Who do you think will find this code most useful?

One group might be those people who would like to write apps with full Qt or KDE look and feel, but prefer to code in Java over C++ (because it's quicker). Another group might be those taking existing Java code and wrapping it to get a fully functional KDE app. A third group might use the Qt side to write apps which will run cross-platform, both on standard Wintel PC's (a port to Windows should be straightforward) and Linux, *BSD, etc.

5. How much of the Qt and KDE APIs have you covered?

280 Qt classes and over 400 KDE classes - pretty complete.

6. How hard do you think it will be to extend the binding to cover the new features in KDE 2.1?

The manual edits applied to get the bindings working are in the form of a patch. So the KDE 2.1 headers need to be put through the converter, then the patch applied. Finally, the diffs added to the KDE CVS since the initial check-in must be applied, and any essential new 2.1 classes added to the project.

7. How does the signal/slot mechanism of Qt translate into Java?

Here is an example of how to connect a signal to a slot in QtJava:

 QObject.connect( _colormenu,
                  SIGNAL( "activated( int )" ),
                  this,
                  SLOT( "slotColorMenu( int )" ) );

If the underlying C++ instance of '_colormenu' has an 'activated(int)' signal, the Java slot is connected to that. Otherwise, the runtime assumes that you want to connect to a Java signal and it connects the slot to that instead.

Emitting a signal looks like this:

 emit("colorChanged", darkGreen());

8. How does this compare with AWT and Swing?

A very interesting question! I've never done any AWT or Swing programming (my background is Objective-C with NeXTSTEP). It doesn't appeal to me because the subclassing and managment of event listeners looks clunky and doesn't make use of Java's dynamic runtime. Swing code appears to need 5 times as many classes and twice the bulk, yet offers less functionality, compared to Apple's Cocoa or Trolltech's Qt.

9. How hard is it for developers to add Java support for their own Qt widgets?

The KDOC converter is included in the Koala KDE bindings project, so they can run their widget headers through that and convert them. One day per widget or so would be my estimate

10. Could this code be used to embed Java code in a C++ KDE application?

Yes, you can mix C++ and Java. The objects don't always have to be instantiated from within the Java environment. If you allocate an object instance on the C++ side, and then you refer to it from within Java, a Java version is created automatically. However, when the Java version is subsequently garbage collected, the C++ instance isn't freed by the Java runtime. It would still exist over in the C++ environment.

However, if you instantiate an instance on the Java side with a 'new' command then the C++ is freed on Java garbarge collection.

11. Where do you plan to go from here?

I plan to finish the Objective-C and C bindings for KDE, finish adding Objective-C and Java support to KDevelop 2.0 and contribute bug fixes/enhancements to the code just released.

12. Is there anything else you'd like to say?

I haven't given the KDOC author a namecheck - which I think he deserves. So a big hand to Sirtaj Singh Kang from me is deserved. Also I forgot to mention there is a patch to the Qt Designer uic tool to generate Java from exactly the same .ui files as C++.

I'd like to thank Richard for creating this cool new binding, and for finding the time to answer my questions. You can get the code by checking out the kdebindings module from the CVS; it's not included in the packages for KDE 2.1 because it's so new. I have added some information to the Java language bindings section of the developer site, including an example of using the bindings for people to have a look at. People interested in using Java with KDE might want to join the kde-java mailing list.



<  |  >

 

  Related Links
 ·   Articles on Interviews
 ·   Also by Richard Moore
 ·   Contact author

  File Attachment
  • Click to download attachment ScribbleWindow.java
    8KB (9205 bytes)

  • Thread Threshold:

    The Fine Print: The following comments are owned by whomever posted them.
    ( Reply )

    Over 40 comments listed. Printing out index only.
    Re: Java Mania: An Interview With Richard Dale
    by Roberto Alsina on Tuesday 27/Feb/2001, @15:59
    Way too cool!

    Congratulations Richard! I knew that week I once spent on QtC would be useful somehow even if only as inspiration to a much better idea :-)

    Actually, if you think about it, this work you did is most of the work to bind ANY language to Qt and KDE.

    Once the C binding is good, any language can bind to it easily.

    And if your language supports binding to C++, then you can do a direct one.

    Come on Pascal/Ruby/Sather guys, have fun! :-)
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by kdeFan on Tuesday 27/Feb/2001, @17:36
    So when gcj matures, we'll be able to write natively compiled kde apps in java? VERY cool! While it may not be as capable as C++, java is a lot of fun to code (imho, of course). Funny thing is, I'm currently taking a java class and an intel assembly class (definitely two extremes), and I enjoy them both more than C++. I have my reasons, most of which amount to personal preference, so I won't start a language war ;) Besides, I would enjoy coding C++ if I had nothing else, and I certainly enjoy it more than C. I should shut up and put on my flamesuit :)

    Seriously though, KDE2 + Qt + gcj would be amazing!

    [ Reply To This | View ]
    More info on the bindings
    by Richard Moore on Tuesday 27/Feb/2001, @18:05
    The developer site seems to having trouble (a result of the number of people downloading 2.1), but you can still see the docs I referenced via CVS. If you don't have CVS access then you can use the webcvs to view them.

    You can also use this interface to look at the files in the kdebindings module itself it you like.
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by John on Tuesday 27/Feb/2001, @18:17
    I'm sure Java is a great language and Qt and KDE are great libraries, but why would you want to write nonportabe KDE apps in java when you can write completely portable apps in swing. This is a thing that java was meant to get rid of. I can't think of the word that describes something like making non-portable java?
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by Jono Bacon on Tuesday 27/Feb/2001, @18:45
    Richard, thanks for your kind contribution to the KDE project. I am currently in the process of learning Java, and your work has given me extra incetive to learn. It is work like this that inspires others to contribute, and which makes KDE such a fantastic desktop and project to be a part of. Congratulations. :-)
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by Luke on Tuesday 27/Feb/2001, @20:18
    Isn't this illegial(as proved in MS vs SUN).
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by Silly on Wednesday 28/Feb/2001, @02:49

    One thing I would note is that Swing isn't as bad as you make out - there are three main problems - one is that there's a lot of very badly written code out there, thanks to "Java applets for dummies" books and the like, another is that people persist in using (definitely flawed) AWT components, and the third is that people are still using the 1.1 swingall.jar swing instead of 1.3 swing, thanks to MS and Netscape faffing.

    The Beans/Swing event handling model is very similar to signals and slots to program (although not in its actual implementation), and I assure you that _my_ swing code is only a little more verbose than Qt code for equivalent functionality, and that reflection-based at-runtime eventlistener connections are possible, and easy to do. There is stronger type-checking on java's events than Qt signals, though, so you have to explicitly deal with different exceptions when you do dodgy things.

    That's not to say I don't prefer Qt programming though! - just that swing is actually not that bad a toolkit (better than programming Gtk in C, anyway, although Gtk--, again, isn't all that bad - I dislike Qt's moc, especially since new C++ compilers have sufficient template support to render it obsolete...), provided you learn it from a decent, i.e. O'Reilly or Sun published, book.


    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by gis on Wednesday 28/Feb/2001, @02:55
    This is indeed excellent! I will try to make use of this in my university projects. It's also a great way to let new programmers write KDE applications without having to learn the (in comparison rather complicated) C++ Syntax.
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by reihal on Wednesday 28/Feb/2001, @03:56
    I wanna Forth binding.
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by Luke on Wednesday 28/Feb/2001, @14:56
    Too bad GNOME has JavaGtk and an implimentation under JNI. But KDE people like to do stuff like integrate browsers into there desktops, use nonportable APIs and component technologies, push nonportable java and FUD the competition. Of course they also do stuff like DoS attacks on google, even though Ximian took there adds down, but the addwords were bought by a free speach advocate.
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by KDE-r0XoR$ on Wednesday 28/Feb/2001, @16:30
    After QtC will there be a lisp binding?
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by 0 on Wednesday 28/Feb/2001, @20:03
    Why did you do a thin wrap of Qt and not do a JNI wrap, would have made alot more sense and all those Swing apps would look cool, not to mention the portability.
    [ Reply To This | View ]
    Swing callbacks?
    by Sean Reilly on Thursday 01/Mar/2001, @07:12
    One thing I would love to see this used for is a Swing callback to render the components for a custom look and feel. This would be similar to the Mac OS X Aqua look and feel in which the Java code calls back to the native code to draw the user interface elements. That would be very nice since all java swing applications (and there are some good ones!) would automatically be consistent with the native desktop theme.
    [ Reply To This | View ]
    Why Java or Objective C Bindings are huge.
    by Alex Hochberger on Thursday 01/Mar/2001, @08:54
    Okay, you want to push a desktop environment and useful applications, time for an unholy alliance... Apple and KDE.

    Apple is sitting, IIRC, at around 8% of the desktop, and Linux/Unix around 4%. I figure that KDE has at least half the Linux/Unix desktop market, so combined that is 10% of the desktop.

    This kind of alliance is huge, because a MUCH higher percentage of Linux users are programmers than Apple users, while Apple brings a marketshare and a marketshare that will pay for commercial applications.

    If you can create a common language for developing MacOS X applications and KDE applications, you now have a competitive desktop standard.

    Java has the potential, Mac is pushing Java, hard. KDE pushing Java hard would also create this alliance. GNOME will never push Java, but pushing a REAL KDE-Java solution (this is a start of course...) will let you combine those markets and create something interesting.

    Alternatively, get Trolltech to port QT to Cocoa, and port the KDE Libs to Cocoa, so that you can build KDE/MacOS X applications in the KDE Library space that will run natively on both...

    Just a thought...

    Alex Hochberger
    Feratech, Inc.

    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by Dave on Thursday 01/Mar/2001, @09:21
    This is way too cool. Is there going to be a site or something that sample Java code would be posted to show how to take advantage of this binding?
    [ Reply To This | View ]
    Thanks Richard!
    by Janne Kylliö on Friday 02/Mar/2001, @04:10
    This is absolutely fabulous :-).

    Java has been my favourite language for a while but writing desktop apps that don't integrate well into desktop has been pointless. Now this is all changed.

    --
    jannek
    [ Reply To This | View ]
    Re: Java Mania: An Interview With Richard Dale
    by Stephen McConnell on Friday 02/Mar/2001, @09:38
    Gee... a non-portable Desktop specific Java... Where have I heard that before? OHHHH Bill strikes again!!!!
    [ Reply To This | View ]

     
    The Fine Print: The previous comments are owned by whomever posted them.
    ( Reply )

      "I'm holding out for a computer interface that plugs directly into my cerebral cortex." -- Sirtaj Singh Kang
    KDE®, "K Desktop Environment", "KDE Dot News", "got the dot?" and the KDE Logo® are trademarks or registered trademarks of KDE e.V. in the European Union, the United States and other countries. All other trademarks and copyrights on this page are owned by their respective owners. Comments are owned by the poster. The rest: Copyright © 2000-2008 KDE e.V. for The KDE Project. For further information or comments on this site, please contact the Webmaster.
    [ home | post article | flat forty | subscribe | search | rdf ]