« March 2010 | Main | May 2010 »

April 29, 2010

Swing XML layout with no dependencies

This article is a continuation of my article about how to start a Swing application. You must download the Teppefall Layout tool to create the correct XML. If you do not want to use this tool (trial is free), you can also use the XSLT files found in the "transformers" folder instead.

This will only work if you remove the Teppefall API's from the JXML. JXML is simply short for Java XML, which is a standard object serialization format in the JRE. The ViewImporter.test method should be called on the Event Dispatch Thread (EDT). In other words, on the Application.create method in the previous article.

<!-- SwingDemo.jfc for Teppefall Layout -->
<!-- Open "View Source/Result" for the JXML -->
<component class="javax.swing.JLabel" text="Hello World !">
<property name="opaque" type="boolean" value="true"/>
<property name="background" type="color" value="#ff0000"/>
</component>




<!-- SwingDemo.jxml after removing the Assembly wrapper code used by Teppefall Layout -->


<?xml version="1.0" encoding="utf-8"?>
<java version="1.4.2" class="java.beans.XMLDecoder">
<object class="javax.swing.JLabel">
<void property="text">
<string><![CDATA[Hello World !]]></string>
</void>
<void property="opaque">
<boolean>true</boolean>
</void>
<void property="background">
<object class="java.awt.Color" method="decode">
<string><![CDATA[#ff0000]]></string>
</object>
</void>
</object>
</java>



class ViewImporter {
static Object decode(InputStream stream) {
XMLDecoder decoder = new XMLDecoder(stream);
return decoder.readObject();
}
// call from Application.create
static JLabel test() {
InputStream is = ViewImporter.class.getResourceAsStream("SwingDemo.jxml");
System.out.println(is);
Object o = ViewImporter.decode(is);
if(o instanceof JLabel) {
System.out.println("ok");
}
return (JLabel)o;
}
}

April 27, 2010

Blowhard blogging versus professional writing

People interested in EDT compliant object creation in JFC with source code.
30 developers.

People interested in me ranting about current events.
8000 developers.

You need a blog to exist on the Internet because of how search engines index material. The problem is that the value is very low because people do not link to you with the correct keywords. And even if they did the related-content industry would probably outrank you anyway. And this is why many businesses try out the social notworking angle.

13 121 unique developers over 30 days might seem impressive. But the reality is that most of these readers never link to this website and therefore, in 20 days time, it will be back to 200-300 unique users a day. And this is why getting linked on Techcrunch is probably almost worthless unless people Twitter about it. So you might as well buy some Stumbleupon ads, or something, to test your server.

The reason blogging is so powerful is because old media companies almost never link to the competition and because many blogs use other blogs as a sort of judicial indemnification. And because of this related content can outrank original content on fringe keywords. Which then fuels the crazy me-too behavior that we see on Techmeme.

There are several websites that can give you this kind of traffic. But you have to write for a specific niche and talk about interesting things to get there. But as I said, this does nothing to promote your actual product or service. So this is basically a hobby that can distract you from your real business.

adsense_2010_april.png

Time spent on site for normal people is three to four minutes but the average is just 27 seconds. And instead of reading the blog front page people instead go to the main website to locate the about page. So pages per visit on the blog is just 1,17.

April 22, 2010

Teenagers make $170k on Apple iPhone OS platform

Here are two guys, 18 and 19, who made $170 000 US on the iPhone OS platform. Very impressive right ? Except the journalistic angle is basically "kids make money from nothing" when the reality is that they have access to two MacBook Pro's, at least one iPhone , two iPad's, a broadband connection, a credit card to pay for the Apple Developer license plus web hosting. And one of them traveled to the US to buy the iPad's on launch day. So the story is really "well off kids strike it big thanks to Wikipedia data set and business savvy". The story even indicates the yearly salary of their parents by saying "they already make as much as their parents". Which may give us some social indicators.

I'm totally jealous. But this is sort of turning into those Lebron James type stories where 99 percent never get anywhere and one percent make a truckload of money. What is funny about the article is that the journalist claims the primary coder is a Java expert. So obviously he knows something we do not. Or maybe Java is really Javascript and they are doing some kind of JSON transaction. But that is less provocative, so I am ignoring it inside my head. So is the Apple iPhone OS platform really a brainwashing device ? You be the judge. Here is a rough translation of the second paragraph.

Alternative graduation

While their friends plan graduation these two data entrepreneurs sit in their room and polish the latest version of their homemade application iWiki for Apple's new reading board iPad.

- I try to do my homework first, and read for my tests. If there is any time left, I write some code, says Bjarne Mogstad.
- Bjarne is better at putting his homework first, says his friend and business partner Nikolai Krill (has an American father, writes the sales text).
- I often write code when I should be doing homework.

Luckily both have maintained their grades throughout the ninth grade and high school. They have spent all their free time writing applications together.

So far they have sold 112.739 units of iWiki over 18 months (as of 21. april 2010).
Profit: 868.000 NOK (146,404.29 USD).

April 21, 2010

What ? Adobe Flash for iPhone OS is an open platform ?

Mike Chambers of Adobe does sound a bit like a spin doctor when he talks about Adobe Flash Professional CS5 support for the iPhone OS platform. Sure, Flash is open in the same way a closed door is open if you use a very large sledgehammer. And the DRM part of Flash is probably just as sensitive as the DRM part of Adobe PDF. So when Adobe talks about open sourcing their "99 percent of web browsers" platform it is basically that, just talk. AIR and Flex are open because the primary dependency is Flash itself. And really, if Flash is that open to begin with then why is Flash video support in JavaFX shipping as a download-only Web Start extension and why is Videolan almost entirely made up of non-American developers ? As noble as Adobe may sound, the reality is that the American patent system is ****** **.

Apple wants people to use Apple API's. In the same way Microsoft, Google, IBM, Oracle and SAP wants people to use theirs. When Apple talked down the importance of Java this was a huge signal flag going up where Apple is telling the world "we want to create vendor lock-in too". Just like Microsoft, Adobe, Google, IBM, Oracle and SAP. Microsoft rewrote Java from scratch with C#. Adobe did the same thing with Actionscript and then started telling everyone how they can support C++. Google created Chrome, Chrome OS, Android, Native Client and App Engine while claiming to be open and platform neutral. And IBM, Oracle and SAP are established job titles for developers because of the lock-in effect.

This is all about API control and HTML5 is totally irrelevant because it does not give you any control. Apple is feeling cornered by aggressive technologies like Microsoft Silverlight (MonoTouch), Adobe Flash and Google Android (Java clone) and watches on as Zynga and Playfish redefine the marked for online social gaming. Apple is afraid that their platform will be watered down by copycats and poorly supported cross-platform technologies. Sun Microsystems created the most widely used server side software platform on the planet. And then Oracle, IBM and SAP took over the marked that Sun Microsystems defined. Because Sun Microsystems thought hardware profits were enough to survive. And today they are the property of Oracle.

Apple basically wants more Apple developers. So when the $199 Google Chrome OS tablet comes along the $629 Apple iPad is still a good deal. Sun Microsystems focused too much on hardware and Apple does not want to make the same mistake. Apple is creating a software foundation for the future where content owners are getting paid and not the monetizing slash copyright infringement by proxy industry. Because high quality content is what sells Apple hardware in the first place. Jobs as a person was defined by Pixar, Next and Apple. And he simply believes Apple needs more developers. Because people buy Xbox 360's and PlayStation 3 machines because many software developers support them. People focus on the word "platform" when the real focus should be on "store". And this is the only reason why Apple gets away with this kind of legal nonsense. Because developers get paid.

If the iPhone OS platform was as open as Android, Symbian and J2ME then would anyone make any real money ? And free ad-supported software in a store is basically just parasitic behavior from the store owners perspective. Shelf space costs money. And this is why Apple is clamping down on advertising networks. $99 a year only works if lots of people choose to sell their wares.

What is funny about this whole thing is that Apple is basically telling developers to use the GCC pipeline instead of proprietary, vendor and language specific, compilers. Actionscript is vendor lock-in. C# is vendor lock-in. Android Dalvik Java is vendor lock-in. But GCC is not really vendor lock-in. But modern Objective C is very much a Mac OS X and iPhone OS lock-in.

Personally I just think Apple is tired of being the also-supported platform when they rake in billions of dollars in profits. Only ExxonMobil (XOM) and Microsoft (MSFT) are bigger players.

April 20, 2010

You should almost never extend JFrame in Java Swing

JFrame is one of the heaviest objects in Java Swing (JFC). Just because you extend JApplet this does not automatically mean that your should extend JFrame as well. Because do you see any start, stop or getParameter methods in JFrame ? No, because it is a window frame and not a browser plug-in. Your code should extend JPanel, JComponent and Canvas. Because then you can use the component inside a JFrame, JWindow and JApplet.

So stop creating example code that extends JFrame. This is terrible advice and is mostly a result of developers who want to ignore the event dispatch thread. Because Swing object creation must be done on the EDT but Sun sort of forgot to tell people about it. If you do not believe me then try running Substance 5 in an applet. The JApplet.createRootPane method is on the wrong thread. The fix is to extend the createRootPane method and call super.createRootPane inside a EventQueue.invokeAndWait (click "Extreme mode"). So even Sun developers themselves do not fully understand the EDT. There is a lot of legacy API nonsense clouding the issue.

Personally I use two patterns to start a Swing application. The Application pattern and the Component View pattern. Set the LAF using swing.defaultlaf or a preceding UIManager.setLookAndFeel call wrapped in EventQueue.invokeAndWait. The Component View pattern is for main based test methods in components while the Application pattern is for large monolithic structures.

PS
Right click on the media player and add http://app.teppefall.com/t.flv.


package arbeid;
import java.awt.*;
import javax.swing.*;

class Application {
JFrame mainFrame;
String args[];
String title = "Undefined";
void create() {
mainFrame = new JFrame(title);
View.configureNormalFrame(mainFrame);
}
void start() throws Exception {
if(EventQueue.isDispatchThread())
create();
else
EventQueue.invokeAndWait(new Runnable() {
public void run() {
create();
}
});
mainFrame.setVisible(true);
}
static void launch(String title, String args[], Application app) throws Exception {
app.title = title;
app.args = args;
app.start();
}
}
class View {
static void configureNormalFrame(JFrame frame) {
frame.setSize(600, 300);
frame.setLocation(100, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
static JFrame asApplication(String title, JComponent panel) {
JFrame mainFrame = new JFrame(title);
configureNormalFrame(mainFrame);
mainFrame.getContentPane().add(panel);
mainFrame.setVisible(true);
return mainFrame;
}
}
class SampleComponent extends JLabel {
public SampleComponent(String text) {
super(text);
setOpaque(true);
setForeground(Color.RED);
}
public static void main(String[] args) {
View.asApplication(SampleComponent.class.getName(), new SampleComponent("Hallo View"));
}
}
public class SwingDemo {
public static void main(String[] args) throws Exception {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
SampleComponent.main(new String[] {});
}
});
Application.launch(Application.class.getName(), args, new Application() {
void create() {
super.create();
mainFrame.getContentPane().add(new SampleComponent("Hello world from App - " + args.length));
}
});
}
}

Beyond the about page

So you have a nice about page on your website. All the information is there and everything looks professional and tidy. And you send an email to somebody important containing several properly formed sentences. But you forgot something. You forgot the email signature.

Email signatures are there for many reasons. To tell professional people who you are. To provide extra contact information if something is time critical. To ensure that email software does not remove your email address when someone prints out a discussion. And finally to create the illusion of competence through elaborate use of US-ASCII.

People who are close to a sales or decision making process are often more interested in body language and tone of voice than cold digital text without any context. Business people even jump on airplanes because they are terrified of communication without direct human contact. Because their skill is basically about reading body language and assessing risk. Cold logic versus emotional exuberance often results in many bizarre conflict situations. Context is lost over and over again. Projects go nowhere.

So what does all this have to do with email signatures ? Well, body language people call you on the phone instead of sending you emails. So if you only do email conversations with them you might never extract any useful information. Because they will just give you the company line rather than real information. The reason the volcano on Iceland is a problem is not so much the ash but rather that the body language demographic is having a nervous brake down. Because if there are no face to face meetings and no airplane travel, does anyone actually work for a living ?

But please remember. If you give people your private phone number they will f***ing call you at 7 in the morning and ask you for the password for that machine you used six weeks ago in some other random country. So you have one phone number for work and one for random female stalkers who do not remember last names very well. Because if female stalkers are having trouble finding the right man in today's digital society, then surely business people might need a little extra help.

April 16, 2010

Always remember the about page

Maybe this is obvious for most people, but I can not stress this enough. You must create an about page and that page must contain actual "about whatever you are" information. Because so many people click on that page it is not even funny. So much traffic went to my about page last month that I thought for 10 minutes that I was under a denial of service attack.

My blog has no real "about me" page because I thought nobody cared. But then I wrote an article that went mainstream and suddenly thousands of people clicked THREE times (blog/homepage/about) just to see my about page. Three freaking read/scan/click actual human events just to figure out who I was.

Also, search engine traffic is up 150 percent on my blog because of that one popular article. You just need to write one page of popular text a month to get several thousand visitors. I guess this is small potatoes for some, but for a developer oriented blog like mine this is huge. The bizarre lesson is that one month of writing may give you more traffic than three years combined simply because you are connected to current search patterns.

Being linked to is not enough. You have to be linked into the current flow of the internet to get real traffic. And this is the real reason why Facebook and Twitter is getting so much hype. Because they are both human spam filters for near real-time information. The social bit is just the "reward factor".

April 09, 2010

Why Apple is restricting programming languages on the iPhone 4.0 platform

They are tired of spam. Oh sorry, your future million dollar iPhone application. The reason application developers are waiting forever to get their software approved is because thousands of developers are more or less spamming the store with unfinished software. Write 200 lines of code, build and ship. And now frameworks like Titanium, PhoneGap and MonoTouch is pitching their wares to the "don't know shit about coding" demographic which consist of florists, waiters, male exotic dancers and other random people. Simplifying the process does not scale very well when everybody wants to be an astronaut in space. There is one shuttle in orbit, one on standby and Europe has a few rockets here and there.

There might be other reasons as well. Apple probably runs automated testing tools on all software to check for buffer overruns, private API calls and copyright violations. Frameworks within frameworks makes it very easy to obfuscate code. Just try to understand the Javascript that runs on your average website. Packed obfuscated code that calls into several Javascript frameworks. The problem is not the code itself, but rather that trusted code could call untrusted code. Google Adsense is basically a code injection attack that people pretend is safe because they don't understand the problem in the first place. Advertising is a perfect channel for spreading hostile code. And what do you think random Joe is putting into his 5 cent application ?

There is no problem with lots of people developing software and showcasing their software on some random developer website. But the iTunes application store is basically like Amazon plus the Xbox 360 MarkedPlace. Apple is paying lots of support staff to service pissed off customers who want a refund. This gets old really fast and Apple has probably ignored the problem for a long time just to build up developer adoption.

I guess C# .NET is similar to C++ .NET so MonoTouch might be safe. But don't take my word for it. What are people whining about anyway ? Many people pirate software and are then appalled when commercial companies try to make money. Apple is just protecting developers and users from illegal business models. If you don't like this then pick another platform. Do some HTML5 thing or Android or whatever. Code signing and the approval process is about stopping repackaging. So that milk does not contain other things than milk.

These new language restrictions are there to reduce testing complexity, increase basic skill set requirements and make the approval process "more snappy". All Apple did was restrict languages to what your find in «gcc –help» under "Permissible languages" on every single stock Linux system plus Objective C and Safari hosted Javascript. Although it's very bizarre that Apple did not include assembly as a legal language since lots of people probably run small sections of optimized assembly.

Any Apple user who think this is about reducing the number of "terrible Java/Flash apps" is living in la-la land. The Apple platform is totally overrated when it comes to software quality. Just try to write Apple software that survives five years of Apple API upgrades. Flash crashes a lot on Mac OS X because OS X is a moving target and Adobe wants to support Tiger. Flash is better on Windows because Microsoft has better software API QA than Apple. Try writing a pure Objective C state of the art accelerated graphics application that needs to support Tiger, Leopard, Snow Leopard and another non-Apple operating system and you will probably prefer washing toilets. The Cocoa/Carbon 32bit/64bit PPC/Intel legacy is a royal pain in the ass. And most people don't even know about stuff like screen gamma, resolution independence and text encoding differences.

Anyone who thinks HTML5 or Android is a threat to the iPhone app... HA ! People think implementing Paypal is a huge hassle. Try running your own support, payment and upgrade operation for a few months and see how much that costs.

Next generation Teppefall software

Coming soon to Teppefall Link.