JC301-1: Introducing Java Card 3.0

Foreword: The JC101 tutorial about Java Card 2 is getting closer to the end, now dealing with the subtleties of cryptography, testing, and other difficult tasks. As progress may slow to a crawl, it is time to start discussing the technology that actually started this blog, Java Card 3.

– o –

Your first program

If you are going to work with Java Card 3, your first program is quite likely to look something like the following:

public class EchoServlet extends HttpServlet {

  public void doGet(
          HttpServletRequest request,
          HttpServletResponse response)
              throws IOException {
    String message =
    StringBuffer echo = new StringBuffer();
    for(int i = 1; i < HTML.length; i++)
    PrintWriter out = response.getWriter();

  private static final String HTML[] = {
         + "<body><center>
    	 + "<h1>Echo</h1><br><br><br>"
         + "<font color=\"#000000\">" , "</font><br>"
         + "<font color=\"#444444\">" , "</font><br>"
         + "<font color=\"#888888\">" , "</font><br>"
         + "<font color=\"#cccccc\">" , "</font><br>"
         + "</center><br><br>"
         + "<small><p align=\"center\">"
         + "Yes, this servlet runs on a Java Card.</p></small>"
         + "</center></body></html>"};

Quite a shocker, isn’t it? This doesn’ look at all like a Java Card program. There is nothing specific for card in this program; it could run on any Java EE Web server. On the program, I have outlined a few words that somehow define what Java Card 3.0 is; let’s take a look at them:

  • int. Everyobdy expected this one eventually, and here it is. Java Card 3.0 is a pure 32-bit virtual machine, and there is no reason to cast computation into short and byte, expect for storage. Of course, this also means that Java Card 3.0 will only work on chips that include a 32-bit processor.
  • String. Another long-time dream of Java Card developers, in particular those working on text-intensive SIM Toolkit applets. Well, strings are supported in Java Card 3.0.
  • new. It is nos possible to allocate objects temporarily, i.e., to program in a more standard Java way. This is made possible by the availability of a real garbage collector, and by the fact that some objects are actually stored in RAM. Of course, this also means that Java Card 3.0 will only work on chips that include enough RAM (at least 16 kilobytes).
  • @Override. This annotation is not very useful in itself, but its availability means that Java Card 3.0 is based on a recent release of Java, which supports annotations. In fact, Java Card 3.0 is based on the latest release, Java 6, and it includes supports for quite a few advanced features, including generics and others.
  • HttpServlet. I have kept the best one for the end. Yes, this application is a servlet, and not an applet. It means that a Java Card 3.0 card is expected to be a Web server, receiving HTTP requests over a TCP/IP connection and answering appropiately with a Web page that will be displayed in your browser.

Now, can we run this application? Of course, we can, and the result is shown below:

Execution of Echo1

A question that often comes to mind about these applications is “Is this still Java Card?” The answer is unclear:

  • No, it’s not! It is a Web server, it talks to your browser. It basically supports Java, and there is no Java Card-specific stuff any more.
  • Of course it is … This thing runs on a smart card, i.e., on devices that keep the interesting properties of a smart card (secure, portable, cheap, manageable), as well as their drawbacks (too small, too slow). So yes, there is still plenty of Java Card-specific stuff to know about Java Card 3.0 and servlets.

That’s it for today! We will get to the real stuff in a few days or weeks. For now, you have an opportunity to come visit my home turf and learn about Java Card 3.0 by attending Smart University session on The Art of Java Card 3.0 Programming on September 16th and 17th in Sophia Antipolis. If you missed the JavaOne bash, don’t miss this opportunity to meet with the Java Card 3 community. See you there!

One Comment

  • yacine fandi wrote:

    Hi Thanks for the info

    there a missing ” in line where + ” is.
    in the other hand thanks a lot for this blog
    in the hop to see more tutorial about java card keep on going
    et Mérci

Leave a Reply

Your email is never shared.Required fields are marked *