Love and hate for Java 8 (Everything that you need to know)

Java8 isn’t scheduled for for release until March 2014, but early release versions have been available for a while. Some of the most interesting new features of Java 8 are: 
  • Streams 
  • Functional interfaces 
  • Default methods 
  • Lambdas 
  • Java Time 

Streams 

The new java.util.stream package contains “classes to support functional-style operations on streams of elements”. Streams aren’t a new type of collection and don’t replace any of the existing ones such as Lists and Queues. Instead, they provide a way to interact with an existing collection, and in that respect are more similar to iterators. 

The javadocs describe a stream as “a sequence of elements supporting sequential and parallel aggregate operations.” A stream pipeline consists of a source (e.g. a collection), intermediate operations (e.g. a filter or map) and a terminal operation, which produce a result (e.g. sum or count). Streams are lazy in that the operations on the data are only performed at the last minute i.e. when the terminal operation is called, and the stream is processed only once. 


For example: 

int totalFxTrading = blocks.stream()
        .filter(trade -> trade.getType() == FX)
        .mapToInt(b -> b.getTradedAmount())
        .sum();



Functional interfaces

Java 8 will have a new feature called functional interfaces. A functional interface has exactly one abstract method. There are many such interfaces that you have probably used as a Java developer, such as Runnable, ActionListener, Comparator and Callable. In Java 8 these types of interfaces are now more formally called Functional interfaces. They can be identified using a new @FunctionalInterfaceannotation, and most importantly, can be represented using Lambda expressions (more later). For example, to use an ActionListener in the past, you needed to create an implementation, often using an anonymous inner class. 

For example: 

JButton button = new JButton();
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                System.out.println(ae.getSource());
            }
        });


Using functional interfaces, this becomes much simpler: 


JButton myButton = new JButton();
        button.addActionListener(
            ae -> {System.out.println("You clicked the button");}
        );


We never need to even mention ActionEvent – the compiler derives the type of ‘ae’ from the context. Note that the @FunctionalInterfaceannotation, like the @Override annotation, is not required. Instead it signals to the compiler your intentions so that it can warn you if something looks amiss e.g. more than one abstract method is available. 


Default methods

Prior to Java7, an interface was a fairly simply thing. It could contain abstract methods only (and constants) which had to be implemented by concrete subclasses. An interface was basically a bunch of method signatures, but could never contain a method definition/implementation. 

In Java8, things gets more interesting. Default methods can now be added to an interface. These are methods that do have an implementation, do not have to be overridden in the interface implementation and can be run directly from the interface. 

These default methods were added as a necessity to provide backwards compatibility. If they had not been added, it would not have been possible to extend/improve the existing collection interfaces, for example, without breaking all the implementations. So for that reason, default methods are sometimes referred to as defender methods. 

To me, the really interesting thing about default methods is that they allow a form of multiple inheritance. Since a class can implement more than one interface, and each of those interfaces can now potentially have a default method with the same name, which version does the subclass inherit? I think this is referred to as the diamond problem. If such a scenario arises when using Java8, the compiler will provide a warning. You can use the syntax X.super.m(…) to explicitly choose one of the parent class’s implementations. 

On a side note, why do these new default methods need the default keyword at all? Couldn’t they have worked just as well without that keyword? The answer is yes, the default keyword is redundant, just like the abstract keyword. Both were added to make things a little more clear. This post has some more details are links. 


Lambda

According to Wikipedia, a lambda expression is “a function defined without being bound to an identifier”. Lambda expressions are coming to Java in version, designed to allow code to be streamlined. 

Many of the other changes I discussed above(default methods, functional interfaces) are very closey related to the introduction of lambas. 

When a Lambda expression is written, it is translated into a functional interface at compile time. Here is an example of using Lambda expressions to replace an anonymous inner class with much cleaner and more readable code.


Old way without Lambda: 

button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println(“Action Detected”);
        }
    });


New way with Lambda: 


button.addActionListener(e -> {
        System.out.println(“Action Detected”);
    });


Using Lambda expressions will often make the code easier to read and require fewer lines. 


Java time

Dealing with dates and time in Java has never been ideal. At best it has been quirky, and at worst, a bit of a nightmare. The Date class was clunky and is now littered with deprecated methods. The Calendar class was an improvement, but I personally always seem to spend more time that I would like having to trawl through the API docs, even for things I have done before. Other 3rd party libraries tried to deal with times in a more elegany fashion (e.g. Joda time). There have been rumors of improved handling in Java itslef anf with Java8, it is here – the java.time package. 

A new (abstract) Clock class provides some useful static methods such as systemUTC() and systemDefaultZone() to get the current time and timezone. And a number of new classes such as LocalDate and LocalTime, and YearMonth and MonthDay provide more elegant handing of day to day (pardon the pun) date operations. 


What’s not in Java8

On a side note, although date/time handling will be improved in Java8, amazingly there is still no good way to handle currency in Java (something I have blogged about in the past). Doubles (and all floating point numbers) are inherently unsuitable for money, or anywhere exact calculations are required. Using int or long requires keeping track of decimal points, and BigDecimal isn’t ideal either.Those guys may improve things, but it looks like we will have to wait until Java 9 for that  :-)

Install and run Windows on a USB / External HDD using an ISO

Ever wanted a copy of Windows you can take with you wherever you go, to use on any computer you want? It's possible: here's how to install a portable version of Windows 8 on a USB hard drive that you can take anywhere.P
The Enterprise version of Windows 8 has a feature called Windows To Go that lets you install a portable version of Windows on a "certified" flash drive. Unfortunately, most of us don't have the Enterprise edition of Windows 8, nor a certified flash drive. However, there is a tool called WinToUSB that can essentially do the same thing, no matter what version of Windows you have. Here's how it works.
WinToUSB is a free software that allows you to install and run Windows operating system on a USB hard drive or USB flash drive, using an ISO image or CD/DVD drive as the source of installation. WinToUSB also support creating bootable WinPE USB drive, it can help you to transfer the contents of WinPE to the USB drive and make the drive bootable.

WinToUSB's key features include:
  • Easy-to-use wizard interface that provides step-by-step instructions for installing Windows/WinPE on a USB drive.
  • Install Windows/WinPE from an ISO image or CD/DVD drive.
  • Support for Windows NT 6.x OS family (Vista/7/8/8.1/2008/2008 R2/2012/2012 R2) and WinPE 2/3/4/5.
  • Use any edition of Windows 8(.1) to create Windows To Go USB drive.
  • Support for MBR and GPT disk layouts.
  • Don't need install WAIK (Windows Automated Installation Kit) or WADK (Windows Assessment and Deployment Kit).
Important notes:
  • Windows Vista/7/2008/2008 R2 does not have built-in USB 3.0 support, so Windows Vista/7/2008/2008 R2 will have to be booted from a USB 2.0 port.
  • USB flash drives are very slow. It takes a long time to install and run Windows from a USB flash drive, highly recommend using a USB hard disk or Windows To Go Certified Drives.
  • Windows To Go drives can be booted on different computers, so you can carry it to anywhere and use it on any computer.
  • Windows 7 is not completely portable. You may have activation and driver problems when booting on different computers.
  • You need to be an administrator on the computer you are installing the WinToUSB on.

System requirements

  • Windows XP or later (32/64-bit).
  • Intel® Pentium® processor.
  • 256MB of available RAM (512MB or more recommended).
  • 10MB of free space on your hard drive.
  • 800x600 graphic device (higher resolution recommended).

Downloads

Download WinToUSB V1.4
Let me know here:  Snehal [at] TechProceed [dot] com,  if you need any further help.  :-)

BBM for Android & iPhone – It's finally here!

BBM for Android and iPhone is now live in Google Play and Apple’s App Store


BBM for Android and iPhone nets over 10 million downloads on day one of release


BlackBerry has revealed than in the first 24 hours since it launched BBM for Andorid and iPhone it has been downloaded more than 10 million times, in what the company describes as "one of the best single-day openings for a mobile app to date ."

BBM achieved number one app status in the UK, US, Canada, Indonesia and "most of the Middle East," according to a BlackBerry statement. It also gained "overwhelmingly positive" user ratings on both Apple's App Store and Google Play with 60,000 five star reviews on Google Play.

Andrew Bocking, BlackBerry's executive vice president of BBM, said, "This has been an incredible launch for BBM across Android and iPhone devices. The mobile messaging market is full of opportunity for BBM. We intend to be the leading private social network for everyone who needs the immediate communication and collaboration of instant messaging combined with the privacy, control and reliability delivered through BBM."

He added: "While we’re excited to bring BBM to iPhone and Android – we aren’t stopping there. Work isn’t slowing down at all. We committed to delivering a BBM experience on iPhone and Android that was equal to that on BlackBerry 10. That means bringing BBM Video, BBM Voice and BBM Channels to Android and iPhone customers too.

"My team is still committed to bringing those features to BBM on Android and iPhone in the near future. And we’re not stopping there – we have some great new features planned that will build on BBM as the private social network you count on for immediate conversations you can control and trust."
Reviews of BBM for Android called into question 

A slew of five star ratings for BBM for Android has resulted in allegations that something fishy is going on inside Google’s Play store, and the allegation is as follows: BlackBerry is writing up fake reviews of its newly released IM application, BBM.

BlackBerry launched BBM for Android and iOS on Monday. Since then a stream of “fake” reviews has appeared inside Google’s Play store (see below).


At the time of writing there are currently 182,000 reviews of BBM for Android. It’s not uncommon for companies to hire marketing firms to write up decent reviews of newly released applications, although BlackBerry says this is not the case it all –– it has nothing to do with the reviews.

A BlackBerry spokesperson gave TNW the following statement:

"We have been made aware of a number of potentially fake reviews of BBM for Android on Google Play, with ratings anywhere from one to five stars. We have no knowledge of how these reviews were created or populated. We do not approve of or condone such activities. There are also many genuinely great and useful reviews from our new BBM users on Google Play. We would like to encourage our fans and users to continue to provide true assessments of the BBM experience through the proper channels."
BlackBerry officially launched BBM for iPhone and Android

After much ado, BlackBerry has finally confirmed the release details of BBM for Android and iPhone. The IM application is now available for download inside Google Play And Apple’s App Store.

BBM for Android and iPhone was downloaded by five million users within the first eight hours of its release, BBM has confirmed. 
BBM now inside Google Play & App Store


BlackBerry confirmed the rollout would begin yesterday evening. Here’s the company’s official statement:


“I am thrilled to tell you that we are about to officially resume our rollout of BBM for Android and iPhone customers around the globe!* In the next few hours, people will start seeing BBM in Google Play, the App Store and in select Samsung App Stores – where it will be free to download,” wrote Andrew Bocking on the official BlackBerry Blog. 

Around six million people signed up for email updates on BBM.com, according to Bocking. And to ensure this rollout goes more smoothly than the last one, BlackBerry has implemented the following roll out schedule:
Download BBM – the easiest way is to visit BBM.com from your Android or iPhone browser
Once you install the app, open it, and enter your email address to hold your spot in line
We will email you as soon as you reach the front of the line and can start using BBM

Users that signed up for email alerts from BBM.com can download and start using the application straight away. But if you didn’t sign up for alerts –– and this is the kicker –– you’ll have to wait for BlackBerry to activate your account. 

“If you didn’t sign up in advance, don’t worry – we are focused on moving millions of customers through the line as fast as possible,” added Bocking.

Once you’re email has reached the front of the queue you’ll receive an email from BlackBerry and you can then –– and only then –– begin using BBM.
Beat the queues and get BBM straight away

In a bid to ensure that the rollout of BBM isn’t royally mucked again, BlackBerry has taken the rather unique approach of implementing a queuing system for access to its now-cross-platform IM app.


How it works is simple: you download the app, register or sign-in, and then wait for BlackBerry to verify your BBM account and grant you access to the service. That’s all well and good but it doesn’t take into account one thing –– most people are very impatient.


So, if you don’t want to have to go through all that, and you just want to start using BBM as soon as you’ve downloaded the app, check out this handy little trick, via CNET, to get instant access to BBM as soon as it’s downloaded: 

“Open the BBM app, enter your e-mail address and click Next. Then, force-close the app: on an Apple device double-click the home button and swipe the app away; or on Android, enter the multitasking menu and swipe the app away, or go to Settings, Apps, BBM, and Force Close.

“Relaunch the app and it should allow you to create an account and start using the app. Bear in mind however that BlackBerry could close this sneaky loophole at any time.”

How do I download or save a YouTube video to my computer?

YouTube has been designed to only allow users to watch and view videos on their website. Many users want to save their favorite videos to their computer so they can watch them without being connected to the Internet or so they can watch them on other devices. Below are the steps required for downloading and watching YouTube videos on your computer for free.

Saving YouTube video as a video file on your computer

Today, there are several online websites that allow you to enter the URL of the video you wish to save to your computer, and get a link to download the file. Below is the simple three step process that will link you to a page that does the job.

  1. Go to the YouTube video page and copy the URL of the video you wish to save. For example, below is a URL to a video on YouTube, the whole address would be copied.
  2. Once this address has been copied, paste that URL into the below URL text field and click the Download Video button.


  3. If done properly, a new window will open with available video formats that can be saved. For most users we suggest the MP4 format, other formats may include FLV, 3GP, and WebM.

Hope you liked the simple way to download the videos from YouTube.  :-)