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( ...
Recent posts

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 ...