Running ACR122U NFC Card Reader SDK Demo with Java / Windows8

Using the ACR122U NFC Card Reader SDK with Java is hard work for a Java Newbie like me, but I managed it spending quiet some time on getting the demo application to run.

First Steps of running the Java Demo

  1. Install the Drivers and Demos from the CD
  2. Plug in the card reader to your PC
  3. the Java Sample Code is located here: Sample CodesJavasource files
  4. Install Eclipse (for Java newbs like me)  :)
  5. Make new Java project in Eclipse
  6. import the demo sources: Sample CodesJavasource files
  7. download the OpenBeacon.org active 2.4GHz RFID reader source code dll Jacspcsc.dll in Folder C:\myfolder
  8. Link the downloaded .dll to the project in eclipse:
    1. Select ‘Run As’ -> ‘Run configurations’
    2. Check that correct run configuration is selected and choose the ‘Arguments’ tab
    3. In the ‘VM Arguments’ textbox add -Djava.library.path=C:\myfolder
  9. Under Windows 8 you have to install Java 32bit to work with the dll: tutorial
  10. After that, you can run the project successfully and the applet should run (see screenshot)

eclipse_nfc_applet_success more…

PageRank Algorithmus in Java

The PageRank algorithm, Also on the Google algorithm is based, can be programmed relatively easily. This is the first must be a crawler(e.g.. crawler4j) Pages (URLs) Browse to the left and then on the links of the pages together, the PageRank can be calculated.

PageRank example

When PageRank pages received with many strong backlinks to a higher value, as pages without backlinks or are only of pages linked to poor PageRank.

more…

Part 2: Clean Code – correct and incorrect comments

According to the book (Chapter 4):  “Clean Code – Refactoring, Patterns, Testing and techniques for clean code” of Robert C. Martin.

“Comment not bad code – write to him.”

(Brian W. Kernighan und P.J. Plaugher)

 

Comments can be both, helpful and hindering:

  • hindrance, if you are outdated and incorrect information supply
  • disturbing, if you are too long and unnecessarily
  • helpful, if you are well placed

The use of comments “our inability to balancing, clear to us in our code to express”(S.85). Before writing a comment, one should consider before, whether the code can not be further written expressive.

more…

Copy Code line numbers delete regex

When copying code from Web pages(z.B. Zend.com) it may occur, that the lines of code containing numbers, e.g..

  1. // Parameters for ClientAuth authentication
  2. $service = Zend_Gdata_Gbase::AUTH_SERVICE_NAME;
  3. $user = “”;
  4. $pass = “pa $ $ w0rd”;
  5. // Create an authenticated HTTP client
  6. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  7. // Create an instance of the Base service
  8. $service = new Zend_Gdata_Gbase($client);
To clear the Zeilennumern, can e.g.. following command to run with Netbeans:
STRG H (SEARCH and REPLACE)
Find what: [0-9]{1,2}.\n
Replace with: (blank)
Select: Regular Expressions

Regular Expressions Netbeans

Part 1: Clean Code – Rules for good, clean code

To write clean code and easy to understand the ultimate goal is a good IT Projet. Much depends on:

  • Maintainability
  • Training time for other programmers, means fast, what do individual functions
  • Robustness to changes
  • Testability, everything falls together, with small changes, can quickly stable updates are
  • Popularity with other programmers e.g.: bei Open Source Projekten, as a negative example is called XT-Commerce

The highly recommended standard work on the subject is “Clean Code – Refactoring, Patterns, Testing and techniques for clean code” of Robert C. Martin. In this article, chapter 1 to 3 treated.

Meaningful names

The name of a variable, Function or class should declare immediately, why you exist, what it does and how it is used. If a variable requires a Comment, It expresses not its purpose.

Bsp:

int d //Anzahl vergangener Tage
besser ist:
int daysSinceCreation;

Pronounceable name use

No constructs with unclear abbreviations as: int daSiCre instead of daysSinceCreation.

Searchable name use

Modern IDEs make searching easy, but it's no, when you have to look for the letters e and a control variable is swamped by results.

Variable names with a letter must only be used as local variables in short methods.

more…

Java Date zu Unix Timestamp Converter

Convert Date to Unix Timestamp (Long).

import java.util.Date;

public class DateHelper {   
    public static Long dateToTimeStamp(Date date) {
        Long millis = date.getTime();
        if(millis > 0)
        {
            return millis/1000;
        }
        else
        {
            return (long) 0;
        }
    }
}

Andorid security MD5 hashing Class

A simple class, to create MD5 hashes with Java.

Note: MD5 is no longer secure, it should be used SHA1. If there is no way around it leads, Always use with Salt.

public class Security {
    
    private static final String TAG = Security.class.getSimpleName();

    public static String getMd5Hash(String string) {
        String result = null;
        byte[] defaultBytes = string.getBytes();
        
        MessageDigest algorithm;
        try {
            algorithm = java.security.MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(defaultBytes);
            byte messageDigest[] = algorithm.digest();
                    
            StringBuffer hexString = new StringBuffer();
            for (int i=0;i<messageDigest.length;i++) {
                    String hex = Integer.toHexString(0xFF & messageDigest[i]); 
                    if(hex.length()==1)
                    hexString.append('0');
                    hexString.append(hex);
            }
            result = hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            Log.e(TAG, "MD5 not available", e);
        }
        return result;                
    }
}

Java Corba Client Server Communications

Corba (Common Object Request Broker Architecture) is similar to RMI, only complicated and circumferential, which is also the reason, why it takes in practice only a small niche.

Based on a middleware (ORB – Object Request Broker), which is responsible for managing the service and the authentication of the user, Users can take advantage of services, running on another PC. The system has the following advantages:

  • OS independent
  • programming language independent, by the IDL (Interface Definition Language), With this interface, users can communicate with the middleware
  • skaliebar, Services can be easily replicated and resources (Server) be added, loose binding of services
  • migratable, because the ORB manages services of the name and not the IP, which of course is at the same URLs
  • concurrently, Processes run in their own threads
  • robust, through central Failure Handling
  • connectionless, Service can be used at any time, as often

more…