Friday, December 19, 2014

JSF 2.3 kick start

That's interesting! Hazem has just started to share with us posts about the new JSF 2.3. The bellow link shows how to build the JSF 2.3 JARs to start working with it from SVN.

http://www.technicaladvices.com/2014/12/19/jsf-2-3-part1-getting-started/

Stay tuned to the coming posts about the new features of the JSF 2.3.

Friday, December 5, 2014

Summarizing different ways to pass a parameter from a JSF page to the managed bean

Summarizing different ways to pass a parameter from a JSF page to the managed bean. So pick up the suitable one!
http://stackoverflow.com/a/4994833

Friday, November 28, 2014

Sunday, November 2, 2014

Define and use a datasource under the Websphere Application Server Liberty

Bellow how to define and use a datasource on your workspace.

  1. Create a directory be used as a shared lib for the Oracle JDBC JAR. For example C:\temp_jars and add the ojdbc14.jar and class12.jar to it.
  2. Open server.xml under the Websphere Application Server Liberty Profile and add the bellow two tags:
  3. <dataSource id="oracle" jndiName="jdbc/oracle">
        <jdbcDriver libraryRef="OracleLib"/>
        <properties.oracle URL="jdbc:oracle:thin:@//localhost:1521/test" password="{xor}KzosKw==" user="test"/>
    </dataSource><library description="Oracle JDBC Driver" id="OracleLib" name="Oracle JDBC">
        <fileset dir="C:\temp_jars" includes="ojdbc14.jar class12.jar"/>
    </library>
    
  4. Notice that the password attribute is encoded. You can encode the password through a security utility under the Websphere Application Server Liberty Profile bin directory.

    To use this utility to encode the "test" password, follow the bellow commands.
    cd <WLP_PATH>/wlp/bin
    securityUtility encode test
    
  5. Now inject the datasource at your DAO class as bellow:
  6. import javax.annotation.Resource;
    import javax.ejb.Stateless;
    import javax.sql.DataSource;
    
    @Stateless
    public class TestDAO implements ITestDAO {
    
        @Resource(lookup = "jdbc/oracle")
        private DataSource ds;
    
        // ... 
    }
    


Friday, October 31, 2014

Difference between @javax.annotation.ManagedBean,@javax.inject.Named and @javax.faces.ManagedBean

I was going to write about the difference between the annotations @javax.annotation.ManagedBean,@javax.inject.Named and @javax.faces.ManagedBean but I found that good answer about a common confusion of the difference between them.

http://stackoverflow.com/questions/11986847/java-ee-6-javax-annotation-managedbean-vs-javax-inject-named-vs-javax-faces

Monday, September 22, 2014

Setting Java to 1.6 after installing 1.7

I have JDK 1.6 installed on my machine. Then I installed JDK 1.7 and I ran the command "java -vesion" to check which version that my machine points to. The result was 1.7 version. I checked my PATH environment variable and it was pointing to the 1.6 version!
The problem was in the java.exe in under C:\Windows\System32. It was pointing to the 1.7. After deleting it, my machine default one is 1.6.

Friday, September 19, 2014

Another Codility task

Bellow is a Java implementation for a solution of the CountDistinctSlices problem that you can find under tasks the Caterpillar method lesson through this link https://codility.com/programmers/lessons/13. This solution has 100% correctness and it suffers in the performance as it is 40%.

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;


public class Solution {

 public int solution(int m, int[] a) {
  if(a.length >= 1000000000) {
   return a.length;
  }
  int cursor = 0;
  int count = a.length;
  HashSet check = new HashSet();
  List temp = new ArrayList();
  for(int y : a) {
   if(y>m) {
    continue;
   }
   temp.add(y);
  }
  
  a = new int[temp.size()];
     int i = 0;
     for (Integer e : temp)  
         a[i++] = e.intValue();
  
  for(int y = 0 ; y < a.length ; y++) {
   
   if(check.add(a[y])) {
    if(check.size() == 1)
     continue;
    count++;
    if(y+1 == a.length) {
     check.clear();
     cursor++;
     y=cursor-1;
    }
   } else {
    check.clear();
    cursor++;
    if(cursor > a.length) {
     break;
    }
    y=cursor-1;
    continue;
   }
  }
  return count;
 }
}

Develop your skills with Codility

As a programmer, Codility.com is a good tool that provide the programmers and developers a good chance to develop their programming skills. It provides programming lessons, readings and monthly interesting challenges for problems to solve in many programming languages such as Java, C#, C and others.
I believe that all of us should keep an eye on such arithmetic and mathematical problems that depends on the way you implement them using your preferred programming language so you can implement them correctly and efficiently. Beside considering the scientific evaluation for your code through considering time and efficiency complexity. This would help refreshing our minds in the way we implement different business problems and requirements in a way or another.
I have gone through some of its lessons that you can find in this link https://codility.com/programmers/lessons/ beside the readings they provided with the lessons. Each lesson contains some tasks that you can go through them to test your skill and develop them.
The first task of the first lesson is a Frog Jump problem . It was a good kick start to start that. You can find my solution implementation for it bellow.

class Solution {
 public static int solution(int x, int y, int d) {
  if (!(x <= y) || x == y) {
   return 0;
  }
  if (x >= 1 && x <= 1000000000 && y >= 1 && y <= 1000000000 && d >= 1
    && d <= 1000000000) {
   int result = (y - x) % d;
   if(result == 0) {
    return (y - x) / d;
   }
   else 
    return ((y - x) / d) + 1;
  }
  return 0;
 }
}


References:-
1- https://codility.com
2- https://codility.com/programmers/lessons/

Friday, August 8, 2014

Checking out JConsole JDK utility

There are many JDK utilities that you can find under the bin directory of the JDK installation on your machine. One of them is the JConsole which is a valuable GUI-based tool. JConsole is used to monitor and manage Java application whether on local or remote machine. Among many features, JConsole allows for viewing memory and threads usages. It was released with the marvelous J2SE 5.0.
For accessing the JConsole on Windows:
1- Start the command line console.
2- Navigate the bin directory under the JDK installation.
3- Type in the console jconsole.exe and press enter.
4- The GUI will start asking whether to access local machine or remote machine.

5- After connecting, the JConsole will show the many features you can use for monitoring.