Speaking in JavaLand Germany 2015

February 20, 2015 in JavaScript

Speaker in JavaLand 2015

Speaker in JavaLand 2015

@Wednesday, March 25 04:00 PM, I will be speaking in JavaLand Germany conference (that will be held from 24 March to 26 March @Brühl, Germany) about “Developing Mobile Applications using JavaScript”. My session will be a practical one, I will discuss mobile apps development using JavaScript and Apache Cordova. My session will also include Apache Cordova Integration tips with jQuery mobile on the three popular mobile platforms (Android, iOS and Windows Phone 8).

There is a JavaScript quiz at the end of my session, the one who will be able to answer it correctly will have a free copy of my new JavaScript book:
Books

I hope it will be an interesting session for all the mobile development passionate :):
https://www.doag.org/konferenz/konferenzplaner/konferenzplaner_details.php?locS=0&id=483801&vid=491546

Personally, it is my first time to visit Brühl, Germany, beside enjoying technical stuff, I would like to visit some tourist places there, any suggestions are welcome :D?

I really wish to see all of you there in JavaLand Germany 2015!

[JavaScript] Getting All Possible Combinations

February 16, 2015 in JavaScript

One of the most interesting mathematical stuff is Combination. A combination is a way of selecting members from a grouping, such that the order of selection does not matter (unlike permutation).

For example, assume that we have 6 balls (numbered from 1 to 6), and a person can select only 4 balls at a time.

Can you write a JavaScript function that can get all the possible 4 ball selections from the available 6 balls?

According to Combination, all the possible 4 ball selections from the 6 balls are (6 Choose 4) which equal to 15. The formula is very simple: n C r = n! / r! n-r!.

Now, let’s use recursion in order to get all the possible combinations.

var Util = function() {
};

Util.getCombinations = function(array, size, start, initialStuff, output) {
    if (initialStuff.length >= size) {
        output.push(initialStuff);
    } else {
        var i;
		
        for (i = start; i < array.length; ++i) {	
	    Util.getCombinations(array, size, i + 1, initialStuff.concat(array[i]), output);
        }
    }
}

Util.getAllPossibleCombinations = function(array, size, output) {
    Util.getCombinations(array, size, 0, [], output);
}

As shown in Util.getAllPossibleCombinations, it takes five parameters as follows:
1. array parameter represents the array of objects that we have.
2. size parameter represents the size of every selection from the array.
3. start parameter represents the current start index.
4. initialStuff parameter represents a temp array that holds every possible combination.
5. output parameter represents the array that holds all the possible arrays of combinations.

In order to know all the possible 4 balls selections from the available 6 balls, you can call the API simply as follows:

// Create an array that holds numbers from 1 ... 6.
var array = [];

for (var i = 1; i <= 6; ++i) {
    array[i - 1] = i;
}

var output = [];

// Select only 4 balls out of the 6 balls at a time ...
Util.getAllPossibleCombinations(array, 4, output);
console.log(output);

In the console, you will find all the possible 15 combinations as follows:

[[1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 3, 6], [1, 2, 4, 5], [1, 2, 4, 6], [1, 2, 5, 6], [1, 3, 4, 5], [1, 3, 4, 6], [1, 3, 5, 6], [1, 4, 5, 6], [2, 3, 4, 5], [2, 3, 4, 6], [2, 3, 5, 6], [2, 4, 5, 6], [3, 4, 5, 6]]

Cool mobile apps for developers

January 21, 2015 in mobile

In the past, only desktops or laptops could be used to create computer programs. However, thanks to technological advancements, today’s smartphones can now be used in the creation of software.

Mobile apps that can be used to create programs on the go were made in order to hasten the development process of apps, which is quite possibly the most lucrative business today. In a study featured on entertainment site Pocket Fruity, it was discussed that more and more people take their smartgadgets wherever they go, may it be at a train station, on a bus, or in a pub. Since the app-making industry is extremely cutthroat, developers created an edge in the form of apps in order to beat deadlines even when they’re not at their workstations.

Here are two useful mobile apps for the web devs out there.

The C Programming Language App

This is one of the best apps for the C programmers out there. It is a handy app for scribbling down codes as well as checking codes thanks to its Reference Tab. The reference tab has links to the language reference, string library, math library, and standard library.

The C Programming Language has a feature that allows developers to test whether or not a program will run smoothly on a chosen platform. It also allows users to easily send their codes via email once they’re done. The app can be used for free by iOS users.

JavaScript Anywhere

JavaScript Anywhere is a three-in-one app that acts as a Java Script, CSS, and HTML editor. It has a very simply user interface so developers can get the hang of using it quickly. Like the C Programming Language App, JavaScript Anywhere allows users to check whether or not their program will work smoothly. Users can import saved projects via the Internet and even store their work on Dropbox for backup. Jsany can also be downloaded for free by iOS users.

Review #2 about the “JavaScript Mobile Application Development” Book

January 5, 2015 in Apache Cordova, Book, Reviews

Attached below the review of Safwat about the “JavaScript Mobile Application Development” book:

JavaScript Mobile Application Development Book

JavaScript Mobile Application Development Book





Excellent

“The book is an easy and comprehensive guide to whoever is interested in multi platform mobile development with examples it shows the full life cycle of developing mobile cordova apps.”





Reference:

http://www.amazon.com/review/R2N5YBCWJK44V2/

The book in Amazon:

http://www.amazon.com/JavaScript-Mobile-Application-Development-Hazem/dp/1783554177/

“Pro JSF and HTML5″ Book Review by Werner Punz

January 1, 2015 in Book, JSF, Reviews

Attached below the review of Werner Punz (Senior software developer for Irian GmbH, Apache MyFaces Committer, and a member of the JSF Expert Group) about the “Pro JSF and HTML5″ book:

Pro JSF and HTML5 Book

Pro JSF and HTML5 Book

Good but not perfect

“The book itself is a crash course in JSF with extensive JSF 2.2 coverage and component coverage.

The first part of the book is an introduction into JSF and JSF 2.2, the second part walks you through component creation the third part covers two of the most widely used component libs and the fourth part walks you through an entire JSF application utilizing Java EE 7.

Well what should I say, while I wished some parts were covered more deeply, like the already extensive component creation part or the Java EE application walk-through which should have gotten more explanatory coverage in the Java EE area, I personally guess that the book as JSF 2.2 reference and as a tutorial book for JSF fulfills its purpose very well.

The problem I see simply is if you want to cover component creation for JSF on its own with all the special cases for different component types, you probably need a book on its own, the same goes for a full blown Java EE application with all its little details on which pattern to apply where and why, this would be also another book which then should omit the JSF tutorial part.

I will give the book 4 stars as very good JSF 2.2 and component creation reference and good JSF tutorial, but one star less due to the lack of depth especially in the application walk-through which should have gotten a bit more explanation on the Java EE side of things.”

Reference:

http://www.amazon.com/review/R1RQKD0WJN7QDB

The book in Amazon:

http://www.amazon.com/Pro-JSF-HTML5-Building-Components/dp/1430250100

Review #1 about the “JavaScript Mobile Application Development” Book

December 29, 2014 in Apache Cordova, Book, Reviews

Attached below the review of Zubin Wadia (the CEO & Co-Founder of CiviGuard, Inc, CEO & Co-Founder of RedRock IT Solutions, and Chief Technology Officer at ImageWork Technologies) about the “JavaScript Mobile Application Development” book:

JavaScript Mobile Application Development Book

JavaScript Mobile Application Development Book

A fine guide for web and native developers alike!

“Fabulous coverage of a powerful and mature cross-platform library. The book goes through the basics over the first five chapters, making sure native app developers aren’t alienated by the diaspora of HTML5/CSS3 web standards out there. A web developer will find that the book truly gets into its stride via the 5th, 6th, 7th and 8th chapters – which cover advanced Cordova API calls, platform specific code for iOS/Android/WinPhone, unit testing (critical) and finally a “Mega App” that puts your knowledge through some practical pacing.”






Reference:

http://www.amazon.com/review/R33GUDCXH5787J

The book in Amazon:

http://www.amazon.com/JavaScript-Mobile-Application-Development-Hazem/dp/1783554177/

JSF 2.3 Part2, Using @inject for FacesContext

December 21, 2014 in JSF

One of the wonderful features of the upcoming JSF 2.3 is the ability to inject many JSF objects such as UIViewRoot, ViewMap, ApplicationMap, ExternalContext and FacesContext. In this post, I will show you how to simply inject FacesContext without having to use the old way FacesContext.getCurrentInstance().

Continuing working on the sample that was introduced in the previous post, let’s modify User managed bean to get FacesContext in order to display an information message to the user once the operation is done. The following code snippet shows the modified User managed bean.

package beans;

import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@RequestScoped
public class User implements Serializable {
    private static final long serialVersionUID = 4629817047379532658L;
    private static final String INFO_MESSAGE = "Operation is done ...";
        
    private String name;
    
    @Inject
    FacesContext facesContext;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String greet() {
        facesContext.addMessage("form1", new FacesMessage(FacesMessage.SEVERITY_INFO, INFO_MESSAGE, INFO_MESSAGE));
        
        return null;
    }
}

As shown, all what you need to inject FacesContext in your managed bean is to annotate its declared instance with @inject annotation.

Running Application on GlassFish 4.1

In order to run our JSF application this time on GlassFish, we need to build Mojarra jars for GlassFish and then configure them on the server as follows:

  1. First of all, you need to make sure that you have both SVN and Apache Ant installed and configured in your operating system.
  2. Check out Mojarra 2.3 source code using the following SVN command:
    svn checkout https://svn.java.net/svn/mojarra~svn/trunk

    In order to build the JSF Mojarra jars for GlassFish then create a new file called build.properties under trunk. Then copy build.properties.glassfish file (which is located directly under trunk) content into it. Do not forget to set jsf.build.home property to the directory in which the sources were checked out into as follows for example.

    # --------------------------------------------------
    # Set this to the directory in which the sources
    # were checked out into
    # --------------------------------------------------
    jsf.build.home=/Users/hazems/projects/mojarra23/trunk
  3. CD to the jsf.build.home path, and then execute the following ant command:
    ant clean main
  4. After the successful execution of the previous command, you can get Mojarra jars from:
    1. jsf-api-intermediate.jar from trunk/jsf-api/build/lib directory.
    2. javax.faces.jar from trunk/jsf-ri/build/lib directory.
  5. Finally, overwrite the default javax.faces.jar file under glassfish-4.1/glassfish/modules with the new built javax.faces.jar file, and deploy our JSF application to GlassFish. After running our JSF application, you can see the information message after clicking "Greet" button as shown below.
    Screen Shot 2014-12-21 at 4.03.07 AM

Getting the JSF sample source code:

The sample source code is available in GitHub:
https://github.com/hazems/jsf2.3-work/tree/master/sampleJSF2

JSF 2.3 Part1, Getting Started

December 19, 2014 in JSF

It is really not so early to start working with the upcoming JSF 2.3 and testing it. In this post, I will show you how to get started in JSF 2.3 by building JSF (Mojarra) jars from its source then use them for your JSF 2.3 application which will run in Tomcat 7.

Building JSF Jars from SVN:

  1. First of all, you need to make sure that you have both SVN and Apache Ant installed and configured in your operating system.
  2. Check out the source code using the following SVN command:
    svn checkout https://svn.java.net/svn/mojarra~svn/trunk
    
  3. In order to build the JSF Mojarra jars for Apache Tomcat then create a new file called build.properties under trunk. Then copy build.properties.tomcat file (which is located directly under trunk) content into it. Do not forget to set jsf.build.home property to the directory in which the sources were checked out into as follows for example.
    # --------------------------------------------------
    # Set this to the directory in which the sources
    # were checked out into
    # --------------------------------------------------
    jsf.build.home=/Users/hazems/projects/mojarra23/trunk
    
  4. CD to the jsf.build.home path, and then execute the following ant command:
    ant clean main
    
  5. After the successful execution of the previous command, you can get Mojarra jars from:
    1. jsf-api-intermediate.jar from trunk/jsf-api/build/lib directory.
    2. javax.faces.jar from trunk/jsf-ri/build/lib directory.

Configuring your first JSF 2.3 application:

Simply all what you need to work with JSF 2.3 in Tomcat 7 is to do the following:

  • Place the two Mojarra jars in step 4 in your web application WEB-INF/lib folder.
  • Set the JSF version in the faces-config.xml to 2.3 as follows.
    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config version="2.3"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_3.xsd"> 
    </faces-config>
    
  • Then now, you can write your JSF application and it will be powered by the upcoming JSF 2.3. I made a very basic JSF 2.3 sample which you can reach its code in the following GitHub URL:
    https://github.com/hazems/jsf2.3-work/tree/master/sampleJSF1
  • Screen Shot 2014-12-20 at 1.07.36 AM

    In my next JSF 2.3 posts, I will show you some of the JSF 2.3 implemented features “so far” in order to allow you to start working with them so stay tuned.

    Tip #4: Storing Media Files Properly in Cordova iOS apps

    December 15, 2014 in Apache Cordova, iOS

    In order to avoid being surprised by the loss of your recorded audio file in iOS, you should be aware of how to properly record and store a media file in Cordova iOS.
    Generally, in order to record an audio file in Apache Cordova, you can use the Cordova Media object as follows:

    var recordingMedia = new Media(mediaFilePath, recordingSuccess, recordingError);
    
    // Start Recording Audio
    recordingMedia.startRecord();
    
    // Stop Recording Audio
    recordingMedia.stopRecord();
    
    // Release Media resource
    recordingMedia.release();
    

    As shown in the code above, in order to record an audio file in Apache Cordova, you need to do the following:

    1. Create a Media object (recordingMedia) and specify mediaFilePath (the path of the audio file), recordingSuccess (the success callback which will be called if the media operation succeeds), recordingError (the error callback which will be called if the media operation fails).
    2. Start recording the audio by calling recordingMedia.startRecord().
    3. After completing the audio recording, call recordingMedia.stopRecord() and then release the used Media object by calling recordingMedia.release()

    In iOS, if you set mediaFilePath to the audio file name only without specifying any path (e.g "test.wav"), you may be surprised to find your audio file stored under the iOS app’s tmp directory (which is located under the iOS app’s sandbox directory). It is very important to be aware that the iOS app’s tmp directory content can be deleted automatically by iOS at anytime by iOS.

    In order to avoid losing your app’s recorded files, just place the "documents://" prefix before the audio file name as follows.

    var recordingMedia = new Media("documents://test.wav", recordingSuccess, recordingError);
    

    Doing this will make the recorded audio file stored under the iOS app’s Documents directory. The iOS app’s Documents directory is located under the app’s sandbox directory and is suitable for storing the app files.

    Reference:

    “JavaScript Mobile Application Development” Book: