Archive for category Programming

How to connect to a .NET Web Service from a J2ME MIDlet using kSOAP 2

Web services had and continue to have a great impact on the development of Web applications because they allow total independence between clients and service providers. The location, the platform, the programming language and the architecture of both the clients and the services has no effect on each other. The Internet technologies and standards that allowed the implementation of Web services are HyperText Transfer Protocol (HTTP), eXtensible Markup Language (XML), Remote Procedure Call (RPC), Web Services Description Language (WSDL), Simple Object Access Protocol (SOAP) and Universal Description, Discovery, & Integration (UDDI).

In this article we will see how to connect to a .NET Web Service from a j2ME MIDlet using kSOAP2 library. The Java 2 Micro Edition (J2ME) Platform offers support for Web Services through the J2ME Web Services API (WSA), JSR 172, which provides two optional APIs: remote service invocation (JAX-RPC) and XML parsing (JAXP). For the next example, we will use the third party kSOAP 2 library because it is lightweight and efficient. The solution is developed in the NetBeans IDE but you could use also Eclipse IDE.

Read the rest of this entry »

, ,

8 Comments

Android Tutorial (8) – How to add a menu, programmatic vs. declarative solution

How to add an Android menuAndroid mobile applications have the advantage of being deployed on mobile devices that have touch displays. This enhance the user experience and allows developers to design the user interface so it will be dynamic, easy to use and efficient. Despite this advantage, the display size and usability concepts (one golden rule is to have all the window controls visible on the display) limit the number of buttons and visual controls that can be placed on a single window/form. So, application wide options and functions can be made available using a menu, leaving the display for particular and contextual options.

A menu is a group of options (items) that are accessed using the device Menu key. The menu items are represented by single options or by groups of options, which are organized in submenus.

In this article, we will see how to add a menu to the Android application. The solution is implemented using both the programmatic and the declarative solution that uses menu.xml files. For the declarative solution we will use also the Android visual editor for menus.

Read the rest of this entry »

,

9 Comments

Android Tutorial (7) – How to debug the Android mobile application with LogCat

In computer science and especially in programming, things can go wrong easily. Even simple things, that you have done it before, can generate runtime exceptions that crash the application. Most of the time, the reason is the inability to think to all aspects every time you do something. And because this will not happen, the programmer best friend is the debugger.

In this article we will see how to debug the Android mobile application using the Android LogCat. Despite this Android SDK tool, the application can be debugged in Eclipse like any other Java application (i.e using breakpoints).

Read the rest of this entry »

,

3 Comments

Android Tutorial (6) – How to create and display a new form, window or activity

In this post we will see what are the basics for developing an Android mobile application that has multiple windows or activities. To do that, we need to know how to create and display a new form, window or activity (for the rest of the post we will use the Android vocabulary and call it just activity).

We have seen in the previous parts of the Android Tutorial which are the fundamentals of an Android application and its components. Also we have seen that behind a window there is an Activity type instance that has a lifecycle and a display.

Read the rest of this entry »

,

11 Comments

Android Tutorial (5) – How to create a new Activity class with the Manifest editor or without it

Behind any window or form in the Android mobile application there is an Activity instance. In order to develop a mobile application with multiple windows you must create, for each display, a new class that extends Activity class.

In this post we will see how to create a new Activity programmatically or using the Manifest WYSIWYG graphical editor that comes with the Android ADT Plugin for Eclipse.

Read the rest of this entry »

,

7 Comments

Android Tutorial (4) – Procedural vs. Declarative Design of User Interfaces

Android mobile applications are relying on user interfaces composed on dialog windows, visual controls, 2D graphics and other multimedia elements for efficiency and usability. The Android platforms allows programmers to use two methods to design user interfaces: procedural or declarative.

In this post we develop a simple Android mobile applications that will help to make an analysis on procedural vs. declarative design of user interfaces.

Procedural means to use only Java code to design the user interface. This is something usual in designing Swing interfaces on JSE platform or designing user interfaces in J2ME MIDlets. Because every element of the user interface is managed by different classes instance, designing means to create them and to manage them.

Declarative means to use a descriptive markup language, as XHTML or XML, to describe the user interface. This is similar to how simple HTML pages are done. The designer describes the page look and the browser interprets and generates the user interface.

Read the rest of this entry »

,

3 Comments

Android Tutorial – Overview and contents

android tutorialThe Android tutorial covers all important concepts that will allow a new programmer to learn how to develop mobile applications for the Android platform. The tutorial is written  from a programmer perspective and dives after few topics into simple and do-by-example applications which are easy to follow. Despite the apparently simplicity, each topic highlights important aspect of the Android platform and synthetize aspects described in detail on the developer.android.com portal.

Topics posted until now:

Read the rest of this entry »

,

10 Comments

How to encrypt/decrypt files in Java with AES in CBC mode using Bouncy Castle API and NetBeans or Eclipse

The Bouncy Castle Crypto API for Java provides a lightweight cryptography API that is an alternative to the standard Sun Java Cryptographic Architecture (JCA) and Java Cryptographic Extension (JCE) bundled in the JDK. The API can be used in J2ME MIDlet applications or in other Java applications up to the 1.7 platform.

The Bouncy Castle lightweight cryptographic API can be used as a:

  • Cryptographic Service Provider (CSP) for the JCA;
  • external library.

In this post we will see how to use the the Bouncy Castle lightweight cryptographic API in both situations, as the syntax differs from one approach to the other. To highlight the differences, the advantages and the disadvantages of the two solutions, the Bouncy Castle API is used in a console Java application to encrypt/decrypt files with the AES (Advanced Encryption Standard) or Rijndael algorithm in Cipher Block Chaining (CBC) mode.

Read the rest of this entry »

, , , , ,

3 Comments

How to convert a byte array to a Hex String in Java

When processing binary values it is very difficult to read or to display them because any printing function generates a String value.  The problem with this approach is that not all byte values can be interpreted as a printable char (i.e. the 0 binary value represents the NUL symbol; for more details check ASCII Codes + HTML Codes and Special Characters) and the resulting String will not contain all the byte values or it will not be accurate. Moreover in Java a char is stored on 2 bytes.

In this post we will see how to convert a byte array to a Hex String in a Java application. The solution is useful because:

  • printing binary values in base 2 or base 10 format can become difficult to read as the value can have multiple digits;
  • is easier to read values in hexadecimal base;
  • it is easier to check or compare values in hexadecimal base.

Read the rest of this entry »

,

1 Comment

How to use Bouncy Castle Cryptographic API in NetBeans or Eclipse for Java JSE projects

The Bouncy Castle Crypto API for Java provides a lightweight cryptography API that works with everything from the J2ME to the JDK 1.6 platform and also a provider for the Java Cryptography Extension JCE (provides an implementation for JCE 1.2.1) and the Java Cryptography Architecture, JCA.

The API provides cryptographic functions for Java JDK 1.1 to 1.6 applications and for J2ME (mobile applications) MIDlets. The API can be downloaded from the Bouncy Castle latest releases page.

In this post we will see how to use Bouncy Castle Cryptographic API either as a JCA provider or as a lightweight API to develop Java J2SE projects in NetBeans 7 (works also on older versions) or Eclipse IDE.

If you want to develop Java applications based on the JSE framework that provide cryptographic services as:

  • generating hash values to check the integrity of the message or file;
  • encryption/decryption using symmetric key algorithms;
  • encryption/decryption using public certificates in a public key infrastructure;
  • generating message authentication codes for messages;

you must use a cryptographic API which provides the necessary classes and methods. Read the rest of this entry »

, , ,

2 Comments