Tuesday, 5 November 2013

JAVA - objects, classes

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts:
  • Polymorphism
  • Inheritance
  • Encapsulation
  • Abstraction
  • Classes
  • Objects
  • Instance
  • Method
  • Message Parsing
In this chapter, we will look into the concepts Classes and Objects.
  • Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
  • Class - A class can be defined as a template/blue print that describes the behaviors/states that object of its type support.

Objects in Java:

Let us now look deep into what are objects. If we consider the real-world we can find many objects around us, Cars, Dogs, Humans, etc. All these objects have a state and behavior.
If we consider a dog, then its state is - name, breed, color, and the behavior is - barking, wagging, running
If you compare the software object with a real world object, they have very similar characteristics.
Software objects also have a state and behavior. A software object's state is stored in fields and behavior is shown via methods.
So in software development, methods operate on the internal state of an object and the object-to-object communication is done via methods.

Classes in Java:

A class is a blue print from which individual objects are created.
A sample of a class is given below:
public class Dog{
   String breed;
   int age;
   String color;

   void barking(){
   }
   
   void hungry(){
   }
   
   void sleeping(){
   }
}
A class can contain any of the following variable types.
  • Local variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.
  • Instance variables: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.
  • Class variables: Class variables are variables declared with in a class, outside any method, with the static keyword.
A class can have any number of methods to access the value of various kinds of methods. In the above example, barking(), hungry() and sleeping() are methods.
Below mentioned are some of the important topics that need to be discussed when looking into classes of the Java Language.

Constructors:

When discussing about classes, one of the most important sub topic would be constructors. Every class has a constructor. If we do not explicitly write a constructor for a class the Java compiler builds a default constructor for that class.
Each time a new object is created, at least one constructor will be invoked. The main rule of constructors is that they should have the same name as the class. A class can have more than one constructor.
Example of a constructor is given below:
public class Puppy{
   public puppy(){
   }

   public puppy(String name){
      // This constructor has one parameter, name.
   }
}
Java also supports Singleton Classes where you would be able to create only one instance of a class.

Creating an Object:

As mentioned previously, a class provides the blueprints for objects. So basically an object is created from a class. In Java, the new key word is used to create new objects.
There are three steps when creating an object from a class:
  • Declaration: A variable declaration with a variable name with an object type.
  • Instantiation: The 'new' key word is used to create the object.
  • Initialization: The 'new' keyword is followed by a call to a constructor. This call initializes the new object.
Example of creating an object is given below:
public class Puppy{

   public Puppy(String name){
      // This constructor has one parameter, name.
      System.out.println("Passed Name is :" + name ); 
   }
   public static void main(String []args){
      // Following statement would create an object myPuppy
      Puppy myPuppy = new Puppy( "tommy" );
   }
}
If we compile and run the above program, then it would produce the following result:
Passed Name is :tommy

Accessing Instance Variables and Methods:

Instance variables and methods are accessed via created objects. To access an instance variable the fully qualified path should be as follows:
/* First create an object */
ObjectReference = new Constructor();

/* Now call a variable as follows */
ObjectReference.variableName;

/* Now you can call a class method as follows */
ObjectReference.MethodName();

Example:

This example explains how to access instance variables and methods of a class:
public class Puppy{
   
   int puppyAge;

   public Puppy(String name){
      // This constructor has one parameter, name.
      System.out.println("Passed Name is :" + name ); 
   }
   public void setAge( int age ){
       puppyAge = age;
   }

   public int getAge( ){
       System.out.println("Puppy's age is :" + puppyAge ); 
       return puppyAge;
   }
   public static void main(String []args){
      /* Object creation */
      Puppy myPuppy = new Puppy( "tommy" );

      /* Call class method to set puppy's age */
      myPuppy.setAge( 2 );

      /* Call another class method to get puppy's age */
      myPuppy.getAge( );

      /* You can access instance variable as follows as well */
      System.out.println("Variable Value :" + myPuppy.puppyAge ); 
   }
}
If we compile and run the above program, then it would produce the following result:
Passed Name is :tommy
Puppy's age is :2
Variable Value :2

Source file declaration rules:

As the last part of this section let's now look into the source file declaration rules. These rules are essential when declaring classes, import statements and package statements in a source file.
  • There can be only one public class per source file.
  • A source file can have multiple non public classes.
  • The public class name should be the name of the source file as well which should be appended by .java at the end. For example : The class name is . public class Employee{} Then the source file should be as Employee.java.
  • If the class is defined inside a package, then the package statement should be the first statement in the source file.
  • If import statements are present then they must be written between the package statement and the class declaration. If there are no package statements then the import statement should be the first line in the source file.
  • Import and package statements will imply to all the classes present in the source file. It is not possible to declare different import and/or package statements to different classes in the source file.
Classes have several access levels and there are different types of classes; abstract classes, final classes, etc. I will be explaining about all these in the access modifiers chapter.
Apart from the above mentioned types of classes, Java also has some special classes called Inner classes and Anonymous classes.

Java Package:

In simple, it is a way of categorizing the classes and interfaces. When developing applications in Java, hundreds of classes and interfaces will be written, therefore categorizing these classes is a must as well as makes life much easier.

Import statements:

In Java if a fully qualified name, which includes the package and the class name, is given then the compiler can easily locate the source code or classes. Import statement is a way of giving the proper location for the compiler to find that particular class.
For example, the following line would ask compiler to load all the classes available in directory java_installation/java/io :
import java.io.*;

A Simple Case Study:

For our case study, we will be creating two classes. They are Employee and EmployeeTest.
First open notepad and add the following code. Remember this is the Employee class and the class is a public class. Now, save this source file with the name Employee.java.
The Employee class has four instance variables name, age, designation and salary. The class has one explicitly defined constructor, which takes a parameter.
import java.io.*;
public class Employee{
   String name;
   int age;
   String designation;
   double salary;
 
   // This is the constructor of the class Employee
   public Employee(String name){
      this.name = name;
   }
   // Assign the age of the Employee  to the variable age.
   public void empAge(int empAge){
      age =  empAge;
   }
   /* Assign the designation to the variable designation.*/
   public void empDesignation(String empDesig){
      designation = empDesig;
   }
   /* Assign the salary to the variable salary.*/
   public void empSalary(double empSalary){
      salary = empSalary;
   }
   /* Print the Employee details */
   public void printEmployee(){
      System.out.println("Name:"+ name );
      System.out.println("Age:" + age );
      System.out.println("Designation:" + designation );
      System.out.println("Salary:" + salary);
   }
}
As mentioned previously in this tutorial, processing starts from the main method. Therefore in-order for us to run this Employee class there should be main method and objects should be created. We will be creating a separate class for these tasks.
Given below is the EmployeeTest class, which creates two instances of the class Employee and invokes the methods for each object to assign values for each variable.
Save the following code in EmployeeTest.java file
import java.io.*;
public class EmployeeTest{

   public static void main(String args[]){
      /* Create two objects using constructor */
      Employee empOne = new Employee("James Smith");
      Employee empTwo = new Employee("Mary Anne");

      // Invoking methods for each object created
      empOne.empAge(26);
      empOne.empDesignation("Senior Software Engineer");
      empOne.empSalary(1000);
      empOne.printEmployee();

      empTwo.empAge(21);
      empTwo.empDesignation("Software Engineer");
      empTwo.empSalary(500);
      empTwo.printEmployee();
   }
}
Now, compile both the classes and then run EmployeeTest to see the result as follows:
C :> javac Employee.java
C :> vi EmployeeTest.java
C :> javac  EmployeeTest.java
C :> java EmployeeTest
Name:James Smith
Age:26
Designation:Senior Software Engineer
Salary:1000.0
Name:Mary Anne
Age:21
Designation:Software Engineer
Salary:500.0

JAVA features

When we consider a Java program it can be defined as a collection of objects that communicate via invoking each other's methods. Let us now briefly look into what do class, object, methods and instance variables mean.
  • Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
  • Class - A class can be defined as a template/ blue print that describes the behaviors/states that object of its type support.
  • Methods - A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
  • Instance Variables - Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.


    Basic Syntax:

    About Java programs, it is very important to keep in mind the following points.
  • Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.
  • Class Names - For all class names the first letter should be in Upper Case.

    If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.

    Example class MyFirstJavaClass
  • Method Names - All method names should start with a Lower Case letter.

    If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.

    Example public void myMethodName()
  • Program File Name - Name of the program file should exactly match the class name.

    When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile).

    Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java'
  • public static void main(String args[]) - Java program processing starts from the main() method which is a mandatory part of every Java program..

Java Identifiers:

All Java components require names. Names used for classes, variables and methods are called identifiers.
In Java, there are several points to remember about identifiers. They are as follows:
  • All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).
  • After the first character identifiers can have any combination of characters.
  • A key word cannot be used as an identifier.
  • Most importantly identifiers are case sensitive.
  • Examples of legal identifiers: age, $salary, _value, __1_value
  • Examples of illegal identifiers: 123abc, -salary

Java Modifiers:

Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers:
  • Access Modifiers: default, public , protected, private
  • Non-access Modifiers: final, abstract, strictfp
We will be looking into more details about modifiers in the next section.

Java Variables:

We would see following type of variables in Java:
  • Local Variables
  • Class Variables (Static Variables)
  • Instance Variables (Non-static variables)

Java Arrays:

Arrays are objects that store multiple variables of the same type. However, an array itself is an object on the heap. We will look into how to declare, construct and initialize in the upcoming chapters.

Java Enums:

Enums were introduced in java 5.0. Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums.
With the use of enums it is possible to reduce the number of bugs in your code.
For example, if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium and large. This would make sure that it would not allow anyone to order any size other than the small, medium or large.

Example:

class FreshJuice {

   enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }
   FreshJuiceSize size;
}

public class FreshJuiceTest {

   public static void main(String args[]){
      FreshJuice juice = new FreshJuice();
      juice.size = FreshJuice. FreshJuiceSize.MEDIUM ;
      System.out.println("Size: " + juice.size);
   }
}
Above example will produce the following result:
Size: MEDIUM
Note: enums can be declared as their own or inside a class. Methods, variables, constructors can be defined inside enums as well.

Java Keywords:

The following list shows the reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names.
abstractassertbooleanbreak
bytecasecatchchar
classconstcontinuedefault
dodoubleelseenum
extendsfinalfinallyfloat
forgotoifimplements
importinstanceofintinterface
longnativenewpackage
privateprotectedpublicreturn
shortstaticstrictfpsuper
switchsynchronizedthisthrow
throwstransienttryvoid
volatilewhile

Comments in Java

Java supports single-line and multi-line comments very similar to c and c++. All characters available inside any comment are ignored by Java compiler.
public class MyFirstJavaProgram{

   /* This is my first java program.
    * This will print 'Hello World' as the output
    * This is an example of multi-line comments.
    */

    public static void main(String []args){
       // This is an example of single line comment
       /* This is also an example of single line comment. */
       System.out.println("Hello World"); 
    }
} 

Using Blank Lines:

A line containing only whitespace, possibly with a comment, is known as a blank line, and Java totally ignores it.

Inheritance:

In Java, classes can be derived from classes. Basically if you need to create a new class and here is already a class that has some of the code you require, then it is possible to derive your new class from the already existing code.
This concept allows you to reuse the fields and methods of the existing class without having to rewrite the code in a new class. In this scenario the existing class is called the superclass and the derived class is called the subclass.

Interfaces:

In Java language, an interface can be defined as a contract between objects on how to communicate with each other. Interfaces play a vital role when it comes to the concept of inheritance.
An interface defines the methods, a deriving class(subclass) should use. But the implementation of the methods is totally up to the subclass.



JAVA - Its history and features

Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]).
As of December 2008, the latest release of the Java Standard Edition is 6 (J2SE). With the advancement of Java and its widespread popularity, multiple configurations were built to suite various types of platforms. Ex: J2EE for Enterprise Applications, J2ME for Mobile Applications.
Sun Microsystems has renamed the new J2 versions as Java SE, Java EE and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere.
Java is:
  • Object Oriented: In Java, everything is an Object. Java can be easily extended since it is based on the Object model.
  • Platform independent: Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.
  • Simple:Java is designed to be easy to learn. If you understand the basic concept of OOP Java would be easy to master.
  • Secure: With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.
  • Architectural-neutral :Java compiler generates an architecture-neutral object file format which makes the compiled code to be executable on many processors, with the presence of Java runtime system.
  • Portable:Being architectural-neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability boundary which is a POSIX subset.
  • Robust:Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.
  • Multithreaded: With Java's multithreaded feature it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications.
  • Interpreted:Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light weight process.
  • High Performance: With the use of Just-In-Time compilers, Java enables high performance.
  • Distributed:Java is designed for the distributed environment of the internet.
  • Dynamic: Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

Second opinion on Leap Motion


Leap Motion controller review
When the Leap Motion controller was revealed to the world, it brought with it the promise of a new and unique computer user experience. And, ever since we first got to see what the Leap Motion controller could do -- grant folks the ability to interact with a computer by waving their fingers and fists -- we've wanted one of our own to test out. Well, our wish was granted: we've gotten to spend several days with the controller and a suite of apps built to work with it. Does the device really usher in a new age of computing? Is it worth $80 of your hard-earned cash? Patience, dear reader, all will be revealed in our review.

The Leap hardware is actually quite unassuming, considering its capabilities. It's just over three inches long, an inch wide and less than a half-inch thick (79 x 30 x 11mm), with a glossy black panel on top, behind which resides the infrared sensors. On the bottom, you'll find a black rubber panel embossed with the Leap Motion logo. The edge, meanwhile, is ringed with a seamless aluminum band, save for a USB 3.0 Micro-B port on the left side (though the device runs at USB 2.0 speeds). There's also a slim LED power / status indicator on the front edge. Alas, as of this writing, the company wasn't able to reveal more specifics about the internals themselves, thanks to pending patent considerations. Along with the controller itself, users get a pair of USB 3.0 cables in the box -- a 5-foot and a 2-foot cord.
Keep in mind, the Leap is different from a Kinect sensor bar in more than just its size and appearance. Leap works using infrared optics and cameras instead of depth, and does not cover as large an area as Microsoft's motion controller. Leap does its motion sensing at a fidelity unmatched by any depth camera currently available: it can track all 10 of your fingers simultaneously to within a hundredth of a millimeter with a latency lower than the refresh rate on your monitor. Of course, that tracking ability isn't just about the hardware, and the capabilities of the Leap are only realized by the software built to work with it.
Leap Motion controller review
Setting up the Leap is a straightforward affair. Simply plug one end into the laptop, the other into the controller and position it in a location where it can see your hands; in front of a laptop or between a desktop keyboard and screen generally works. Once you're plugged in, you'll see the green LED on the front of the device and the infrared LEDs beneath the top plate come to life. From there, it's a matter of downloading the appropriate Windows or Mac Leap Motion software suite (consumers will be prompted automatically to do this upon connecting the device). That download includes both a diagnostic and status program (for reporting bugs and re-calibrating the device when necessary) and the software portal from whence most Leap-friendly apps will come.

Software

Leap Motion controller review
While executing the hardware correctly is surely of great import, the Leap is a platform that's only as good as the applications built for it. Which is why the company has spent so much time ingratiating itself with developers through an extended beta and created a purpose-built portal, called Airspace, in which to feature applications built for Leap. As we noted when we first saw Airspace demoed, it's a bifurcated portal composed of the Airspace Store on the web (where you acquire new apps) and the local Airspace Home (a launcher for any and all Leap-compatible apps). When you "buy" an app in the Airspace Store, Home detects that purchase and proceeds to download it automatically.

Leap Motion controller review (screenshots)

As of this writing, there are 54 applications built to run on Windows 7 and 8 machines and 58 apps for Macs running OS X 10.7 or higher. Nine of those apps are Windows exclusives, and 14 applications are Mac-only, with one app, called Touchless, having separate, but functionally identical versions for each (more on that later). Naturally, with such a large library of software at launch, we were unable to test every app in the Airspace Store. However, we did spend time with quite a few apps for both Windows and OS X.

Mac user experience

Leap Motion controller review
While the Airspace software felt welcoming and polished, things took a turn for the worse when we launched the pre-installed Orientation app, meant to familiarize users with the size of the gesture sandbox provided by the device and to serve as a general introduction to how Leap works. Orientation begins with a screen where a section of 3D space is marked out by a wireframe border and filled with a sort of luminous confetti. That confetti moves as if suspended in water, and it changed from white to glowing yellow and orange hues as we virtually swept our hands through it. Next, we were prompted to draw glowing white marks using our fingers, and, finally, we were shown a futuristic animated wireframe of our hands that included the individual joints of our fingers and tracked our movements. So far, so good.
Unfortunately, as we moved our hands around, our virtual fingers and thumbs disappeared and reappeared spontaneously; our wrists twitched some from side to side; and even slow, deliberate attempts to rotate our hands from palm up to palm down caused numerous detection failures. Not the most confidence-inspiring way to start off our Leap experience.
However, our faith was restored by several of the apps we tested. It's clear that, right now, the majority of folks building for the Leap are all about creative outlets, particularly gaming and music making. There's Boom Ball (think BrickBreaker in 3D), which works pretty much as you'd expect: you move around your extended finger, which corresponds to a digital paddle, and can control its pitch and yaw for finely tuned ricochet-angle control. Cut the Rope (a Mac-exclusive title for now) works as it does everywhere else, only you're swiping through thin air instead of on a screen. In Balloon Buzz, your bee avatar tracks to your fingertip and you pop balloons as they appear onscreen. All three of these games largely feature similar mechanics to touchscreen games, and the Leap performed admirably with all of them. The controller tracked our fingers precisely, and input dropped only sporadically, largely due to our own excitement causing our movements to become frenetic, or exiting the Leap's functional viewing area.
Leap Motion controller review
Dropchord is a wholly new gaming entity (for this editor, at least). In brief, it's a musical game that provides dazzling (if potentially seizure-inducing) visuals and requires players to use two hands to control dual points that slide along the circumference of a circle. A line connects those two points and players must bring that line in contact with orbs that appear within the circle to score and advance within the game. The controls here are simple, and since they're limited in scope, we had nary a problem -- our failures in the game were due mainly to lack of skill.
Not all our gaming experiences were positive, however. Digit Duel is a gunslinger-dueling title with pretty hand-drawn-style graphics, where you draw by forming your hand into the shape of a gun and flicking your finger up to shoot. We struggled mightily getting the game to recognize when we wanted to fire, and aiming was -- forgive the pun -- a crapshoot. Vitrun Air, a Marble Madness-style game where you move your hand forward to move and left or right to steer, suffered from similar control glitches -- the game would often fail to recognize our steering input, sending us falling off the course to our doom. Lastly, there's Block54, a digital Jenga-esque tower game requiring players to carefully remove blocks without causing the tower to topple. Control inputs were accurate for the most part, but we struggled to get the in-game camera placed at an optimal angle to allow for the removal of blocks, and positioning the virtual paddles used to remove blocks proved extremely difficult. Also, despite the fact that the game recommends using one hand to play, we found it impossible to get the angle correct when trying to grab blocks with one hand, and had far better luck using a two-handed approach (though our previous statements about the game's difficulty still stand).
In addition to games, there's a wide selection of music-making apps. AirHarp is exactly what you think it is, letting users strum away on a series of digital strings, while moving your fingers towards the screen increases the reverb. AirHarp also helped us acclimate to working with our hands in space -- it forced us to practice hovering and touching with more precision, so that we didn't always just scrape our finger along sequential harp strings. We did become more adept at this, but never to the point where we achieved the desired action 100 percent of the time. Chordion Conductor, meanwhile, is a genius little app for crafting songs using a variety of tempo, timbre, instrument and other settings. Plus, it has an Arpeggiator mode that automatically assembles notes in a melodic fashion as your fingers flit over digital keys. With the Arpeggiator turned on, we found it easy to create pleasing tunes. Truly, Airspace has some useful tools for the budding Mozart in your life.
Aside from games and music makers, several offerings in the Airspace Store are closer to demo "fluff" than actual programs. Flocking and Gravilux, for example, are straight eye candy. In Flocking, the tips of any extended fingers are represented as glowing orange orbs in an underwater environment, and those orbs cause hundreds of digital fish to swim around them in unison. Similarly, Gravilux is essentially a physics engine demo that displays thousands of tiny particles (users can choose their color and size) in a black environment -- those particles were attracted to the tips of our fingers and swirled around them as we waved our phalanges about. In both apps, the fluidity of the animations was impressive, and it's certainly cool seeing all those objects reacting to our hands, but we tired of both after a few minutes.
Leap Motion controller review
The other major category of apps available is educational. Cyber Science 3D lets you pull apart a human skull to identify the bones that comprise it and Frog Dissection lets you, well, dissect a digital frog (along with providing plenty of info about the amphibian's biology). Exoplanet lets you virtually explore the known universe and Molecules provides an up-close look at the molecular makeup of various compounds. In each of these, controls are rudimentary and fairly simple, but you can see the potential of the z-axis, pitch and yaw controls that the Leap provides -- it allowed us to easily manipulate three-dimensional digital objects and see them from all angles in a way we've never been able to before.

Windows user experience

Setup on our Windows machine was largely the same as it was for Mac, so we won't rehash the process here. Once we did get set up on our Windows 8 machine, however, we skipped past the fun titles in the app store and went straight for the serious stuff, starting with Touchless for Windows (there's an identical app built for Mac as well). Judging from its title image, which shows a finger navigating Windows 8's tile-based UI, we wondered whether this might offer an alternative to using the mouse. Heck, it could potentially even bring Windows 8 on the desktop PC more in line with the fluidity of the operating system on a touchscreen device. Alas, it wasn't to be.
Leap Motion controller review
Desktop control relies on dividing 3D space into two separate zones: one closer to your body, which is for "hovering," and one closer to the display, which is for "touching." In other words, it's just like hovering with a stylus before making contact with the screen on a Wacom tablet or Galaxy Note -- and hence it sounds like it should be intuitive. However, in practice we found that every time we moved a finger towards the computer monitor, the cursor drooped on the vertical axis, causing a mishit. This is because it's very hard to prevent your index finger from dropping slightly as it moves away from your body -- an inevitable consequence of the human elbow joint. Although practice would probably have improved the situation, we gave up after about 20 minutes due to its fairly steep learning curve and an encroaching sense that our time-limited existence on this beautiful planet was ebbing away.
Things improved when we shifted to Corel Painter Freestyle, which allows you to select different colors or brushes simply by hovering over a button for a few seconds. In this app, you only "touch" when you want to engage the brush on the paper, which avoids the need for precise button selections and therefore makes things easier. So long as you go for a masterpiece in the modernist style, with big and abstract strokes, it's a genuinely impressive experience. That's due to the way the software detects your movements on so many different axes, not just the position of your finger on the page, but also its orientation, which -- for example -- controls the directional flow of paint from your spray gun. The strokes on the screen might look messy, but they perhaps look more organic than what an inexperienced person could achieve with a Wacom stylus.
It was also annoying that the sensor often saw a thumb as a finger, even when we never intended for it to be registered. The only reliable way to prevent this was to tuck the thumb behind our bunched-up fingers, so that it couldn't protrude -- something that has felt instinctively wrong and unnatural ever since our first fistfight in the schoolyard.
Generally, although our control over the device did improve with time, it never became precise enough to allow for navigation of the Windows (or Mac) environment, in either the desktop or the modern UI -- and that was a huge blow to the daily usability of the Leap Motion controller.
All is not lost, however. Software updates could conceivably grant more control over how the device responds to our gestures -- perhaps by allowing us to set the sensitivity of different axes independently and saving these settings as profiles -- in order to minimize the impact of naturally arced motions. Perhaps some kind of thumb rejection is in order as well, to prevent us from having to tuck it inside our fist.
The Leap Motion did receive one update while we toyed with it, so we know its makers are there in the background, working on improvements -- there's just no guarantee as to whether or when they'll really deliver a "fix" for these issues.

Wrap-up

Leap Motion controller review

More Info

All in all, the Leap Motion controller is more about potential than anything else. While it provides a new means for computational control unlike anything else we've seen, it's clear that it's not cut out to replace a touchscreen or mouse as a primary input device. Not yet, anyway. Some developer may well figure out a way to take full advantage of the Leap's capabilities with a novel UI, but for now, it's best suited for creative pursuits, not productivity. The initial software library for Leap is relatively limited, but as the number of folks with Leap controllers grow, so will the amount of attention it'll receive from developers. And, there are enough apps in the Airspace Store that most folks will find at least a few to their liking. Eighty bucks for a glimpse of what could be the future of computer controls? Not a bad deal, but if you do dive in, we'd advise you think of it as an entertainment expense, not a business one.

All about Leap Motion

True new innovations in the technology space only come around every few years, and even rarer are the innovations that have the power to change our day-to-day interactions with our devices. That’s why I was excited when I first heard about the Leap Motion, a little motion control device that promised to alter how we think of using computers. One year since the initial preview, the device is in the hands of the public, and now it’s up to the people to decide if it can change the way we use our computers.

Hardware

Upon receiving the $80 little box, the packaging makes a good first impression. Inside the box you’ll find Leap Motion controller itself, and two USB cables (a shorter one and a longer one: usable interchangeably depending on your computer setup.) Both cables are standard grey USB cables, and they interface with the Leap Motion using what appear to be USB 3.0 Micro-B connectors.
Focusing on the hardware, you could almost mistake the Leap Motion for an Apple accessory. Perhaps this is unsurprising given that its COO, Andy Miller, is a former Vice President at Apple.
The device is comprised of an aluminum band that runs around the entire device, capped off with a rubber foot on the bottom (reminiscent of the Apple TV), and a dark, semi-translucent black plastic window on top that covers the sensors.
When the device is plugged in, a series of dim, red lights can be seen through the sensor window, but are barely noticeably off-axis. Additionally, a small green LED indicator on the side of Leap Motion indicates when the device is receiving power.
Leap Comparison
It’s hard to imagine how small the device actually is without seeing it in context with something else. In fact, the Leap Motion is so small and light (just 3” long and 1.2” wide) that I was afraid the USB cable would cause the box to twist out of place when set down on a flat surface. Fortunately, the rubber foot does a great job of keeping it securely in one spot. Above is an image comparing the Leap’s size to a well-known device (the iPhone 5).
Leap Motion Setup

Setup

The included card in the Leap Motion box directs you the setup page to activate your device. After downloading the software and installing it, you’re treated to a tutorial and demo of the device’s capability. This will help you get comfortable with learning how to interact with your computer in 3D space. The whole thing does feel somewhat futuristic; it’s really bizarre being able to wave your hands around in the air and control your computer. Especially after being used to a keyboard and mouse all of your life.
The demo- while neat- perhaps shows a little too much. It gives you too close of a look at what the software is actually doing under the surface, and how it detects your hands. It’s almost like seeing behind the curtain in the Wizard Of Oz- it ruins some of the magic of the experience. On one screen in the demo, you’re shown a visual wireframe of your hands as the Leap Motion detects them. Rather than make you more comfortable using the device, this part of the demo actually made me more cautious and careful about how I interacted with it, undoubtably the opposite effect desired. Seeing how easily the device could lose track of one of your fingers or hands by simply moving the wrong way or a little bit too far during use made me more inclined to carefully think out each motion before I did it- a totally unnatural experience. In use- the software seems to compensate pretty well for these sensing errors, but its a hard mindset to shake.

Usage

Once the Leap Motion is setup, you’re pretty much on your own. Since there aren’t any real directions or guides other than the demo, you’re left to figure everything out yourself. This can be a little frustrating at times. Launching Airspace, the Leap Motion’s equivalent of Launchpad on the Mac, shows all the apps installed on your system that will work with the device. A few apps are there by default, like Google Earth, which can work with the Leap Motion right out of the box, but to do anything really useful you’ll have to head over to the Airspace Store. To test out the device, I headed over to the store and grabbed every free app currently available on the Mac.
Right now, the Leap Motion is very app dependent. In order to get any functionality out of it, you need to turn to the Airspace Store. Out of the box, I was expecting basic functionality, like the ability to control my Mac, to be up and running. After turning on the device and heading to the desktop, I was surprised to see that nothing appeared to work. It was only after some digging around on the store that I found “Touchless for Mac,” the app required for Desktop integration. Similarly, to get the most of the Leap Motion’s gesture support, you’ll need to install Better Touch Tool, a complex app for setting up and managing app-specific and system wide shortcuts. More on this later.
Using apps with the Leap Motion was a mixed bag. When they work, it can be a lot of fun. When the motion tracking fails, however, it’s downright frustrating.
The Leap Motion’s sensor range extends up from the device and about a foot away from it, providing you with a generous, but limited area for gestures. While the sensor area is plenty large when doing simple tasks, when playing games, I’d often times find myself extending out of the sensor’s range and failing at a particular task in game.
There isn’t a simple solution here. By extending the gesture area, the device would be open to larger, more fluid movements and more advanced gestures. However, the larger the area the device has to watch, the higher chance for error.
The Leap Motion website suggests that the device be kept in front of your keyboard for optimal use, but trying to type with the Leap Motion in front of your keyboard will inevitably lead to accidental input from your hands, and even your head if you sit too near your computer. I found it best to keep the Leap Motion directly behind my keyboard, even though it increased arm strain. Perhaps it would be beneficial to build a universal on/off gesture into the software to reduce spurious input.
Airspace

Apps

Only days after launch, the Airspace store selection is, as expected, very limited. This will improve over time. From my testing, where the Leap Motion really shines is natural, interactive gameplay. Two games- Cut The Rope and Dropchord- really stand out. Cut The Rope is fun because it’s simple. Using your finger to flick around and cut the ropes feels natural. It’s a great example of how the device should be used. Dropchord is fun because it gets your mind in the habit of thinking in 3D space. Using a gesture controlled device like this is far different than using a mouse, or even a touchscreen, and it requires an entirely different state of mind. After using Dropchord, I felt much more comfortable controlling the device.
Other apps, like Molecules and Cyber Science 3D Motion are great demos of the educational potential with the Leap Motion. Being able to interact with molecular structures and bones in 3D is remarkably realistic and intriguing. There’s a big opportunity here for education.
Finally, some things don’t work at all. Google Earth, which I was expecting to be really neat, is far too sensitive to use. Trying to control it was a disaster.
Desktop control integration also left something to be desired. Although the Leap Motion can detect very precise movements, the human finger isn’t precise enough to control your cursor accurately mid-air. The experience is comparable to using a desktop operating system on a touchscreen- it’s not optimized. I am optimistic that this can be fixed, however. Applications like Cut The Rope and NYTimes for Leap Motion invented their own methods of UI control, which, in my opinion, work great for a device like this. Controlling the desktop accurately will require rethinking how we interact with the cursor, not adapting this new paradigm to the old method.
Better Touch Tool

Customization

For those that are more ambitious, BetterTouchTool provides a great deal of customization for the Leap Motion. Think of this as the AppleScript of the motion control world- it’s very hacky. Using system-wide gesture support, I was able to get OS X gestures for Mission Control, Launchpad, and Spaces all working with Leap Motion, as well as some other custom gestures in the native Maps application for OS X (launching with Mavericks this fall). Trying to integrate gestures with unoptimized games, however, didn’t seem to work well. The extensive customization available through BetterTouchTool makes using the Leap Motion a lot more useful. That is if you’re willing to put in the time.
Leap Motion MacBook

Conclusion

There’s no doubt about it- nothing else like the Leap Motion exists on the market in its current state. It’s an incredibly unique product with a ton of potential. That said, right now, the device feels a little bit like a prototype. While the hardware is extraordinarily refined, the software is rough in spots, and the tracking isn’t perfect. There’s also a steep learning curve. A lot of the functionality is only obvious after playing around with the device for a few hours, and novice users might get discouraged initially.
Overall, if you’re an early adopter of technology, a developer, or someone who is curious and wants to explore the future of computing, this is the device for you. While the functionality is currently limited, many of the device’s issues can be fixed with software updates.
For casual users, however, there isn’t a whole lot to see here. The Leap Motion can’t replace your mouse right now. It’s a cool concept, but this is technology that’s going to take years to develop. In the meantime, I’m extremely excited about the future of motion control and I think that devices like the Leap Motion have a promising future ahead of them.