Friday, May 16, 2014

I Code Java : A Blog on Java Generics and Methods






This blog is inspired by the book “Effective Java” by Joshua Bloch. It is quintessential step to write good methods since these methods are exposed as APIs to other set of classes and packages.

Why should we all use Java methods?

  • For reusable code
  • For top down programming
  • To create conceptual units


Guidelines for writing a good Java method?

  • Whenever a method is exposed to an outside entity, we cannot make assumptions for the type of arguments which would be sent when the method is invoked.
  • Firstly if there is an operation performed over the arguments, we must assert for null ability. 
  • There are many ways in which we could make it null safe. We could use documentation, annotations or explicit null checks in the method. 
  • Documentation using JavaDocs is necessary but not sufficient. 
  • Annotations helps to preserve the sanity of the method but still results in runtime validation exceptions. 
  • Explicit null checks when done properly help in avoiding any runtime errors. Using all the above 3 ways in conjunction with each other is a good practice.

Ex:


/** Checks the equality of the given input arguments. 

* @args obj1      Object  1st argument
* @args obj2      Object  2nd argument
* @returns Boolean True if both are equals, False if not equal

**/
Boolean isEqual(Object obj1, Object obj2) {

                if (obj1 == null && obj2 == null)
                                return true;
                if (obj1 == null || obj2 == null)
                                return false;
                if (obj1.getClass() != obj2.getClass())
                                return false;
                return obj1.equals(obj2);
}


Specify the type of parameters as precise as possible. If the type of the argument can be subclasses, the method needs to ensure type safety.

Guidelines for using Java Generics

Generics is been a boon to java developers since its introduction in Java 1.6. Generics brings in a lot of freedom and abstraction to the developer. Consider the example below.


Abstract Class Shape {
}
Class Polygon extends Shape {
                int sides;
}
Class Pentagon extends Polygon {
                public Polygon (int sides) {
                                this.sides = sides;
                }
}
Class Circle extends Shape {
                int radius;
}
// Incorrect Way
Boolean getNumberOfEdges( <? extends Shape> foo){
                // business Logic
}
// Correct way
Boolean getNumberOfEdges( <? Extends Polygon> foo){
                // business logic
}
In the above example, we have restricted the type of object to anything of type Polygon as we expect instances of Polygon only to have edges. Whereas this is not guaranteed for all classes which extend the parent class Shape.

To end on a funny note!


















References:
[1] : http://uet.vnu.edu.vn/~chauttm/e-books/java/Effective.Java.2nd.Edition.May.2008.3000th.Release.pdf
[2] : http://java.dzone.com/articles/5-things-you-should-know-about-java-generics
[3] : http://www.tutorialspoint.com/java/java_methods.htm
[4] : http://www.leepoint.net/JavaBasics/methods/method-commentary/methcom-purpose.html

How to GIMP!



GIMP is the GNU Image manipulation tool is basically a raster graphics editor. It can be used for tasks such as photo retouching, image composition and image authoring. As a part of designing a handbook for the 180i website, we used this too extensively to create 2D puzzles which set the theme for our project. In this blog, I would like to share the intricacies involved in achieving the same.

Why choose GIMP over Photoshop?

  • GIMP is free because it is developed as an open source project. 
  • It is as powerful as Photoshop and you can open Photoshop files in GIMP.
  • It has versatile selection and transformation tools.
  • It is compatible with most operating systems.
  • Its easy to learn as compared to Photoshop.
  • Cost of GIMP : $0, Photoshop : $699
  • Size of GIMP : 18Mb, Photoshop : 1GB + additional space during installation 

Steps involved in Converting the Original image to a Jigsaw puzzle



  • Download and install GIMP from : http://www.gimp.org
  • Decide the dimensions of the puzzle and create an image with those dimensions
  • Draw the puzzle outline with : Filters --> Render --> Pattern --> Jigsaw

  • Set the options for the puzzle outline

  • In the Jigsaw dialog box, set the horizontal and vertical number of tiles to be numbers of horizontal and vertical rows calculated in Step 1. Set Bevel Width to 0 and Highlight to 0. That will make sure that the lines separating the puzzle pieces will be as thin as possible.
  • Bevel width : It controls the slope of the edges of the puzzle pieces
  • Highlight : It  controls the strength of the highlight that will appear on the edges of each piece. It can be compared with the glossiness of the material that the puzzle is made up of. Highlight width is relative to the Bevel width. As a rule, the more pieces you add to the puzzle, the lower Bevel and highlight values should be used.  
References : 
[1] http://docs.gimp.org/en/plug-in-jigsaw.html
[2] http://www.wikihow.com/Turn-a-Photo-Into-a-Puzzle-Using-GIMP
[3] http://geekitude.com/Gimp/creatingPuzzles.html


·  



Challenges involved in Beta Testing Video Games



Many of us have come across beta testing in real life situations – it could have been for one of our favorite games or one of the applications on our operating systems that we use on a daily basis.

Beta testing can be defined as allowing the software to undergo usability testing with users who provide feedback, so that any defects found by the users can be reported to the developers and fixed.”

Where does Beta testing fit in?



A big problem with beta testing video games, is finding people that are willing to test the software. Gaining peoples feedback on a piece of software is very difficult because many just want to experience the software and not provide feedback to the developers. Popular online games such as World of Warcraft and City of Heroes performed beta tests of their games before the actual release. The main reason for this was to test their hardware servers and make sure that they could handle the amount of players that are likely play at any one time.

What makes beta testing video games challenging?

  •  A video game tester requires thinking critically about video games and game play.
  •  A game tester will play a certain level on certain difficulty setting: examples can be  equipping certain weapons to fight enemies, complete missions etc. While doing so,  the tester has to watch out for all the errors and ambiguous behaviors in the game  and write up a bug report giving details about the error and how the error was  encountered.
  • A large error, like a game crash, is very easy to spot, but a smaller error like a graphical glitch can be difficult to spot.
  • Sometimes it is difficult to reproduce  the errors since the exact test scenario can be complex.
  • Many games feature multiplayer functionality, requiring players to test together to simulate a live experience.
  • Depending on the genre and content, the target participants of a game beta may be a very young audience, which lead to different recruitment and management issues.
  • For closed platform games (iPhone, etc.), distributing pre-release builds to testers is challenging. This is primarily due to security concerns which result in a number of obstacles.
  • Many games require very large participant pools. These pools can require an enormous amount of coordination, communication, and logistical planning. Seemingly simple tasks such as distributing beta builds become increasing complex as the number of participants rises.
  • Between the younger ages of game beta testers, the large size of many game tests and the excitement to test a new game, there is a higher likelihood that testers will want to discuss their experiences in game betas. This can increase the possibility of leaks about the product.
  • Game testers end up playing the same level literally hundreds of times. This is a far cry from the rosy picture most people have of video game beta testers enjoying their tasks.
  • To prepare for testing video games, beta testers should gain experience with using different console controllers. This is a huge ask!
  • The tester has to play the video game along all possible paths and make sure all the game logic is tested. The controllers and the audio also need to be tested for each of the levels.
  • The non-functional game features like balance, difficulty and fun factors are other areas which need to be covered. 
         Beta testing video games can really be fun and a good profession for people who love to try     their hands at different kinds of games.

          References :
          [1] http://www.animationcareerreview.com/articles/breaking-video-game-industry-                   quality-assurance-otherwise-known-video-game-testing
          [2] http://www.centercode.com/beta/types/games/
          [3] http://thegameprodigy.com/the-truth-about-being-a-game-beta-tester/
 



Friday, April 18, 2014

User Experience Rocks !!


Mobile phones are used by commoners who have limited technical know how of the device operations. Every available smartphone comes with hundreds of pre-installed applications and the actual success of these applications depends on the ease with which they reach-out to the crowd. Mobile usability testing is a way to find the design flaws in the product so that the user experience is improved. The internal functionality of the system is not known to the user as opposed to the developer. So testing done by the actual end users before the launch of the handset is known as Usability testing. 

The main creative goals for Android based phones are : Enchant the user, simplify the user experience and amaze the user with the features provided. These goals can only be achieved when the end user finds it easy to use the system. Its highly impossible to create a user manual for all the pre-installed applications that are shipped from factory. 

Mentioned below are the things to keep in mind while performing Usability test in Android based phones








Having worked in the Android Mobile handset division myself, there are a few lessons that I always keep in mind during Usability testing.

  • By performing testing in the User's own handset and environment, you are more likely to unearth the issues. Reason being, the user is quite comfortable with the phone he is currently using and can easily determine changes in the same.
  • Perform drive tests. Network issues and behaviors related to connectivity can be simulated only when the user is travelling.
  • Ask people from different age groups to test the phone. The younger generation is more likely to know the technology than the elderly who have not tried their hand at using the latest applications. The success of the phone will depend on the ease with which all can use it.
  • The important traits of a good UI are : It should be consistent, flexible, comfortable, intuitive and correct.
    • Intuitive UI : UI is clean, unobtrusive and not busy. Responses are obvious. Does the help feature really help the users 
    • Consistent UI: Placement of buttons should be consistent throughout the phone.
    • Flexible UI : Users like flexibility in performing operations. Shortcuts should be provided to users.
    • Comfortable UI: Does the UI provide Redo/Undo options? How fast are the reactions to the commands performed?
                                                                      The points mentioned above help the developers to achieve the desired results out of Usability testing. If applications are uploaded onto the Android market without the actual user testing it beforehand it could cause the application to fail miserably and have no buyers.




References:
[1] http://sdsu-dspace.calstate.edu/bitstream/handle/10211.10/3556/Alluri_Aruna.pdf?sequence=1
[2] http://developer.android.com/design/style/index.html
[3]https://www.cs.drexel.edu/~spiros/teaching/SE320/slides/usability-testing.pdf

Thursday, April 10, 2014

Open Source Organics



A few days ago while working for one of my Cloud computing projects, I stumbled upon an open source cloud computing platform for private and public clouds called: OpenStack. After burning mid night oil for a few days I was finally able to deploy it successfully on my virtual machine. The efforts that I put during this time had me intrigued enough to write a blog about the organics of open source software’s like OpenStack.

OpenStack provides users with ubiquitous open source cloud computing platform and predominantly provides Infrastructure as a service. It also provides users with computing and networking resources. So users have hardware, software and applications delivered to them through a web browser.

Listed below are a few advantages of using OpenStack
·         Users can have public and private clouds available anytime on any PC and access it via a web browser.
·         Simple to integrate, scalable, and has a dashboard which makes it easy to use.
·         Provides unlimited storage and has mechanisms to prevent data corruption.

So what are we waiting for? Let’s get started and setup OpenStack on your Linux machines



Step 1: I would suggest you to install OpenStack in your virtual machine and not on your main host. Reason for this being OpenStack needs its own dedicated environment to run. You can use VMWare or Virtual Box to create your virtual machine and then run Ubuntu in them.

Step 2: Increase the RAM of the virtual machine to at least 1.5GB and memory to at least 6GB. OpenStack seems to get hungry very soon so it’s preferable to have this memory lest your VM may be really slow.


Step 3: We need to create a user named “stack” for installation to be successful




Step 4: Also we need to give all privileges to “stack”







This will open the file visudo. In this file we need to set the following data







Step 5: Now we can logout from the root and login again as the user “stack”. We can install “git” if it’s not present already.







Step 6: Download the OpenStack code from github. The code should be stored in “/var” so we first do cd /var and run the below command









To avoid any permission issues we need to execute the below commands







Step 7: We need to now create a localrc file which stores the passwords and login information. Path for this file is /var/devstack/localrc

Contents of this file












Set IP address = VM eth0 IP address. It can be found by running ifconfig command in the terminal.

Step 8: Run ./stack.sh from the path /var/devstack. Once it completes it will show the below screen

















Step 9: You can use Mozilla to login to OpenStack Horizon dashboard. Use your IP as shown in the above figure: http://10.0.0.14. The username and the password to be used are also mentioned at the end of the compilation.




So we have successfully deployed OpenStack on your PC. You can create instances and volumes using the same.



Recently during a discussion with a bunch of friends we were speaking about how Netflix can charge as little as $8 per month for its services?? Yup everything is built on open source software!! They have the entire infrastructure established so it's an easy task for them.
“Too many cooks spoil the broth” is a saying of the past now. As for the developers what’s more apt is: “The more, the merrier”.  More intelligent developers ensure that the software is more stable and secure than the proprietary software because anyone can spot a bug and even have the code to analyze and fix it.
        







“A mind is like a parachute. It doesn't work if it is not open.”  - Frank Zappa




B is for Burglar!!!



We lock our doors, have burglar alarms for our houses but we leave the biggest door open. The door which cyber criminals have used time and again to steal our credit card information, personal identities and other valuable data.

I happened to read a cartoon which said: “Don’t underestimate the I.Q of crooks “. It made me ponder about the loop holes and the ever prevalent issues of Cyber Security which have bogged the society in the current times.

In August 2013, hackers supposedly disrupted the NASDAQ trading market and the market had to be shut off for more than 3 hours. A problematic issue showed up in a quote processing system which brought the technical glitch into light. This issue instigated a lot of questions arising in the minds of the investors who now doubt the over dependence on technology for their trading. This kind of attack could be performed at the blink of an eye by a person who is miles away. There are several other breaches which are possible like the attacker could alter the trading algorithm which in turn could cause the market to crash. The worldwide impact would be unimaginable if at all a cyber-attacker could gain access to NASDAQ computers.

As a matter of face we are prone to cyber-attack all the time. We use Cloud services, smart phones for internet banking, social networking sites to interact with friends all over the world. All this has only complicated the process of achieving cyber security. The world is more interconnected today that it was before the era of Smartphones and Internet.



How do you protect yourselves from Cyber crimes??

  • Install a good Anti-Virus program on your   PC and smart-phones which detects viruses and removes them. 
  • Set really complex and strong passwords 
  • Try not to open mails from unknown sources. Also prevent opening attachments in mails from unknown sources.
  • Do not download "exe" files from the internet and be careful about the websites that you visit and the links that you click.
  •  Limit the amount of personal information that is posted online. Also use privacy settings to ensure personal information is not shared across everyone.
  • Be cautious about online deals. If it is too good to be true then probably it's not true! 
  • It's important to ensure that your computer and routers are installed with good firewalls. 
  • Public WiFi's send data which is not encrypted so avoid using Public WiFi connections.

How do you choose the right password??
  • Create a password with minimum of 8 characters. The longer the better!
  • Choose a series of random words which are easy to remember but tough to break.
  • Have an alphanumeric password and also add some special characters to make a complex password.
  • Use a mixture of upper and lower case alphabets since passwords are case sensitive.


What not to do while choosing passwords?

  • Do not choose obvious passwords like name, date of birth or other related personal details
  • Don't choose a complex password which you cannot remember.
  • Do not choose an English word as a password. Crooks can perform the dictionary attack and break your password.
  • Do not choose only alphabets or numerals and do no choose passwords of length less than 8 characters.


     With all this taken care of these is just one last thing that you need to do!!





And finally : Lock your Computer!!                                                                                 





      References : 

             http://kb.iu.edu/data/akln.html
                   http://ieeexplore.ieee.org.libaccess.sjlibrary.org/stamp/stamp.jsp?tp=&arnumber=6568387
                   http://ieeexplore.ieee.org.libaccess.sjlibrary.org/stamp/stamp.jsp?tp=&arnumber=6284146
                   http://www.reuters.com/article/2013/08/22/us-nasdaq-halt-tapec-idUSBRE97L0V420130822
                   http://www.wikihow.com/Choose-a-Secure-Password