Archive for the ‘Computers’ Category

A common problem is to convert a List of type X to a List of type Y, given a well-defined function from X to Y. For example, we have a List<Double> and want a List<Long> containing those numbers rounded. In Java 8, there is a quick solution for this:

Short enough, but not lazy: We may not always need to access every member of the List, and thus we don’t need to allocate memory for the whole result and calculate it all at once. In those situations, I use this utility method:

As you can see, line 2 is much simpler now (once map is available as a global utility method). It allocates very little memory, which does not depend on the size of the source List, and doesn’t run Math::round yet. However, when the same number is accessed more than once, it has to calculate it again. So it’s not always the best solution.

Recently someone asked me how to convert a List of type X to a List of type Y, given a well-defined function from X to Y. I’ve seen some horrible “solutions” for that in real world programs, and I hope that some people will benefit from my way of doing this:

JTiger is a test framework, developed by Tony Morris in 2004 and published March 23, 2005.

Defining attributes

JTiger had a rich set of features and predefined assertions:

an integrated test assertion for serializability

check for expected Exception

check for equals/hashCode contract

It was easy to run tests programmatically or from an Apache Ant task.

History

Tony Morris developed Assertion Extensions for JUnit (at that time known as JUnitX; not to be confused with other frameworks sharing the same name) a while ago. It contained advanced assertions to be used with plain old JUnit. When Java SE 5 was in beta, he started with the development of JTiger. Because of his contract as an employee of IBM, he needed permission by IBM to publish it as Open Source, even though he developed it in his free time. That process took several months. JTiger even crossed the desk of Erich Gamma, who commented on it in a private email to Tony Morris.

While JTiger was in this approval process, TestNG has been released. At that time it had less fancy assertions (see examples above), but the concept was just as good and additional assertions have been introduced later. Also there were IDE-Plugins for Intellij Idea and Eclipse.

After JTiger has been approved by IBM and released, it gained a fair amount of community acceptance. Independent comparisons with JUnit and TestNG were rather positive, such as Justin Lee’s Test Framework Comparison.

In December 2005 I officially took charge of the project and Tony Morris retired from it. I never changed much except for the documentation and website, though.

Early in 2010 the transfer of the domain ownership for jtiger.org to me failed. I don’t know what went wrong. I got the correct release code from Tony Morris and gave it to my registrar. A few days later my registrar informed me that either the current registrar or the owner (Tony Morris) did not approve the transfer. That was the end of the website.

What now?

In 2008, Tony Morris released Reductio. Similar to QuickCheck, it uses Automated Specification-based Testing. Reductio has become part of the Functional Java API.

System requirements

Installation

Tactical motivation

Experienced players have optimised their research in such a way that many technologies are outdated a few minutes after they have been researched. The lifespan of some weapons is very short in games with experienced players. For example ripple rockets are available in less than 19 minutes (T1, no starting bases), which makes mortars pretty much useless. When someone tries to use mortar or bombard pits, the opponent can simply build a few bunkers and wait for CB tower and ripple rockets. Even a huge field of mortar pits can only destroy a few bunkers before it gets smashed by ripple rockets.
With this mod, ripple rockets will be available around game minute 37, which makes mortars more attractive.

It does not slow down the entire game! Production speed and unit movement speed as well as power income are unchanged. So relative to the research, these elements are twice as fast now. For example in the previously short time span from when twin mg gets researched until the research of heavy MG (or a different superior counter weapon like mini pod), a player can build twice as many tanks with twin MG and move twice as far with them as before.

What it does is this: It tries to connect to IRC.BENDOVER.BE (that server is no longer operational), then joins #spreader.crew (password: spreadmaster). In my case it used the name!id: oppqrrstc!oppqrrstc (probably generated individually). Then it stayed in the channel and did nothing more. It probably waited for a bot or real person to contact it with further instructions.

Any hints about this trojan or the creators (former owner of bendover.be? "spreader.crew"?) are appreciated.

How to fix UnsatisfiedLinkError in JNI

I have never had problems with JNI. In the few situations when I needed it, it just worked. But last week someone asked me for help with his problem. When I tried to reproduce it, I found out that it had spread even to my old JNI programs which worked until 2006!

When running a program that uses a native function the following error occured:

It’s obviously a linker problem related to the generation of the .dll file. I have no idea why it occurs now and didn’t occur in the past. Different OS, compiler version, something like that? For some reason both the linker of Visual Studio and the linker of GCC started to think that is was a good idea to replace all method names by some arbitrary name which then cannot be found at runtime.

Fix for GCC

To fix that with GCC, the linker opion --add-stdcall-alias can be used.

Fix for Visual C

For Microsoft Visual C Compiler it should theoretically be possible with a linker option as well.

Find out the correct linker option

First compile and link in the usual way that didn’t work. This will create the .dll file which results in the error we are talking about. Then use the dumpbin tool to list the procedure names:

dumpbin HelloWorld.dll /EXPORTS

You will find your procedure name, something like _Java_HelloWorld_print@8. Now try to guess what the name should be. My guess in this case would be Java_HelloWorld_print. This would result in the linker option /EXPORT:Java_HelloWorld_print=_Java_HelloWorld_print@8

Recently the PR department of uCertify approached me and asked me to blog a review about their exam preparation kit. Since this is an interesting topic to me (see my posts Whizlabs vs. Enthuware, and Effective Enthuware) and since I would get a free simulator, I agreed.

uCertify produces preparation kits for many different IT certifications, including SCJA, SCJP, SCJD, SCWCD, SCBCD, SCMAD and SCDJWS. I got the one for SCBCD 5.0 (Sun Certified Business Component Developer for the Java Platform, Enterprise Edition 5, CX-310-091), which costs USD 59.99, to test it. I used the uCertify PrepEngine Version No: 12.21.05.

Strengths

A nice looking user interface with good usability, especially regarding all the little things. For example it is possible to click on the answer itself, not only on the checkbox next to it. Several keyboard shortcuts are available.

It has an optional study mode for every kind of test. When enabled, it says immediately which answers were wrong, rather than evaluate all answers only after they have been given. This provides a more harmonic way of learning and measuring progress.

It automatically shuffles the order of the answers. That’s an awesome feature that I miss in Enthuware and Whizlabs! It prevents me from remembering the position of the right answer instead of really learning the right answer.

The explanations to answers are good and include diagrams where it makes sense.

Huge amounts of study material are included! It is not only a simulator, it is a full preparation kit, just as promised.

Aside from the option to study the topics using small articles in the style “What is the PreDestroy method?” and larger articles about complex topics, there is an interactive mentor that almost provides the feeling of having a real private teacher. In small chunks it presents the exam topic as specified by Sun, then explains it, and afterwards asks me a question about it to check whether I understood it.

There is a feature to discuss any single question with others, similar to a forum thread. Once there are more users this can be very useful. I tried it a few times, and it took more than a day to get my comments “approved”. Hope that gets better.

Questions can be assigned a custom tag. For example I can give several questions the tag “unsure” or “do again before exam” and then create a custom test based on the tag. I would highly recommend to use this feature to assign box IDs according to the Leitner System, similar to how I described it for Enthuware in Effective Enthuware. (Note that numbers and short names are problematic, so use for example “bbbb” for box 2.)

There are lots of features which I didn’t cover in this review, because there are so many. I covered the ones I considered important to my way of learning, but one of the other ones might just be the feature you always wanted.

Question quality and exam topic coverage: I trained for a section using Enthuware until I was able to answer all questions in Enthuware corectly. After that I tried questions for the same topic in the uCertify simulator. I passed on the first try, but there were some exam-relevant topics that had not been covered enough in Enthuware! (Concrete example: It is possible to get through the Enthuware questions without fully understanding MEMBER [OF] in JPQL. uCertify did not let me get away with that.) Nothing against Enthuware – it is possible that this test would have worked the other way round in the same way. Simulators have different strengths and weaknesses.

Weaknesses

It doesn’t have a direct way of selecting a range of questions. For example I can’t easily create a test with questions 1 – 6 of topic X and later questions 7 – 12 of topic X. (To do that, I have to add all questions to the pool, sort by ID, then delete some of them, remember which ones I deleted, do the others later.)

Support. I used the general support, not the one for paying customers, because I am not really a paying customer. My questions were answered only partially sometimes, and one of three support requests was ignored completely. Let’s just hope they provide better support for normal customers.

The license is complicated. I asked the support about it, but still don’t understand if I can install the product years later on different hardware. An on-line activation is required. I wouldn’t recommend buying it if you are planning to use it for longer than a year, unless you sort this out.

Getting the custom tags, an important feature (see above), to work was a challenge. First I tried tags like “1”, or “2”, and they just didn’t show up in the custom test dialogue. Then I tried “a” and “b”, still no success. So I tried “11111” (maybe it’s a length issue?). Then it showed up, but when I tried to add the questions with that tag, only two or three, it added more than 100 to the question pool. In brief, my impression is that there are certain rules for tags: 1. At least 3 or 4 chars; 2. no numbers (or not only numbers?).

Conclusion

uCertify provides more than Enthuware or Whizlabs. I cannot answer the very important question of which simulator provides the most relevant questions regarding the real exam, and if someone who uses the complete preparation kit of uCertify will get a better result in the real exam than a low budget learner with Enthuware plus free study material. More fun with uCertify – well, that’s indeed possible due to the nice user interface and the interactive mentor. The complicated license and poor support are a problem.

I just got the strangest error message when trying to use a stateless session EJB as a WebService in Glassfish v2 u1:

[#|2008-07-13T16:41:25.366+0200|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.tools.deployment|_ThreadID=12;_ThreadName=Thread-31;_RequestID=d816d64c-543d-47ac-b339-2231f346754e;|Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException
at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1817)
at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2089)
at com.sun.enterprise.deployment.backend.AppDeployerBase.loadDescriptors(AppDeployerBase.java:328)
at com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:200)
at com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:129)
at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:169)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:266)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:739)
at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:174)
at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:210)
|#]

Apparently there is a problem in this Glassfish version that prevents it from showing the proper Exception as JAX-WS reports it. The verifier only barfed random shit at me, too.

I updated to the lastest Glassfish to get a better error message, but then it even worked without an error. Strange days.