Skip to main content

Posts

Java 9 Collection Changes Overview

Introduction Java 9 finally brings the convenience of creating small unmodifiable Collection instances using just one line code. New APIs make it convenient to create instances of collections and maps with small number of elements. Driving Factor Too much code is required to be written to create a small, unmodifiable collection, which involves constructing it, then storing it in a local variable, and calling methods e.g. Set< String > set = new HashSet<> (); set . add( "first" ); set . add( "second" ); set . add( "third" ); set = Collections . unmodifiableSet(set); Alternatively one can create same using constructor method. Set< String > set = Collections . unmodifiableSet ( new HashSet<> ( Arrays . asList( "first" , "second" , "third" ))); Or using Double brace method Set< String > set = Collections . unmodifiableSet ( new HashSet< String > () {{ add( ...

Java 8 streams performance on mathematical calculations

Java 8 Streams API supports many parallel operations to process the data, it abstracts low level multithreading logic. To test performance did following simple test to calculate factorial of first X number starting with N. Following program calculates factorial of first 1000 numbers. package com.java.examples ; import java.math.BigInteger ; import java.time.Duration ; import java.time.Instant ; import java.util.ArrayList ; import java.util.List ; public class MathCalculation { public static void main ( String [] args ) { List < Runnable > runnables = generateRunnables ( 1 , 1000 ) ; Instant start = Instant . now ( ) ; // Comment one of the lines below to test parallel or sequential streams runnables . parallelStream ( ) . forEach ( r - > r . run ( ) ) ; // runnables.stream().forEach(r -> r.run()); Instant end = Instant . now ( ) ; System . out . println ( " Calculated in " + Duration . between ( start , end ) ...

Mobile Testing

Mobile application testing falls into broadly two types: Hardware Testing This includes testing internal hardware, screen size, resolution, space, camera, Bluetooth, WIFI etc. Software or Application Testing This includes testing the application that are running on device. Because of types of apps this can be divided into following categories: Native apps Mobile web apps Hybrid apps There are some key things to be considered when testing mobile apps: Native apps have single platform Native apps are written in platforms like SDKs while Mobile web are written in html, css Native/Hybrid apps may or may not require internet connection Mobile web apps require internet connection Native/Hybrid apps are downloaded from playstore Mobile web apps are accessible from internet Mobile Testing complexity in comparison web applications Different range of mobile devices, screen sizes etc. Various manufactures customizations OS types iOS, Android, Windows etc. Di...

Java keytool to create keypair

Use following command to create a public/private keypair using java keytool command. keytool -genkey -keyalg RSA -alias mykeystore -keystore keystore.jks -validity 30 -keysize 2048 Once you run the command follow the steps to complete generation of keypair, make sure you remember the password that you provide during generation.

Windows to Mac cheatsheet

For any user who moves from windows to Mac here are some frequently used shortcuts that we commonly use on windows Task Manager Command+Option+Esc Screenshot Shift+Command+4 Eclipse Preferences Unlike Windows where they are under Window -> preferences, on mac they are under eclipse -> preferences

Gulp command not found on Mac OSX

Was getting following error after installing gulp on mac. Sachins-MBP:MyApp sachin$ gulp -bash: gulp: command not found After fighting for hours and searching on internet, tuned out to be a very simple fix. While installing gulp missed the parameter to install globally. Sachins-MBP:MyApp sachin$ npm install -g gulp Yay !!!! Its working, thought to write to save time for somebody else.

MQTT : Android step by step guide using Eclipse Paho

For MQTT integration, recently explored Paho Android project, very simple to use, here are the steps: Intialize a client, set required options and connect.     MqttAndroidClient mqttClient = new MqttAndroidClient(BaseApplication.getAppContext(), broker, MQTT_CLIENT_ID);     //Set call back class     mqttClient.setCallback(new MqttCallbackHandler(BaseApplication.getAppContext()));     MqttConnectOptions connOpts = new MqttConnectOptions();     IMqttToken token = mqttClient.connect(connOpts); Subscribe to a topic.     token.setActionCallback(new IMqttActionListener() {       @Override       public void onSuccess(IMqttToken arg0) {            mqttClient.subscribe("TOPIC_NAME" + userId, 2, null, new IMqttActionListener() {                 @Override                 public void ...

Parsing mailing address in Java

Recently came across a problem to parse postal address String using Java, did some research here are some findings. Given String s = "60 Strawberry Hill Ave Stamford CT 06901" Required Result Street = Strawberry Hill Ave City = Stamford Number = 60 zip = 06901 state = CT You can use  JGeocoder public static void main(String[] args) { Map<AddressComponent, String> parsedAddr  =     AddressParser.parseAddress("Google Inc, 1600 Amphitheatre Parkway, Mountain View, CA 94043"); System.out.println(parsedAddr);       Map<AddressComponent, String> normalizedAddr  = AddressStandardizer.normalizeParsedAddress(parsedAddr);         System.out.println(normalizedAddr); } Output will be: {street=Amphitheatre, city=Mountain View, number=1600, zip=94043, state=CA, name=Google Inc, type=Parkway} {street=AMPHITHEATRE, city=MOUNTAIN VIEW, number=1600, zip=94043, state=CA, name=GOOGLE INC, type=PKWY} There is ano...

Clean and Simple Email Sender Design

Recently review design for an email sender with following requirements: Build a service to send email Service must have failover recovery, in youcase if system goes down and comes back up it should still send out pending email reminders You are not expecting any acknowledgements for the messages sent. The design proposal in place was to use a funky framework with persistence store etc etc.  After going through the simple requirements stated above, used following clean and simple design and I am happy to say we made right decision: Use Java Mail API to send email reminders Create a table which stores reminders to be sent and update a flag after email reminder is sent In case system goes down, you can resend all reminders for which flag was not set. It was so simple and easy to implement and we have all control in our hand and there was no RAMP up time to learn new frameworks. So, if you are confused with n number of ideas available out there using x numbe...

Map Reduce Simplified

Yes it is about parallel and distributed computing, there are tonnes of web pages, books articles, diagrams etc. etc with nice buzz words to talk about Map Reduce, here is the most simplified explanation. Lets take a real life example. 1. Company CEO called all Program Manager's "I need total effort spent this month by noon". Program Manager's no problem sir. Why are Program Manager's not worried because they are going to distribute task :-) 2. Each Program Manager called their project manager asking for effort spent so far. 3. Each Project Manager pulled up effort sheet and provided it to their Program Managers. 4. Program Managers complied received sheet into one file and sent it to CEO. 5. Company CEO collated all the sheets and calculated total effort spent. Each individually broke its task to smaller tasks (Mapped its input task to smaller tasks), Program Manager was required to provide effort spent, he mapped his task to smaller tasks, this is...

Apache Roller Getting Started

If you are thinking to setup a blog website then apache roller is the quickest and simplest thing to do so, below are steps for getting started, though these instructions are present in documentation provided by apache, but hopefully following steps will make it very easy for you. Here you Go !! 1. Download apache roller http://roller.apache.org/download.cgi#roller50 2. Install Tomcat http://tomcat.apache.org/download-70.cgi 3. Download mysql http://dev.mysql.com/downloads/ 4. Unzip apache roller zip file and copy roller-5.0.1-tomcat.war from \roller-weblogger-5.0.1-for-tomcat.zip\roller-weblogger-5.0.1-tomcat\webapp to tomcat webapps folder 5. Create mysql database, dont worry about schema, that will be automatically created later. mysql -u root -p password: ***** mysql> create database rollerdb; mysql> grant all on rollerdb.* to scott@'%' identified by 'tiger'; mysql> grant all on rollerdb.* to scott@localhost identified by 't...

HTML5 Cool Features

HTML5 has come up with lot of features but coolest of them are MathML and SVG support. Tried few quick examples, they make web designing more fun: If you don't see a green circle, red rectangle and a blue line then your browser does not support HTML5, visit following URL to check your browser: http://html5test.com/ Good luck for rich GUI's.

Best way to visit Statue of Liberty

Well it actually depends on how much time you have and for how long you are in New york. If you are in states for shorter time then probably you would take a ferry from battery park. Going from battery park you may have to be in long queues for tickets then ferry and same when you take the ferry back from Ellis island and statue of liberty. But if you are around new york for a longer time and you are traveling with kids then the best way is to rent a car and go to liberty state park in Jersey City. And if you are coming from Connecticut then I would suggest that you take Tappan Zee bridge and Garden state parkway. From Stamford, CT we found this route most convenient and traffic free. From the Jersey side the queues are much much shorter, no waiting. Would strongly recommend especially if you are traveling with kids. We felt so relieved when we went there last weekend with nine month old baby, it would have been so hard to stand in long queues. Also the time that you save from standing...

Watch Youtube HD on PS3

Last few weeks i spent a lot of time searching on internet to watch Youtube HD videos on PS3, there were a few solutions available, but the following worked for me and is the simplest. 1. Open browser on ps3 2. Goto Ps3Youtube.com 3. There is a search box on top, enter your keywords (you may add word HD in your search criteria) 4. From the search list click on a video and play it, thats it !! I know there are some other instructions on website in green colored text but playing the video on same site worked for me. I hope this helps, searching through internet i found lot of people feeling this pain of unable to watch youtube HD videos and low quality that is provided by Youtube XL. Good luck !

View Drools Generated Code

When we execute rules, behind the scene java code is generated which is actually getting executed, to see this java code you need to set configuration path where you want java code generated by drools to be stored. PackageBuilderConfiguration configuration = new PackageBuilderConfiguration(); configuration.setDumpDir(new File("XYZ")); final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory .newKnowledgeBuilder(configuration); Set XYZ as a directory path where you would like drools to store generated code. e.g. XYZ = "c:/drools/codegen" When you run your program the java classes generated for the .drl files are stored at the path XYZ. This generated code is really helpful to understand the behavior in lot of situations.

Listen Hindi Internet Radio Channels on PS3

PS3 is the best gadget i have ever used and its true "It only do everything". Having used it to play games, watch netflix, youtube and see my collection of pictures and listen to songs. I was searching for a way to play radio on PS3 and specifically "Hindi Internet Radio Channels" After spending couple of days, finally I have it working in few easy steps: 1. Download PS3 Media server on you laptop or PC: http://ps3mediaserver.blogspot.com/ 2. Open WEB.conf file of PS3 and add following lines: audiostream.Web,Radio=Desi Radio - www.desi-radio.com,http://76.73.90.27:80/ audiostream.Web,Radio=Desi-Radio - www.desi-radio.com,http://76.73.126.218:80/ 3. Restart PS3 Media Server 4. In your PS3, you should see PS3 Media server, open following path: Web -> Radio You should see "Desi Radio" in list. 5. Click on Desi Radio and you have live hindi songs streaming on your Ps3. I am searching more hindi internet radio channels, will update this blog when i find more...

JSON Optimizing for Faster Rendering

All web applications have fast rendering as one of the primary goals, JSON is a preferred choice in most of AJAX based applications because it is lightweight data interchange format. Consider a scenario where you have to read data from database and render it on UI, typically the steps which will be followed are: a. Send request data to server using AJAX calls b. At server end invoke the Business layer c. Business layer calls the database layer d. Data returned from database layer is populated into business objects e. From business objects build JSON objects, send them back to client f. Client use Javascript libraries to render data on UI. If everything works fine for you, you can stop reading right now, because you are achieving the required goal in the best way. But in real world this might not be working for you because of performance issues at one or the other step mentioned above. Here are few performance tips, they might suite in some of the scenarios and might be th...

Drools - An overview

For Java based applications the most challenging part has always been the business logic maintenance, and pick any applications which you find complex and if we ask ourself how complex it would be moving forward, the answer will always be nX times. What do we do ? Drools comes for Rescue as a Rule Engine. Drools provides mechanism: a. To write business logic in simple english language b. Easy to maintain and very simple to extend c. Reusability of logic by defining keywords in a DSL file and using them in DSLR file. But be careful nothing comes free, everything takes cost in terms of memory and time space. Use Drools if you really have : a. Business logic which you think is getting cluttered with multiple if conditions because of variety of scenarios b. You will have growing demand of increase in the complexity c. The business logic changes would be frequent (1 - 2 times a year would also be frequent) d. Your server's have enough of memory as it is a memory hungar...

Give Me Some Sunshine Keyboard Notes

No doubt about the movie of this song that was one of the best movies but I liked this song and thought to play it, was able to work on some of the begining lines, here are few song notes. Sa Re Umar Hum Ga Ga Re Sa Re Mar mar ke jee liye Ga Ga Re Sa Re Loved playing this song, will work on chords next weekend.

Class Data Sharing

Class data sharing (CDS) a feature introduced in J2SE 5.0 reduces the startup time for Java programming language applications. When the JRE is installed on 32-bit platforms using the Sun provided installer, the installer loads a set of classes from the system jar file into a private internal representation, and dumps that representation to a file, called a "shared archive".Class data sharing is not supported in Microsoft Windows 95/98/ME. During subsequent JVM invocations, the shared archive is memory-mapped in, saving the cost of loading those classes and allowing much of the JVM's metadata for these classes to be shared among multiple JVM processes. The primary motivation for including CDS in the 5.0 release is the decrease in startup time it provides. CDS produces better results for smaller applications because it eliminates a fixed cost: that of loading certain core classes. The smaller the application relative to the number of core classes it uses, the larger the sav...