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 »



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 portal.

Topics posted until now:

Read the rest of this entry »



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 »

, , , , ,


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 »

, , ,


Android Tutorial (3) – How to create, run and read your first application, Hello World

In this article we will see how to use the Eclipse IDE and the ADT (Android Development Toolkit) Plugin for Eclipse to create a very simple Android mobile application, the classic Hello World !. Despite its simplicity, the application just prints a message on the screen, its is very important to understand it, because its structure represents the core for any other Android mobile application.

Other topics highlighted in this article will help you to:

  • create an Android mobile application project using Eclipse and ADT (Android Development Toolkit) Plugin;
  • run the mobile application using different mobile Android emulators;
  • understand and read the structure of the Android project.

Read the rest of this entry »



Android Tutorial (2) – Applications key concepts, activities and resources

In order to understand the Android application architecture you need some basic knowledge regarding Android applications key concepts. Understanding these elements will allow you to control:

  • application components
  • application lifecycle
  • application resources

In this post are described all these key concepts  in order to highlight their role, utility and importance. Other posts will describe in more detail how are used in order to develop an Android mobile application.

The main characteristics of an Android application (more detailed information on are:
Read the rest of this entry »



Android Tutorial (01) – Setting the development environment

Android is an open source software toolkit created by Google and Open Handset Alliance. Initially developed for mobile phones, it has become a major application platform for a wide range of mobile devices.

The scope of this post is to summarize the steps needed to set the development environment and to start learning and developing Android applications.

Read the rest of this entry »



Tutorial Java SCJP – # 19 Enumerari de tip enum

Exista situatii in care o variabila trebuie sa aiba valori limitate la o anumita multime, definita in specificatiile solutiei. Sa presupunem ca trebuie dezvoltata o aplicatie Java care gestioneaza Vehicule iar tipul de motor trebuie sa ia o valoare din multimea {BENZINA, DIESEL, HYBRID, ELECTRIC}. Pentru a implementa cerinta se poate defini atributul asociat tipului de motor ca String sau ca int si se valideaza de fiecare data valoarea de intrare. Pentru siruri de caractere se poate compara valoarea de intrare cu "BENZINA", "DIESEL", si asa mai departe. Pentru int se poate face asocierea BENZINA este 1, DIESEL este 2, … si se verifica valorile pe baza acesti abordari. Aceasta este o solutie posibila, dar nu e eficienta pentru ca se pot face cu usurinta greseli si pentru ca se complica o procedura care ar trebui sa fie simpla.

Read the rest of this entry »

1 Comment

Tutorial Java SCJP – # 18 Blocuri de initializare

Pentru a face prelucrari si pentru a obtine rezultate este nevoie de date. Si aceste valori de intrare sunt de obicei stocate in variabile statice, variabilele locale (definite în metode) sau variabile de instanta (variabile nonstatice definite în clase). Pentru a initializa o variabila o poti face la definitia sau mai târziu într-o metoda (constructor sau nu). In ciuda acestor doua solutii comune, exista o alta cale folosind blocuri de initializare.

Blocurile de initializarea sunt blocuri de cod definite intre { si }. Din acest punct de vedere, ele seamana cu blocuri/corpuri de metode, dar principala diferenta este ca blocurile de initializare nu au un nume. Ele sunt ca metodele, insa fara antet/header (tip returnat, nume metoda, lista de parametri).

Read the rest of this entry »

1 Comment