<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Complex to Simple - Medium]]></title>
        <description><![CDATA[Keep-up with the industry - Medium]]></description>
        <link>https://medium.com/complex-to-simple?source=rss----fd4eee0a0900---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Complex to Simple - Medium</title>
            <link>https://medium.com/complex-to-simple?source=rss----fd4eee0a0900---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:09:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/complex-to-simple" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AS400 Application Migration to Modern Technology and Infrastructure]]></title>
            <link>https://medium.com/complex-to-simple/as400-application-migration-to-modern-technology-and-infrastructure-1d596003b093?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/1d596003b093</guid>
            <category><![CDATA[ibm-iseries]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[as400]]></category>
            <category><![CDATA[modern-technology]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Wed, 17 Jul 2024 01:10:28 GMT</pubDate>
            <atom:updated>2024-07-17T01:09:53.256Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why Migrate?</h4><ol><li><strong>Aging Workforce and Skill Shortages</strong>: The talent pool for AS400 expertise is shrinking as many experienced professionals retire. Modern platforms have a broader talent base.</li><li><strong>Integration Challenges</strong>: Integrating AS400 systems with modern applications and services can be complex and costly.</li><li><strong>Cost Efficiency</strong>: Modern infrastructure, particularly cloud-based solutions, often offer more cost-effective scalability and maintenance.</li><li><strong>Enhanced Capabilities</strong>: Newer platforms provide advanced features like artificial intelligence, machine learning, and real-time analytics.</li><li><strong>Compliance and Security</strong>: Modern systems can offer enhanced compliance and security features that are easier to manage and update.</li></ol><h4><strong>How ?</strong></h4><p><strong>1. Assessment and Strategy Development</strong></p><ul><li><strong>Inventory Applications and Workloads</strong>: Identify and document all applications, workloads, and dependencies running on AS400.</li><li><strong>Determine Business Objectives</strong>: Understand the business goals driving the migration, such as cost reduction, agility, or modernization.</li><li><strong>Choose the Right Migration Strategy</strong>: Options include re-hosting, refactoring, or replacing with SaaS solutions.</li></ul><p><strong>2. Selecting the Target Platform</strong></p><ul><li><strong>Cloud Platforms</strong>: AWS, Azure, and Google Cloud offer scalable, flexible environments for migrated applications.</li><li><strong>Hybrid Solutions</strong>: Combining on-premises and cloud solutions can provide the best of both worlds.</li></ul><p><strong>3. Data Migration and Integration</strong></p><ul><li><strong>Data Assessment</strong>: Analyze data formats, structures, and volumes to plan for seamless migration.</li><li><strong>Data Cleansing</strong>: Ensure data quality and integrity during migration.</li><li><strong>Integration Tools</strong>: Utilize modern integration tools and middleware to bridge AS400 data with new systems.</li></ul><p><strong>4. Application Modernization</strong></p><ul><li><strong>Refactoring</strong>: Rewrite parts of the application to align with modern architectures and technologies.</li><li><strong>Replacing</strong>: Substitute legacy applications with modern off-the-shelf solutions or SaaS applications.</li></ul><p><strong>5. Testing and Validation</strong></p><ul><li><strong>Comprehensive Testing</strong>: Ensure functionality, performance, and security through rigorous testing.</li><li><strong>Parallel Run</strong>: Run the AS400 applications in parallel with the new system to validate operations before full cutover.</li></ul><p><strong>6. Training and Change Management</strong></p><ul><li><strong>Training Programs</strong>: Educate staff on new systems and technologies.</li><li><strong>Change Management</strong>: Manage organizational change to ensure smooth adoption and minimize disruption.</li></ul><p><strong>7. Post-Migration Optimization</strong></p><ul><li><strong>Monitoring and Maintenance</strong>: Continuously monitor performance and make necessary adjustments.</li><li><strong>Optimization</strong>: Leverage modern tools and practices to continually optimize the new environment.</li></ul><p>Migrating AS400 applications to modern technology and infrastructure is a strategic move that can provide significant business benefits. With careful planning, execution, and ongoing optimization, organizations can overcome the challenges of legacy systems and harness the power of modern platforms to drive innovation, efficiency, and growth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCtjQXud6wZMMu9BVWwH1A.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d596003b093" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/as400-application-migration-to-modern-technology-and-infrastructure-1d596003b093">AS400 Application Migration to Modern Technology and Infrastructure</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run WSO2 Api Manager with Docker]]></title>
            <link>https://medium.com/complex-to-simple/run-wso2-api-manager-with-docker-f8fb4d8a7e39?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/f8fb4d8a7e39</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[docker-container]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[wso2-api-manager]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Thu, 11 Jan 2018 21:21:22 GMT</pubDate>
            <atom:updated>2018-01-16T19:55:26.207Z</atom:updated>
            <content:encoded><![CDATA[<p>Lets start with docker terms</p><p><strong>Dockerfile</strong> : A Dockerfile is a text document that contains all the commands you would normally execute manually in order to build a Docker image. <a href="https://docs.docker.com/glossary/?term=Dockerfile">Read more …</a></p><p><strong>Docker Image</strong> : Docker images are the basis of <a href="https://docs.docker.com/glossary/?term=container">containers</a>. An Image is an ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime. An image typically contains a union of layered filesystems stacked on top of each other. An image does not have state and it never changes. <a href="https://docs.docker.com/glossary/?term=image">Read more …</a></p><p><strong>Docker Repository</strong> : A repository is a set of Docker images. A repository can be shared by pushing it to a <a href="https://docs.docker.com/glossary/?term=registry">registry</a> server. The different images in the repository can be labeled using <a href="https://docs.docker.com/glossary/?term=tag">tags</a>. <a href="https://docs.docker.com/glossary/?term=repository">Read more …</a></p><p><strong>Docker Registry</strong> : A Registry is a hosted service containing <a href="https://docs.docker.com/glossary/?term=repository">repositories</a> of <a href="https://docs.docker.com/glossary/?term=image">images</a> which responds to the Registry API. <a href="https://docs.docker.com/glossary/?term=registry">Read more …</a></p><p><strong>Docker Container</strong> : A container is a runtime instance of a <a href="https://docs.docker.com/glossary/?term=image">docker image.</a> <a href="https://docs.docker.com/glossary/?term=container">Read more …</a></p><p>See the following digram to get the idea of how the above terms link together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/0*e14CHwnvUJMQf7l-." /></figure><p>Hope you have high level understanding of how the docker is working. Lets try the above scenario with wso2-api-manager.</p><p><strong>STEP 1:</strong> Create Dockerfile for WSO2-API-Manager</p><p>We need following major components to run the WSO2 API Manager on any environment.</p><ul><li>Java 8</li><li>API Manager Distribution</li></ul><p><a href="https://gist.github.com/malalanayake/3469ac2802af9c6dff8aaaf9a8cc5c33/raw/92113e0a0a30d1b8cc82e995ccae41fa3ff2719a/Dockerfile">view </a><a href="https://gist.github.com/malalanayake/3469ac2802af9c6dff8aaaf9a8cc5c33#file-dockerfile">Dockerfile</a></p><p><strong>STEP 2: </strong>Build the Docker image from the docker file.</p><p>I assume that you have install the docker in your development environment. <a href="https://docs.docker.com/glossary/?term=Docker%20for%20Mac">Read more</a></p><p><strong>$&gt; docker build .</strong></p><p>I got following output since I have already build the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*viE3mSBsPSjQPDBT." /></figure><p><strong>STEP 3:</strong> Tag the image to the repository</p><p>You have to register on the <a href="https://cloud.docker.com/">docker cloud</a> to maintain the image repositories. I have created one for the WSO2-API-Manager.</p><p><a href="https://cloud.docker.com/swarm/sysensor/repository/docker/sysensor/wso2-api-manager">https://cloud.docker.com/swarm/sysensor/repository/docker/sysensor/wso2-api-manager</a></p><p>Then tag your image with the repository that you have created.</p><p><strong>$&gt; docker tag 324ba320d9b6 sysensor/wso2-api-manager</strong></p><p><strong>STEP 4:</strong> Push the tagged repository</p><p>Before you push you may need to login to your docker registry from the command line. <a href="https://docs.docker.com/edge/engine/reference/commandline/login/">Read more …</a></p><p><strong>$&gt; docker push sysensor/wso2-api-manager</strong></p><p><strong>STEP 5:</strong> Run the docker image from the repository</p><p>You have to do the port mapping for the exposed ports from the WSO2-API-Manager to get access from your local computer.</p><p><strong>$&gt;docker run -p 9443:9443 -p 9763:9763 -p 8243:8243 -p 8280:8280 -p 10397:10397 -p 7711:7711 sysensor/wso2-api-manager</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*bIbUE157P_XEdRsg." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*Ac1fiM3hBY8VPY-n." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*uFfyzWOB54Km9ljw." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*sHEXyvtRBWli7MS2." /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8fb4d8a7e39" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/run-wso2-api-manager-with-docker-f8fb4d8a7e39">Run WSO2 Api Manager with Docker</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSL configuration on spring boot application with self signed certificate]]></title>
            <link>https://medium.com/complex-to-simple/ssl-configuration-on-spring-boot-application-with-self-signed-certificate-312b56ef715?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/312b56ef715</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[self-signed-certificate]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Sat, 28 Jan 2017 17:54:27 GMT</pubDate>
            <atom:updated>2017-01-28T17:47:48.967Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s start with What?</p><p><strong>SSL</strong> — (<a href="http://info.ssl.com/article.aspx?id=10241">Secure Sockets Layer</a>) is the standard security technology for establishing an encrypted link between a web server and a browser. This link ensures that all data passed between the web server and browsers remain private and integral</p><p><strong>Self signed certificate</strong> — is an identity <strong>certificate</strong> that is <strong>signed</strong> by the same entity whose identity it certifies</p><p><strong>Keystore and Truststore — </strong>is used to store SSL certificates in <strong>Java</strong> but there is subtle <strong>difference between</strong> them. <strong>truststore</strong> is used to store public certificates while <strong>keystore</strong> is used to store private certificates of client or server</p><p>Let’s pretend you need to build simple application with spring boot(with fat jar deployment) and you need to expose the application with encryption(over https). In oder to do that you have to configure the spring boot application over https by adding the key-store which holds the certificates. So when its comes to get the certificate you have to choices either self signed or signed by one of the public certificate authorities(CAs)</p><p>Now the question is why we need to go for the self signed certificate rather public CA signed certificate. The main reason that people do self-signed certificates because it doesn’t add any cost it is free, But if the site is public facing it would be better to go for the public CA signed certificate rather the self signed. So if you have public CA signed certificate then client browser do verify the certificate without any problem because the browser by default identifies the public CAs otherwise it will show as follows which is not trusted site unless you import the certificate to the browser trust store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*2oOOLTtln9RX2qTo." /></figure><p>The good thing is you will get the encryption over <strong>https</strong> no matter which certificate you use.</p><p>Best scenario that I’m thinking is to create a self-signed certificate when you are in DEV and TEST environments but when you need to expose that to PROD which will be exposing to public use the public CA signed certificate. But if it is internal facing then you can still use the self-signed certificate once you have registered the certificate on clients browser trust stores.</p><p><strong>How to create the self signed certificate with </strong><a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html"><strong>JAVA key-tool</strong></a>.</p><p>1. Create Java Key Store with certificate</p><p><em>keytool -genkey -keyalg RSA -alias </em><strong><em>selfsigned</em></strong><em> -keystore </em><strong><em>${DEST_PATH}/keystore.jks</em></strong><em> -storepass </em><strong><em>${PASS_WORD}</em></strong><em> -validity 360 -keysize 2048</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*8QuPujpULZat54Cm." /></figure><p>2. List out the details of the given keystore</p><p>keytool -v -list -keystore <strong>${PATH_TO_KEYSTORE}/</strong>keystore.jks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*eXp02pwrhDSabAe4." /></figure><p>3. Export self-signed certificate if you want to distribute to the clients.</p><p>keytool -exportcert -rfc -alias selfsigned -keystore <strong><em>${DEST_PATH}/keystore.jks</em></strong> -file <strong><em>${DEST_PATH}/</em></strong>selfsigned.crt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*Wquw5ixZ9EAEsG3Y." /></figure><p>4. Verify the certificate</p><p>keytool -printcert -file <strong>${PATH_TO_CERTIFCATE}</strong>/selfsigned.crt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*5WpG7-3IrICD6d3f." /></figure><p>So now need to expose your .jks file to spring boot application and configure that to be exposed as https. Fist of all place your keystore.jks file on the class path and then set the following properties in application-*.properties file.</p><pre>server.port=8443<br>server.ssl.key-alias=selfsigned<br>server.ssl.key-password=test123<br>server.ssl.key-store=classpath:keystore.jks<br>server.ssl.key-store-provider=SUN<br>server.ssl.key-store-type=JKS</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=312b56ef715" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/ssl-configuration-on-spring-boot-application-with-self-signed-certificate-312b56ef715">SSL configuration on spring boot application with self signed certificate</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make the java runtime to trust the certificate present by the host]]></title>
            <link>https://medium.com/complex-to-simple/how-to-make-the-java-runtime-to-trust-the-certificate-present-by-the-host-e68e0f8f84b3?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/e68e0f8f84b3</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[keystore]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Sat, 14 Jan 2017 19:10:13 GMT</pubDate>
            <atom:updated>2017-01-14T19:10:13.467Z</atom:updated>
            <content:encoded><![CDATA[<p>URL -https://my-site.com/test</p><p>Let’s start with simple example. If you invoke above URL through your simple java application you will simply get the <strong>SSLHandshakeException</strong> because it is exposed as https endpoint and the java runtime is not going to trust the certificate that present through the URL call. So before you invoke the service you have to present the certificate to your java runtime to trust the certificate. Then when ever you call the URL it will trust the certificate. You can do this in two different ways as follows.</p><ol><li>Download and import the certificate to your java runtime certificate store.</li><li>Write the code in your program to trust the certificate provided by the host.</li></ol><p><strong>1. Download and import the certificate to your java runtime certificate store.</strong></p><p>First of all you have to download the certificate from the host. In order to do that you can simply go to the URL through the browser and then download the certificate to your local machine as <strong>.cer</strong> file.</p><p>In <strong>Chrome</strong> browser you can simply go to the certificate as follows and drag and drop to the local folder. I choose the <a href="https://google.com/"><strong>https://google.com</strong></a> as a example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*mIScVAnENXEUSkix." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*HIJJwHF7TrAM8vgS." /></figure><p>So once you have downloaded the certificate you should be able to use the keytool to import the certificate.</p><p>keytool -import -alias <strong>google</strong> -keystore <strong>${PATH_TO_JDK}</strong>/jre/lib/security/cacerts -file <strong>${PATH_TO_CERT_FILE}</strong></p><p>You have to provide the keystore password as “<strong>changeit</strong>” unless you have customized it.</p><p>ex/</p><p>keytool -import -alias <strong>google</strong> -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre/lib/security/cacerts -file /Users/dmalalan/Documents/www.google.com.cer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*ldJkYgUFQRAh1rjl." /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*5E7Cx20CZ400-qwS." /></figure><p><strong>2. Write the code in your program to trust the certificate provided by the host</strong></p><p>You need to use the following code sample before you invoke the URL. This is just allow the runtime to trust all the certificates presented by the host but you need to be careful with this approach because host can present the bogus certificates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*KkG3Wodk7EgSx5n_." /></figure><p>References : <a href="http://stackoverflow.com/questions/33868167/javax-net-ssl-sslhandshakeexception-sun-security-validator-validatorexception?answertab=active#tab-top">sample code</a> &amp; <a href="https://www.grim.se/guide/jre-cert">sample instructions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e68e0f8f84b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/how-to-make-the-java-runtime-to-trust-the-certificate-present-by-the-host-e68e0f8f84b3">How to make the java runtime to trust the certificate present by the host</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RMI vs JMS Clarification]]></title>
            <link>https://medium.com/complex-to-simple/rmi-vs-jms-clarification-e496ed9e1ee?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/e496ed9e1ee</guid>
            <category><![CDATA[jms]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[distributed-computation]]></category>
            <category><![CDATA[mir]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Tue, 19 Apr 2016 21:34:55 GMT</pubDate>
            <atom:updated>2016-06-18T16:27:30.352Z</atom:updated>
            <content:encoded><![CDATA[<p>Most of the developers and system designers may know what is <strong>RMI</strong> and what is <strong>JMS</strong> but when they come to develop or design the real world application then they are in trouble with which one to choose. So I thought its better to publish some thoughts on this.</p><p>Lets start with the regular descriptions.</p><p><strong>RMI — Remote Method Invocation</strong></p><figure><img alt="rmi-5" src="https://cdn-images-1.medium.com/max/400/0*JtFDJxibMKUoqpdY.gif" /></figure><ol><li>Synchronous communication — <em>Request initiator wait for the response. In order to archive this RMI service need to be up at the time of communication.</em></li><li>Tightly coupled — <em>Requesting system is couple to the declared interface in RMI service.</em></li><li>Unreliable communication — <em>If something happen in-between the communication you will loose the request and you have to handle those in application level.</em></li></ol><p><strong>Advantages :</strong><br>Easy to start by writing the simple interface and the implementation.</p><p><strong>Disadvantages :</strong><br>Can use only the java supported platforms.<br>Cannot use the code out of the scope of java.<br>Security issues need to be monitored more closely.</p><p><strong>Using RMI :</strong><br>If you have process with heavy computation and need more computation power to improve the performance then you can go with RMI because it will give you the computation power on simple method call.</p><p><strong>JMS — Java Message Service</strong></p><p><strong>Topic</strong> — Publish and subscribe model</p><figure><img alt="publish_subscribe" src="https://cdn-images-1.medium.com/max/522/0*M5ZmTtrkaG7lXsTx.gif" /></figure><p><strong>Queue</strong> — Load balancing model</p><figure><img alt="qs-multiple-consumers" src="https://cdn-images-1.medium.com/max/600/0*vfKaEgt7w8koniJZ.gif" /></figure><ol><li>Asynchronous communication — Request initiator is not going to wait for the response and it just send the message out then close the connection. No need to have backing service up at the time of communication.</li><li>Loosely coupled — It is not tight to the service as RMI. You can use any kind of data format to communicate via message <strong>QUEUEs</strong> and <strong>TOPICs</strong>. ex/ <strong>XML, JSON</strong></li><li>Reliable communication — This is not like RMI because this communication has message broker in-between the systems and message broker has capability of error handling and the persistent of the messages and handover them to the responsible party.</li></ol><p><strong>Advantages :</strong><br>Due to asynchronous messaging, All the modules don’t need to be up for the application to function as a whole.</p><p><strong>Disadvantages :</strong><br>Extra overhead on setup and maintain the message broker</p><p><strong>Using JMS :</strong><br>If you have any process which will be getting heavy request load and that can be run asynchronously then go for <strong>JMS Queue</strong> implementation and run them separately and communicate via the queue. The next point is if you have a process that need to send the data to many downstream applications then go for <strong>JMS</strong> <strong>Topic</strong> implementation.</p><p><strong>By the way remember this, There is no such a thing as bad technology only bad choice.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e496ed9e1ee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/rmi-vs-jms-clarification-e496ed9e1ee">RMI vs JMS Clarification</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache-Camel with Java (Integration)]]></title>
            <link>https://medium.com/complex-to-simple/apache-camel-with-java-integration-6efe0ff765ae?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/6efe0ff765ae</guid>
            <category><![CDATA[activemq]]></category>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[camel]]></category>
            <category><![CDATA[routing]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Sun, 11 Oct 2015 19:55:50 GMT</pubDate>
            <atom:updated>2016-06-18T16:27:46.283Z</atom:updated>
            <content:encoded><![CDATA[<p>Apache camel is very useful routing implementation. If you involve with some integration then you will realize how it is solving your problems. When technology evolves Integration will come to the picture as follows.</p><p>A company has a software, which runs in old technology. The company wants to go for another tool, which is going to work on latest platforms and technology. But still the company need to get integrated with the old system because new tool depends on the company data, which is in old system. In this case we need to come up with good solution that can be bridge to the communication. In the industry we used <strong>Message Queues </strong>to make realtime communication so if it is realtime we can use the message queue in between the two systems.</p><p>Above sample is really simple scenario but think about if you have number of systems in downstream to communicate, then you will need proper routing mechanism otherwise you will end up with multiple endpoints, which is doing the same thing (duplicate work). <strong>Apache Camel</strong> is open source tool for routing data with JAVA application.</p><figure><img alt="Apache Camel" src="https://cdn-images-1.medium.com/max/645/0*wwO9S82IjkAlFAJE." /></figure><p>I have created simple adapter with apache camel routes. It explains how to use camel routes in implementation level. This is a maven project produce the war file, which you can deploy on apache tomcat and subscribe to the queue. ( I hope you have understanding of use Spring Boot and Spring Profile) This sample doesn’t contain JMS client to publish messages so I’m going to use the ActiveMQ console.</p><p>You can clone the whole project in following location. <a href="https://github.com/malalanayake/camel-sample">https://github.com/malalanayake/camel-sample</a></p><p>In code level you need to create the camel route and camel message processor as you wish. See the following rout configuration and sample message processor implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbea3f3ff8dd6f4e107adc0fbc96438e/href">https://medium.com/media/fbea3f3ff8dd6f4e107adc0fbc96438e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/242e843ade71f3336973c32959b41d29/href">https://medium.com/media/242e843ade71f3336973c32959b41d29/href</a></iframe><p>Follow the instruction to deploy and run the adapter.</p><p>Start Apache ActiveMQ and create the queue as “<strong>sample_queue” </strong>then change the <a href="https://gist.github.com/malalanayake/c5e9f5d37f903719f2cb#file-application-dev-properties"><strong>application-dev.properties</strong></a> in resource folder. I used spring profile for switch the context so you need to update the default profile as follows in <a href="https://gist.github.com/malalanayake/8f59a6dbc2fd92f0367f"><strong>application.properties</strong></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f67488e98612d0d92c1284f3d04a88c6/href">https://medium.com/media/f67488e98612d0d92c1284f3d04a88c6/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b2c2ab65b1c446ba98756a99b688535/href">https://medium.com/media/3b2c2ab65b1c446ba98756a99b688535/href</a></iframe><p>Now build the WAR file and deploy the WAR on Apache Tomcat. Then you will see the WAR adapter is going to subscribe to the <strong>sample_queue</strong></p><figure><img alt="activemq" src="https://cdn-images-1.medium.com/max/645/0*elNbB7yfFBBwdfRI." /></figure><p>Now go to operation and do “<strong>Send To</strong>”. Now your adapter is going to consume the given message. See the logs in tomcat console.</p><figure><img alt="send" src="https://cdn-images-1.medium.com/max/645/0*GjKLbFVj-xcwvev9." /></figure><figure><img alt="after_sent" src="https://cdn-images-1.medium.com/max/645/0*sP-o7uSx0lgAqnfq." /></figure><figure><img alt="console" src="https://cdn-images-1.medium.com/max/645/0*gFg-AkgFcNEm1g11." /></figure><figure><img alt="after_consume" src="https://cdn-images-1.medium.com/max/645/0*JzrcKc9aeePdTSBF." /></figure><p>The routing mechanism and routing patterns might vary with the problem domain. However the implementation perspective is similar. For example subscribe to message queue and then route the message to endpoints. I hope you got some idea how to use the camel routes.</p><p>Enjoy the integration.</p><p>[polldaddy poll=9121750]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6efe0ff765ae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/apache-camel-with-java-integration-6efe0ff765ae">Apache-Camel with Java (Integration)</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Java pass by value]]></title>
            <link>https://medium.com/complex-to-simple/understanding-java-pass-by-value-a35112c5e641?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/a35112c5e641</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[pass-by-value]]></category>
            <category><![CDATA[core-java]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Mon, 08 Dec 2014 04:48:17 GMT</pubDate>
            <atom:updated>2016-06-18T16:27:34.260Z</atom:updated>
            <content:encoded><![CDATA[<p>I think most of the people they are confused with this concept because it is appearing in different angles. First thing I have to say that Java is pass by Value not pass by reference. I’ll show the example to clear the concept.</p><p>First of all I’ll show the sample code, then you can see the confused point that you will drive to think that java is pass by reference. you can checkout the full source <a href="https://github.com/malalanayake/Java-PassBy-Value">here</a>.</p><p>[code language=”java”]<br>package sample.passby.value;</p><p>/**<br> * Point class<br> * <br> * @author malalanayake<br> *<br> */<br>public class Point {<br> private int x;<br> private int y;</p><p>public Point(int x, int y) {<br> this.x = x;<br> this.y = y;<br> }</p><p>public int getX() {<br> return x;<br> }</p><p>public void setX(int x) {<br> this.x = x;<br> }</p><p>public int getY() {<br> return y;<br> }</p><p>public void setY(int y) {<br> this.y = y;<br> }</p><p>}<br>[/code]</p><p>[code language=”java”]<br>package sample.passby.value;</p><p>/**<br> * Demonstration of Java pass by value<br> * <br> */<br>public class App {<br> public static void main(String[] args) {<br> int xOrginal = 0, yOriginal = 0;<br> System.out.println(“Original Coordinates:” + xOrginal + “,” + yOriginal);<br> App.getNextCoordinates(xOrginal, yOriginal);<br> System.out.println(“After modification of Coordinates:” + xOrginal<br> + “,” + yOriginal);</p><p>Point pOriginal = new Point(0, 0);<br> System.out.println(“Original Point:” + pOriginal.getX() + “,”<br> + pOriginal.getY());<br> App.getNextCoordinates(pOriginal);<br> System.out.println(“After modification of Point:” + pOriginal.getX()<br> + “,” + pOriginal.getY());</p><p>}</p><p>public static void getNextCoordinates(int x, int y) {<br> x = 12;<br> y = 15;<br> }</p><p>public static void getNextCoordinates(Point point) {<br> point.setX(12);<br> point.setY(15);<br> }<br>}<br>[/code]</p><p>Output:<br><strong>Original Coordinates:0,0<br>After modification of Coordinates:0,0<br>Original Point:0,0<br>After modification of Point:12,15</strong></p><p>So you can see in the above example if I pass the primitives then it is not going to change the values. But if I pass the object type then if i change something on that it will reflect. The understanding point is Java every time pass by value and if it is primitive then it is just pass the value to the given argument and nothing will reflect. See the following image for understanding.</p><figure><img alt="PassByValue (1)" src="https://cdn-images-1.medium.com/max/300/0*rVXEZO7j3umcwT6_." /></figure><p>But if we pass the Object type then java pass the <strong>“reference by value”</strong>. This is the tricky point that we need to understand.</p><figure><img alt="PassByValue (2)" src="https://cdn-images-1.medium.com/max/300/0*AcQv-BuglI8R2zC9." /></figure><p>So you can see if we pass some Object type to some function actually its going to pass the pointer to that Object. That means if we change some thing on that it will be reflect on that. But be aware about this, You cannot change the pointer which is not in the scope. As an example if you do following coding in <strong>getNextCoordinates(Point point)</strong> method it will not reflecting anything on the original object because it is going to change the pointer of the object which is under that scope not the original object that passed to the function.</p><p>[code language=”java”]<br>public static void getNextCoordinates(Point point) {<br> point = new Point(12,15);<br>}<br>[/code]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a35112c5e641" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/understanding-java-pass-by-value-a35112c5e641">Understanding Java pass by value</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparator and Comparable interfaces in Java]]></title>
            <link>https://medium.com/complex-to-simple/comparator-and-comparable-interfaces-in-java-19f2061150c7?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/19f2061150c7</guid>
            <category><![CDATA[collection]]></category>
            <category><![CDATA[sorting]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[comparable]]></category>
            <category><![CDATA[comparator]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Fri, 05 Dec 2014 23:48:28 GMT</pubDate>
            <atom:updated>2016-06-18T16:27:47.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="c4" src="https://cdn-images-1.medium.com/max/300/0*WARoVkcSURs48VGu." /></figure><figure><img alt="c3" src="https://cdn-images-1.medium.com/max/150/0*d_lzwHgihrfFYAY3." /></figure><p>Comparator and Comparable interfaces are heavily used in the Java development to manage the sorting of the collections. This approach will achieve the software engineering goals such as extensibility, reusability, modularity etc. In this post I like to explain this mechanism of how to use comparator and comparable interfaces. First thing is we are going to use the <strong>Collections API</strong> for sorting which is provided by Java. So we have to expose sorting comparison logic without exposing the internal structure of our custom implementation.<a href="https://github.com/malalanayake/Comparable-Comparator-Java">Here</a> you can download the source.</p><p>Lets look at how to use <strong>Comparable</strong> interface.</p><p>As an example I have Employee class which is created by me and need to sort the collection of employees according to the employee age.</p><ul><li>First we need to implement the <strong>Comparable</strong> interface in Employee class and override the <strong>compareTo</strong> method</li><li>Then we can pass the employee collection to the Collections.sort() API to do the sorting.</li><li>Underneath what will happen Collections.sort() method will access the compareTo implementation and get the decision according to the return value.</li></ul><p>See the code sample below to get clear understanding.</p><p>[code language=”java”]<br>package sample.common;</p><p>/**<br> * Employee Class<br> *<br> * @author malalanayake<br> *<br> */<br>public class Employee implements Comparable&lt;Employee&gt; {<br> private int id;<br> private String name;<br> private int age;<br> private int salary;</p><p>public Employee(int id, String name, int age, int salary) {<br> this.id = id;<br> this.name = name;<br> this.age = age;<br> this.salary = salary;<br> }</p><p>public int getId() {<br> return id;<br> }</p><p>public void setId(int id) {<br> this.id = id;<br> }</p><p>public String getName() {<br> return name;<br> }</p><p>public void setName(String name) {<br> this.name = name;<br> }</p><p>public int getAge() {<br> return age;<br> }</p><p>public void setAge(int age) {<br> this.age = age;<br> }</p><p>public int getSalary() {<br> return salary;<br> }</p><p>public void setSalary(int salary) {<br> this.salary = salary;<br> }</p><p>public int compareTo(Employee o) {<br> if (o.getAge() == this.age) {<br> return 0;<br> } else if (o.getAge() &gt; this.age) {<br> return -1;<br> } else {<br> return 1;<br> }<br> }</p><p>@Override<br> public String toString() {<br> return “[Employee ID:” + this.getId() + “ Name:” + this.getName()<br> + “ Age:” + this.getAge() + “ Salary:” + this.getSalary() + “]”;<br> }</p><p>}<br>[/code]</p><p>[code language=”java”]<br>package sample.app;</p><p>import java.util.ArrayList;<br>import java.util.Collections;<br>import java.util.Comparator;<br>import java.util.List;</p><p>import comparator.sample.app.SalaryComparator;<br>import sample.common.Employee;</p><p>/**<br> * Application Class<br> *<br> * @author malalanayake<br> *<br> */<br>public class App {<br> public static void main(String[] args) {<br> List&lt;Employee&gt; employees = new ArrayList&lt;Employee&gt;();</p><p>Employee emp_dinuka = new Employee(101, “Dinuka”, 27, 95000);<br> employees.add(emp_dinuka);</p><p>Employee emp_malalanayake = new Employee(100, “Malalanayake”, 27, 85000);<br> employees.add(emp_malalanayake);</p><p>Employee emp_Thanuja = new Employee(305, “Thanuja”, 23, 150000);<br> employees.add(emp_Thanuja);</p><p>Employee emp_Damith = new Employee(204, “Damith”, 20, 75000);<br> employees.add(emp_Damith);</p><p>System.out.println(“=======Before Sorting=====”);<br> for (Employee emp : employees) {<br> System.out.println(emp.toString());<br> }</p><p>Collections.sort(employees);<br> System.out.println(“=======After Sorting=====”);<br> for (Employee emp : employees) {<br> System.out.println(emp.toString());<br> }<br> }<br>}</p><p>[/code]</p><p>You can see in the above case we can have only one sorting logic over the employee class. Lets think about sometimes if I need to sort the Employee by their salaries and sometimes I need to sort by their age. Then you can see we don’t have space to put that logic in my Employee class because already I have method implementation according to the age. In this kind of situation <strong>Comparator</strong> comes to the picture to solve the problem.</p><p>Lets look at how to use <strong>Comparator</strong></p><ul><li>So first you have to have comparator implementation class. In above case I have created <strong>SalaryComparator</strong> class which is provide the salary comparison.</li><li>Then you can pass the employee collection to overloaded method in collections api to sort the given collection according to the given comparator.</li></ul><p>[code language=”java”]<br>package comparator.sample.app;</p><p>import java.util.Comparator;</p><p>import sample.common.Employee;</p><p>/**<br> * Salary Comparator<br> *<br> * @author malalanayake<br> *<br> */<br>public class SalaryComparator implements Comparator&lt;Employee&gt; {</p><p>public int compare(Employee o1, Employee o2) {<br> if (o1.getSalary() &gt; o2.getSalary()) {<br> return 1;<br> }</p><p>if (o1.getSalary() &lt; o2.getSalary()) {<br> return -1;<br> }<br> return 0;<br> }</p><p>}<br>[/code]</p><p>[code language=”java”]<br>package sample.app;</p><p>import java.util.ArrayList;<br>import java.util.Collections;<br>import java.util.Comparator;<br>import java.util.List;</p><p>import comparator.sample.app.SalaryComparator;<br>import sample.common.Employee;</p><p>/**<br> * Application Class<br> *<br> * @author malalanayake<br> *<br> */<br>public class App {<br> public static void main(String[] args) {<br> List&lt;Employee&gt; employees = new ArrayList&lt;Employee&gt;();</p><p>Employee emp_dinuka = new Employee(101, “Dinuka”, 27, 95000);<br> employees.add(emp_dinuka);</p><p>Employee emp_malalanayake = new Employee(100, “Malalanayake”, 27, 85000);<br> employees.add(emp_malalanayake);</p><p>Employee emp_Thanuja = new Employee(305, “Thanuja”, 23, 150000);<br> employees.add(emp_Thanuja);</p><p>Employee emp_Damith = new Employee(204, “Damith”, 20, 75000);<br> employees.add(emp_Damith);</p><p>SalaryComparator comparator = new SalaryComparator();<br> Collections.sort(employees, comparator);<br> System.out.println(“=======After Sorting By Salary=====”);<br> for (Employee emp : employees) {<br> System.out.println(emp.toString());<br> }<br> }<br>}<br>[/code]</p><p>So If you have multiple sorting logics then you have to go for the Comparator because then only you can have multiple logics. Otherwise you can encapsulate the logic inside your custom implementation class by using the Comparable interface. I hope you got the idea of how to use the comparator and comparable interfaces.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19f2061150c7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/comparator-and-comparable-interfaces-in-java-19f2061150c7">Comparator and Comparable interfaces in Java</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSP, Servlet, Scope variables and Init Parameters]]></title>
            <link>https://medium.com/complex-to-simple/jsp-servlet-scope-variables-and-init-parameters-747c5cb1671a?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/747c5cb1671a</guid>
            <category><![CDATA[scope-variables]]></category>
            <category><![CDATA[jsp]]></category>
            <category><![CDATA[servlet]]></category>
            <category><![CDATA[init-parameters]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Fri, 10 Oct 2014 06:03:44 GMT</pubDate>
            <atom:updated>2016-06-18T16:27:28.212Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are getting involved in Java EE development you have to have good knowledge about the JSP and Servlets. Servlets are server side components that provide a powerful mechanism for developing server side programs. JavaServer Pages (<strong>JSP</strong>) is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types.</p><p>First look at how request and response handle in servlet container. Servlet container create one instance from each servlet but its going to serve for multiple threads. See the following diagram. You can see HTTP Request comes to the container and it will create the HTTPServletRequest, HTTPServletResponse objects. Finally put those two objects in new thread and let the thread to access the instance of specified servlet.</p><figure><img alt="Servlet Conatiner" src="https://cdn-images-1.medium.com/max/645/0*XGRxFEVfK-dZE_dk." /></figure><p>According to the above process you can see we have to be careful of the thread safety of instance variable in servlet. Because each and every thread is gong to access the single Servlet instance. If you have some instance variable in the servlet which is going to modify with in the thread you have to make it thread safe.</p><p>Look at the Servlet life cycle</p><p><strong>init()</strong> — this method is going to run only one time<br><strong>service()</strong> — this method is going to run each time the request comes to the servlet. And it will identify either <strong>doGet</strong> or <strong>doPost</strong> to execute according to the request.</p><figure><img alt="Servlet Life Cycle" src="https://cdn-images-1.medium.com/max/270/0*uxoP-Yvh_pDemjzZ." /></figure><p>JSP life cycle is same as Servlet, only additional thing is its going to translate to the servlet. Ultimately its acts as Servlet. JSP you can override two methods which is <strong>jspInit()</strong> and <strong>jspDestroy(). </strong>But you <strong>cannot override the jspService()</strong> method.</p><p>Lets talk about Scope variables.</p><p>1. <strong>Application Context </strong>— In other words we can say this is <strong>servletContext. </strong>You can use servletContext to store the global data which is going to share through out the application. This is <strong>not thread safe</strong>. You can easily access this context as follows.</p><pre>request.getServletContext();<br>request.getServletContext().setAttribute(&quot;attribute_name&quot;,&quot;value&quot;);</pre><p>2. <strong>Session Context </strong>— Session management is handling by the servlet container and you can store the user specific data on session. This object is <strong>not thread safe</strong>.</p><pre>request.getSession(); //going to create the session if session is not exist.<br>request.getSession(false); // Not going to create the session.</pre><p>3. <strong>Request Attributes</strong> — You can use this scope to carry the data in server side from one resource to another. As an example while you are doing the request forwarding. This is thread safe because one request is handle by one thread.</p><pre>request.setAttribute(&quot;attribute_name&quot;,&quot;value&quot;);<br>request.getAttribute(&quot;attribute_name&quot;); // return the Object you have to cast it</pre><p><strong>Config Parameters</strong></p><p>We have two different types of init parameters. One is available for the whole application and the other one is only for specific servlet. These parameters are <strong>deployment time constants. </strong>That means once the application is deployed you cannot change it. These parameters are going to declare in web.xml</p><p>[code language=”xml”]<br>&lt;web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=”http://java.sun.com/xml/ns/javaee&quot; xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot; version=”3.0&quot;&gt;<br> &lt;servlet&gt;<br> &lt;servlet-name&gt;springmvc&lt;/servlet-name&gt;<br> &lt;servlet-class&gt;<br> org.springframework.web.servlet.DispatcherServlet<br> &lt;/servlet-class&gt;<br> &lt;init-param&gt;<br> &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br> &lt;param-value&gt;/WEB-INF/config/springmvc-config.xml&lt;/param-value&gt;<br> &lt;/init-param&gt;<br> &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br> &lt;/servlet&gt;<br> &lt;servlet-mapping&gt;<br> &lt;servlet-name&gt;springmvc&lt;/servlet-name&gt;<br> &lt;url-pattern&gt;/&lt;/url-pattern&gt;<br> &lt;/servlet-mapping&gt;<br> &lt;context-param&gt;<br> &lt;param-name&gt;ApplicationName&lt;/param-name&gt;<br> &lt;param-value&gt;ApplicationName&lt;/param-value&gt;<br> &lt;/context-param&gt;<br>&lt;/web-app&gt;<br>[/code]</p><p>1. <strong>Global init parameter</strong></p><pre>getServletContext().getInitParameter(&quot;ApplicationName&quot;);</pre><p>2. <strong>Specified int parameter</strong></p><pre>getServletConfig().getInitParameter(&quot;contextConfigLocation&quot;);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=747c5cb1671a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/jsp-servlet-scope-variables-and-init-parameters-747c5cb1671a">JSP, Servlet, Scope variables and Init Parameters</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Selecting proper data structures for the realtime problems]]></title>
            <link>https://medium.com/complex-to-simple/selecting-proper-data-structures-for-the-realtime-problems-4b264bfd3c82?source=rss----fd4eee0a0900---4</link>
            <guid isPermaLink="false">https://medium.com/p/4b264bfd3c82</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Dinuka Malalanayake]]></dc:creator>
            <pubDate>Fri, 26 Sep 2014 02:39:16 GMT</pubDate>
            <atom:updated>2016-06-18T16:27:23.485Z</atom:updated>
            <content:encoded><![CDATA[<p>As a software engineer you have to have a proper understanding about data structures and the corresponding implementations. In real world application development you need to think about the efficiency of the operations and it should fit for the entire domain that the solution is addressing. So in this blog post Im going to explain some of the data structures implemented in java.</p><p>Look at the following class hierarchy.</p><figure><img alt="collections" src="https://cdn-images-1.medium.com/max/300/0*Dr4SC0icR646ftVo." /></figure><p><strong>1. LinkedList </strong>— Use the linked list If you need to maintain the list which is <strong>no need random access</strong> to the values and needed frequent insertions and deletions.<br>Insertion and deletion is O(1) and access the (k)th element is O(n). <br>But remember LinkedList is not thread safe.</p><p><strong>2. ArrayList — </strong>Use the array list if you need the random access to the values frequently and same as you don’t need frequent insertion and remove operations.<br>Access the (k)th element is O(1) and insertion and deletion is O(n).<br>Same as LinkedList remember ArrayList is not thread safe.</p><p><strong>3. Vector — </strong>When you need to maintain thread safety over the ArrayList use the Vector. If you don’t need any synchronization on each and every operations you have to go for ArrayList otherwise it will give bad performance impact on each operation.</p><p><strong>4. PriorityQueue — </strong>We know that queue is a first come first serve basis but some times we need to get the things according to the priority. So if you have that kind of problem use the priority queue. But remember PriorityQueue is not thread safe.</p><p><strong>5. HashSet — </strong>It is not maintaining the duplicates. When you need to maintain the unique list of objects you can use the HashSet. HashSet allows the NULL Objects but it is not maintain the insertion sequence. If you need to maintain the insertion sequence you have to use the <strong>LinkedHashSet</strong>.</p><p><strong>6. TreeSet — </strong>Same as HashSet this data structure maintain the duplicate free collection and additionally its provide the sorted order of the elements.TreeSet is not allow the NULL objects. Guarantees log(n) time cost for the basic operations add, remove and contains.</p><p><strong>7. HashTable — </strong>This data structure is useful when you need to do the insertion, deletion and the quick access to the given element in constant time. All operations are in O(1).Hash tables are not maintain the insertion sequence. I would like to explain the HashTable little bit in depth because this is commonly using in the industry. As an example a router table. When a packet has to be routed to a specific IP address, the router has to determine the best route by querying the router table in an efficient manner.</p><p>To use the Hash tables you have to implement the equals(), hashCode() functions the Object type that you are going to store in the HashTable.<br>hashCode() — as a best practice you have to consider all attributes in the object to generate the hash code. See the following example.<br>[code language=”Java”]<br>public class Employee {<br> int employeeId;<br> String name;<br> Department dept;<br> <br> // other methods would be in here <br> <br> @Override<br> public int hashCode() {<br> int hash = 1;<br> hash = hash * 17 + employeeId;<br> hash = hash * 31 + name.hashCode();<br> hash = hash * 13 + (dept == null ? 0 : dept.hashCode());<br> return hash;<br> }<br>}<br>[/code]<br>Once you call the insert method in the hash table it will calculate the hash value and then store the the data according to the hash value.<br>[code language=”java”]<br> int hashValue = hashCode % hash_table_size;<br>[/code]</p><p>There are several ways to handle the collisions in hash table.<br>1. Separate Chaining — Maintain the list in each slot. If there are two objects with same hash value it is going to store in that list. This implementation has extra overhead to maintain the list. Total Performance is depend on the number of elements in the list.</p><p>2. Open Addressing — In this approach it is find the next available slot according to the probing function.<br>Linear prob — <em>h(x), h(x)+1, h(x)+2, h(x)+3,..</em><br>Quadratic prob — <em>h(x), h(x)+1², h(x)+2², h(x)+3²,..</em><br>Double hashing — <em>h(x), h(x)+1*h’(x), h(x)+2*h’(x), h(x)+3*h’(x),..</em></p><p>Delete elements in hash table — If hash table is use open addressing then it is logically delete the value from the table by setting a flag.</p><p>Performance of the hash table is denoted by alpha load factor.<br>[code language=”java”]<br> alpha = number_of_elements/table_size;<br>[/code]</p><p>If hash table is filled we need to do the rehashing. Rehashing is done according to the load factor. If load factor reaches to some level we need to do the rehashing. This is the only disadvantage of the HashTable.</p><p><strong>8. HashMap — </strong>Hash map is used when you need to store the elements as key, value pairs.In hash map you cannot duplicate the key but you can duplicate the value with different key. This is not maintain the insertion sequence. If you need to maintain the insertion sequence you have to use the <strong>LinkedHashMap</strong>. Remember HasMap is not thread safe if you need thread safety over HashMap you have to use the <strong>ConcurrentHashMap</strong></p><p><strong>8. TreeMap — </strong>If you need to maintain the key, value pairs in sorted order this is the data structure suits for that operation. Its guarantees that the given key value pairs arrange in sorted order according to the compareTo() method in Object type which is stored in TreeMap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b264bfd3c82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/complex-to-simple/selecting-proper-data-structures-for-the-realtime-problems-4b264bfd3c82">Selecting proper data structures for the realtime problems</a> was originally published in <a href="https://medium.com/complex-to-simple">Complex to Simple</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>