Thursday, August 18, 2011

Track your Phone / Laptop using Prey

Now you can track your stolen laptop / phone (but not iPhone yet) for free using an open source software called Prey. It is a very small & lightweight software that can be installed on your Mac, Windows, Linux or Ubuntu Laptop or your Android smart Phone. Set it up and then you can wake it up in case your device is (God forbid) stolen. There are paid Pro version too for those who want a greater feature set and active monitoring.
This was recently used by self professed Info Sec Evangelist Greg Martin to track his stolen MacBook in the aftermath of the London riots.

Tuesday, August 2, 2011

Java 7 Summary of New Features

Here is a summary of the new features released in Java 7 as part of Project Coin language enhancements are:
  1. Improved Numeric Literals - Binary integral literals and Underscore in numeric literals
  2. Strings in switch
  3. Diamond operator or simpler type inference for generic instance creation
  4. try-with resource statement
  5. Multi-catch and more precise throw
  6. Simplified varargs method invocation
  7. Fork & Join enhancements
  8. NIO 2.0 & File system access enhancements
These are explained in detail below.

Improved Numeric Literals
Integral types (byte, short, int, and long) can also be expressed using the binary number system by prefixing "0b" or "0B" to the number's binary representation as:
int binaryLiteral = 0b110011

You can have underscores in numeric literals to make them more readable like:
int tenMillion = 10_000_000;

Strings in switch
Till Java6, only numbers or enums could be used in switch statements. Now strings are also allowed:
String switchString = getStringValue();
switch(switchString) {
    case "foo": doFoo();
    case "bar": doBar();
    case "fuu": doFuu();
    default: doDefault();
Diamond operator
This is a short cut to reduce typing and make it simpler to infer generic types during instance creation
Map<String, List<Pair<String,BigDecimal>> myMap = new HashMap<>();

Simplified varargs method invocation
When a programmer tries to invoke a *varargs* (variable arity) method with a non-reifiable varargs type, the compiler currently generates an "unsafe operation" warning. This proposal moves the warning from the call site to the method declaration. This merits more detailed explanation and a separate post.

Multi-catch and more precise throw
Now you can catch multiple exceptions in the same catch clause and also re-throw final exceptions without declaring the method with the "throws" clause.  More Precise Rethrow allows you to catch a high level exception instead of each possible exception, but when you re-throw this caught exception, the correct sub-class is thrown instead of the higher level exception. This merits more detailed explanation and a separate post.

Fork & Join threading enhancements
New Fork / Join framework as an implementation of the ExecutorService to help take advantage of mulit-core / multi-processor machines.

NIO 2.0 & File system access enhancements
NIO 2.0 & File system related changes make it easier for traversing file system trees and access file properties.
There are numerous changes and these could be a good candidate for a separate book in itself.

Check out the Summary of Java 5 features that are also hold good and are very useful.

Java Diamond "<>" operator

As part of Project Coin - Language enhancements, Java 7 has introduced the Diamond operator "<>".
In reality, this is just a short cut for a simpler type inference for generic instance creation.
So instead of this:

List<String> stringList = new ArrayList>String>();

one can use this in Java7:
List<String> stringList = new ArrayList<>();

So you say "big deal"?! The real benefits show when the type being inferred is very complicated and has multiple types nested in it like:
Map<String, List<Pair<String,BigDecimal>> myMap = new HashMap<>();

You are saved from repeating the same thing - less typing and less errors!


Related Posts Plugin for WordPress, Blogger...