Translate

Friday, 29 November 2013

Apple iPhone 5s vs Google Nexus 5

If you are looking for a unbiased comparison between the Apple iPhone 5s and Google Nexus 5 you have come to just the right place.
Nexus 5
iPhone 5s
Processor
The CPU here is the powerful Qualcomm Snapdragon 800 which is a 4 core processor that enables the device to perform at 2.26Ghz. The Snapdragon is among the fastest of its other family members such as the Snapdragon 600 or Snapdragon 400.
       The Qualcomm family of processors also appears in handsets like the Xperia Z1 from Sony, G2 from LG, HTC One from HTC, Lumia 1020 from Nokia, Galaxy mega from Samsung. The Processor is fast and reliable. For more info on this processor follow this Link.
our rating is 4.5 stars
1.3GHz dual-core A7 processor powers the new iPhone 5s. If you assume that iPhone has lost this round, you couldn't be more wrong. Apple has introduced a 64bit processor architecture which is a new concept among other rivals. The mobile processor industry has clearly stepped in the next generation of mobile computing with the arrival of this processor.
       The arrival of this processor in the market has paved a way for the development of 64bit applications and enabled the mobile devices to operate on as much as 4GB of RAM. Rumors have it that Galaxy S5  will also have a 64bit processor be it from Qualcomm or any other vendor. During several tests that were conducted , iPhone beat the competition like Samsung S4 and LG G2.
our rating is 4.8 stars


RAM and Storage
The RAM in this device is 2GB, with which the device handles multiple tasks seamlessly. The Storage in GB comes in 2 different versions: the 16GB and the 32GB.
our rating is 5 stars.
The RAM in this device is 1GB, which is clearly less than Nexus 5 but the processor seems to make up for this loss too. The Storage in GB comes in 3 different versions: the 16GB, the 32GB and the 64GB.
our rating is 3.5 stars.

Sensors
GPS
Gyroscope
Accelerometer
Compass
Proximity/Ambient Light
Pressure
Hall
our rating is 3.5 stars
GPS
Three-axis gyro
Accelerometer
Proximity/Ambient light sensor
Fingerprint identity sensor
our rating is 4.4 stars

Dimensions, Power and Connectivity
137.84mm Height 69.17mm Weight 8.59mm Depth 130gm Weight 2300 mAh battery with wireless charging. 2G/3G/4G LTE
GSM: 850/900/1800/1900 MHz
Model LG-D820 (North America)
CDMA band class: 0/1/10
WCDMA bands: 1/2/4/5/6/8/19
LTE bands: 1/2/4/5/17/19/25/26/41
Model LG-D821 (Rest of World)
WCDMA bands: 1/2/4/5/6/8
LTE bands: 1/3/5/7/8/20

our rating is 4.2 stars
123.8mm Height 58.6mm Width 7.6mm Depth 112gm Weight 1570mAh battery. The networks supported include GSM, CDMA, 3G, EVDO, LTE, HSPA+.
our rating is 3.8 stars
Screen
4.95" 1920 x 1080 display (445 ppi) Full HD IPS Corning® Gorilla® Glass 3
our rating is 4.2 stars
4" (diagonal) widescreen Multi‑Touch display 1136 x 640 pixel resolution at 326 ppi.
our rating is 4.1 stars

Camera
1.3MP front facing
8MP rear facing
our rating is 3.5 stars
1.2MP front facing
8MP rear facing
our rating is 3.4 stars

Total scores
Total rating is 24.9 Total rating is 24

Thursday, 28 November 2013

Learn Hibernate Quick

Before we proceed with Hibernate it is important to understand 2 basic concepts: ORM and RDBMS.
ORM stands for Object-Relational Mapping (ORM) is a programming technique for converting data between relational databases and object oriented programming languages such as Java, C# etc.
Examples of ORM:

  • Hibernate
  • TopLink
  • Castor

RDBMSs represent data in a tabular format whereas object-oriented languages, such as Java or C# represent it as an interconnected graph of objects.
                Hibernate is an ORM created by Gavin King in 2001. Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities. Hibernate works best with POJO.
                Hibernate is a popular framework with many advantages over traditional RDBMSs. Few of the important ones are listed below:
Advantages of Hibernate include:

  1. Fast development of application
  2. Hides details of SQL queries from OO logic
  3. No need to deal with the database implementation.
  4. Takes care of Transaction management.

    Hibernate Architecture

JNDI and JTA allow Hibernate to be integrated with J2EE application servers.

Configuration Object
The Configuration object provides two keys components:
Database Connection: This is handled through one or more configuration files supported by Hibernate. These files are hibernate.properties and hibernate.cfg.xml(an example file is given below).

hibernate.cfg.xml example
-------------------------------------------------------------------------------------------------------------------------
<hibernate-configuration>
   <session-factory>
      <property name="hibernate.dialect">
         org.hibernate.dialect.MySQLDialect
      </property>
      <property name="hibernate.connection.driver_class">
         com.mysql.jdbc.Driver
      </property>

<!-- Assume test is the database name -->
      <property name="hibernate.connection.url">
         jdbc:mysql://localhost/test
      </property>
      <property name="hibernate.connection.username">
         root
      </property>
      <property name="hibernate.connection.password">
         root
      </property>

<!-- List of XML mapping files -->
      <mapping resource="Employee.hbm.xml"/>
   </session-factory>
</hibernate-configuration>
-------------------------------------------------------------------------------------------------------------------------

Class Mapping Setup
This component creates the connection between the Java classes and database tables..

SessionFactory Object
Configuration object is used to create a SessionFactory object which inturn configures Hibernate for the application using the supplied configuration file and allows for a Session object to be instantiated.
The SessionFactory is heavyweight object so usually it is created during application start up and kept for later use. One SessionFactory object per database using a separate configuration file is made. So while using multiple databases multiple SessionFactory objects need to be created.

Session Object
A Session is used to get a physical connection with a database. The Session object is lightweight and designed to be instantiated each time an interaction is needed with the database. It must be opened and closed as the requirement, should not be kept open for a long time as it is not thread safe.

Query Object
Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and create objects. A Query instance is used to bind query parameters, limit the number of results returned by the query, and finally to execute the query.

Hibernate Mapping
This is where the classes are mapped onto tables of databases.
A Hibernate mapping file usually has the name: <name-of-the-class-to-be-mapped>.hbm.xml
The contents of a hibernate mapping file generally look like this:

<hibernate-mapping>
   <class name="Employee" table="OFFICEEMPLOYEE">
      <meta attribute="class-description">
         This class contains the employee detail.
      </meta>
      <id name="id" type="int" column="id">
         <generator class="native"/>
      </id>
      <property name="firstName" column="first_name" type="string"/>
      <property name="lastName" column="last_name" type="string"/>
      <property name="salary" column="salary" type="int"/>
   </class>
</hibernate-mapping>

Here the class being mapped is Employee to a table named OFFICEEMPLOYEE.
We then start mapping class variables to the table columns. The name of this file should be Employee.hbm.xml

Application Class (has main method to use the hibernate setup we just created)
General structure of code in main method of application class
------------------------------------------------------------------------------------------------------------------------
Session session = factory.openSession();
Transaction tx = null;
try {
   tx = session.beginTransaction();
   // do some work...
   tx.commit();
}
catch (Exception e) {
   if (tx!=null) tx.rollback();
   e.printStackTrace();
}finally {
   session.close();
}
---------------------------------------------For more info. about Session interface refer this Link.----
               
               
----Follow the code below to create the factory Object from Configuration object.---------------
try{
         factory = new Configuration().configure().buildSessionFactory();
      }catch (Throwable ex) {
         System.err.println("Failed to create sessionFactory object." + ex);
         throw new ExceptionInInitializerError(ex);
      }
-------------------------------------------------------------------------------------------------------------------------

-------------TO MAKE AN ENTRY FOR A NEW EMPLOYEE---------------------------------------
Session session = factory.openSession();
      Transaction tx = null;
      Integer employeeID = null;
      try{
         tx = session.beginTransaction();
         Employee employee = new Employee(fname, lname, salary);
         employeeID = (Integer) session.save(employee);
         tx.commit();
      }
    catch (HibernateException e) {
         if (tx!=null){
             tx.rollback();       
         }
         e.printStackTrace();
      }finally {
         session.close();
      }
-------------------------------------------------------------------------------------------------------------------------

----------TO READ ALL THE EMPLOYEES--------------------------------------------------------------
Session session = factory.openSession();
      Transaction tx = null;
      try{
         tx = session.beginTransaction();
         List employees = session.createQuery("FROM Employee").list();
         for (Iterator iterator = employees.iterator(); iterator.hasNext();){
            Employee employee = (Employee) iterator.next();
            System.out.print("First Name: " + employee.getFirstName());
            System.out.print("  Last Name: " + employee.getLastName());
            System.out.println("  Salary: " + employee.getSalary());
         }
         tx.commit();
      }catch (HibernateException e) {
         if (tx!=null) tx.rollback();
         e.printStackTrace();
      }finally {
         session.close();
      }
------------------------------------------------------------------------------------------------------------------------

----------Using Hibernate 3.0 with Annotations-------------------------------------------------------------
above class name
    @Entity
    @Table(name="OFFICEEMPLOYEE")

above class variables name
    @Column(name="id")
    @GeneratedValue
    @Id

Only the factory object needs to be altered in case of using annotations, rest all remains the same
factory = new AnnotationConfiguration().configure().
               //addPackage("com.xyz") //add package if used.
               addAnnotatedClass(Employee.class).
               buildSessionFactory();

------------------------------------------------------------------------------------------------------------------------
HQL (Hibernate Query Language)
lets see some examples to understand hibernate query language.
eg1:    String hql = "SELECT E.firstName FROM Employee E";
It should be noted here that Employee.firstName is a property of Employee object rather than a field of the OFFICEEMPLOYEE table.

eg2:     String hql = "UPDATE Employee set salary = :salary " + "WHERE id = :employee_id";
            Query query = session.createQuery(hql);
            query.setParameter("salary", 1000);
            query.setParameter("employee_id", 10);
            int result = query.executeUpdate();
--------------------------------------------------------------------------------------------------------------------------