tag:blogger.com,1999:blog-6303631817541506602024-03-14T10:57:43.816+05:30Tech Trek: A Software Engineer's Guide to Code and BeyondAbdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.comBlogger183125tag:blogger.com,1999:blog-630363181754150660.post-82037222410161779262023-12-04T15:26:00.001+05:302023-12-04T15:26:05.040+05:30How TOPT Works: Generating OTPs Without Internet Connection<p><b>Introduction</b></p><p>Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an internet connection? This fascinating technology is made possible through Time-Based One-Time Passwords (TOTP). In this article, we will explore the mechanics of TOTP, its security features, and why it doesn't rely on the internet at the client-side for generating OTPs.</p><p>Understanding TOPT</p><p><b>1. TOPT in a Nutshell</b></p><p>TOPT, or Time-Based One-Time Password, is a security feature designed to enhance the authentication process. It generates OTPs that are only valid for a short period, typically 30 seconds. TOPT uses a secret key, often shared between the server and the user's device, to generate these OTPs. The central idea is to provide a second factor of authentication, beyond just a static password, to strengthen security.</p><p><b>2. The RSA Authenticator App</b></p><p>One popular example of a TOPT implementation is the RSA Authenticator app. This app is commonly used for two-factor authentication and generates OTPs even when the device is offline. So, how does it work?</p><p>The Inner Workings of TOPT</p><p><b>1. Secret Key and Initialization</b></p><p>When setting up TOPT on a device, the user and the authentication server share a secret key. This key is securely stored on both sides and is crucial for generating the OTPs. The server also maintains a counter that increments every 30 seconds.</p><p><b>2. Time-Step and Hashing</b></p><p>To generate an OTP, the device combines the secret key with a time-step value. This time-step value is derived from the current time, typically using Unix time (the number of seconds since January 1, 1970). The resulting value is then hashed, often using the HMAC-SHA1 algorithm.</p><p><b>3. Presentation of OTP</b></p><p>The resulting hash is typically a 160-bit value, which is then truncated to obtain a 6 to 8 digit OTP. The truncation involves taking a subset of bits from the hash. The number of digits and the specific bits selected are implementation-dependent.</p><p><b>4. Rolling Code</b></p><p>The server, which is aware of the current time and the shared secret key, can perform the same process to generate an OTP. If the generated OTP matches the one presented by the user, access is granted.</p><p><b>Advantages of TOPT</b></p><p><b>1. Offline OTP Generation</b></p><p>One of the major advantages of TOPT is that it does not require an internet connection to generate OTPs. The algorithm is based on a predefined time-step, allowing the device and the server to independently generate OTPs at the same time. This is particularly useful when an internet connection is unavailable, ensuring users can still access their accounts securely.</p><p><b>2. Enhanced Security</b></p><p>TOPT significantly enhances security because the OTPs are time-bound and change frequently. Even if an attacker intercepts an OTP, it will be invalid within seconds, reducing the risk of unauthorized access.</p><p><b>TOTP: A Special Case of TOPT</b></p><p><b>1. What is TOTP?</b></p><p>TOTP, or Time-Based One-Time Password, is a specific implementation of TOPT. It uses the current time as the input for generating OTPs. TOTP ensures that OTPs are synchronized between the device and the server, allowing for secure authentication even when offline.</p><p><b>2. TOTP in Action</b></p><p>In TOTP, the user and the server share a secret key. The device and the server independently generate OTPs based on the current time. The time-step is typically set to 30 seconds, ensuring that OTPs remain valid for a short period.</p><p><b>Conclusion</b></p><p>TOPT, and specifically TOTP, play a crucial role in modern authentication systems. They provide an additional layer of security by generating time-bound OTPs, without requiring an internet connection at the client-side. This capability ensures that even when internet access is unavailable, users can still access their accounts securely. The use of secret keys and time-based calculations makes TOPT a robust and widely adopted security feature, strengthening the overall security of online services.</p>Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-53905640865792024702023-12-04T15:21:00.000+05:302023-12-04T15:21:01.684+05:30Demystifying Service Mesh: How it Works and Why You Need It<p><b> Introduction:</b></p><p>In the ever-evolving landscape of modern application development and deployment, the concept of a "Service Mesh" has gained significant traction. As a tech blogger with over 12 years of experience, I'm here to provide a comprehensive update on this crucial topic. In this article, we'll delve into what a Service Mesh is, how it works, and why it has become an indispensable tool for managing complex microservices architectures.</p><p><b>What is a Service Mesh?</b></p><p>A Service Mesh is a dedicated infrastructure layer designed to facilitate communication between the microservices that make up an application. It acts as a transparent, language-agnostic network of interconnected components, providing essential functionalities such as service discovery, load balancing, security, and observability. The primary goal of a Service Mesh is to enhance the reliability, security, and manageability of microservices-based applications.</p><p><b>How Does it Work?</b></p><p>Now, let's dive deeper into how a Service Mesh actually works:</p><p></p><ol style="text-align: left;"><li><b>Sidecar Proxy:</b> At the heart of a Service Mesh, you'll find a sidecar proxy. Every microservice in the application is paired with its own proxy, effectively forming a "sidecar." These sidecar proxies are responsible for intercepting all inbound and outbound network traffic to and from the microservice they are attached to.</li><li><b>Service Discovery:</b> When a microservice needs to communicate with another service, it queries the Service Mesh for the location of the target service. The Service Mesh provides dynamic service discovery, ensuring that services can locate each other regardless of their changing IP addresses or locations.</li><li><b>Load Balancing:</b> Service Meshes implement sophisticated load balancing algorithms, distributing incoming requests evenly across instances of a service. This helps in optimizing resource utilization and ensuring high availability.</li><li><b>Security:</b> Security is a top priority in microservices architectures. Service Meshes offer robust security features like mutual TLS (mTLS) encryption, authentication, and authorization. With mTLS, all communication between microservices is encrypted and authenticated, significantly enhancing the overall security posture.</li><li><b>Traffic Management:</b> Service Meshes allow for fine-grained traffic control and routing. This means you can implement A/B testing, canary releases, and gradual rollouts with ease, all while monitoring the impact on your application's performance and stability.</li></ol><p>Observability and Monitoring: Service Meshes provide rich observability features, including metrics, logging, and tracing. This enables DevOps teams to gain deep insights into the behavior of their microservices and diagnose issues quickly.</p><p><b>Why You Need a Service Mesh:</b></p><p>Now, you might wonder why Service Meshes have gained such popularity. Here are a few key reasons:</p><p></p><ol style="text-align: left;"><li><b>Microservices Complexity: </b>As applications become more microservices-oriented, managing the complexity of service-to-service communication becomes increasingly challenging. Service Meshes provide a centralized solution for handling this complexity.</li><li><b>Resilience and Reliability:</b> With features like load balancing, circuit breaking, and automatic retries, Service Meshes improve the overall resilience of your application. They can handle failures gracefully, reducing downtime and improving user experience.</li><li><b>Security:</b> Service Meshes enhance the security of your microservices by implementing encryption and authentication. This is crucial, especially in multi-cloud or hybrid cloud environments.</li><li><b>Observability:</b> The ability to monitor and troubleshoot your microservices is essential for maintaining high availability and performance. Service Meshes offer a wealth of observability tools that simplify this process.</li></ol><p></p><p><b>Conclusion:</b></p><p>In the world of modern application development, a Service Mesh has become more of a necessity than a luxury. It offers a unified solution for managing the complexities of microservices architectures, ensuring reliability, security, and observability. </p>Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-71389915171441317652020-05-05T17:17:00.000+05:302020-05-05T17:17:10.509+05:30Creating first Jenkins pipeline: tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
<span style="font-size: 14pt;">Jenkins uses
a feature called Jenkins Pipeline which is a collection of jobs that brings the
software from version control into the hands of the end-users by using
automation tools. They represent multiple Jenkins jobs as one whole workflow in
the form of a pipeline.</span></div>
<div class="MsoNormal">
<span style="font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">In this blog,
I am going to share my knowledge on how can we write multiple Jenkins jobs as a pipeline and it uses two different syntaxes i.e. Declarative and Scripted pipeline and i</span><span style="font-size: 14pt;">n our examples, we're going to use the Scripted Pipeline which is following a more imperative programming model built with Groovy.</span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><b><br /></b></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><b>Prerequisite:</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
</div>
<ul style="text-align: left;">
<li><span style="font-size: 14.0pt; line-height: 107%;">Code
on bitbucket/<a href="https://github.com/abdulwaheed18/demo" target="_blank">GitHub </a><o:p></o:p></span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Jenkins
<a href="https://www.waheedtechblog.com/2020/04/jenkins-installation-on-ubuntu.html" target="_blank">Installation</a><o:p></o:p></span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Download
required <a href="https://www.waheedtechblog.com/2020/04/continuous-integration-with-jenkins-and.html" target="_blank">plugins </a>to run pipelines like Pipeline, SonarQube Scanner, Check Style, Junit,
Git Integration, Maven Integration.<o:p></o:p></span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Sonar
up and running.</span> </li>
</ul>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><b>Let’s start
creating pipeline will do below tasks:</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo2; text-indent: -18.0pt;">
</div>
<ul style="text-align: left;">
<li><span style="font-size: 14.0pt; line-height: 107%;">Clone</span> Project from Jenkins</li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Build
and run Junit test cases<o:p></o:p></span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Run
Sonar<o:p></o:p></span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Run
Checkstyle<o:p></o:p></span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Package
it as a jar file<o:p></o:p></span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-p38sOX_f554/XrFA0AyIDsI/AAAAAAAAKUs/ztWrJinPV-k4I6KX1Lcu9KuWhfjAkRoKQCLcBGAsYHQ/s1600/gitPipeline.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="197" data-original-width="660" height="190" src="https://1.bp.blogspot.com/-p38sOX_f554/XrFA0AyIDsI/AAAAAAAAKUs/ztWrJinPV-k4I6KX1Lcu9KuWhfjAkRoKQCLcBGAsYHQ/s640/gitPipeline.JPG" width="640" /></a></div>
<div>
<span style="font-size: 18.6667px;"><br /></span></div>
<!--[if !supportLists]--><br />
<b style="font-size: 18.6667px;"> </b><div>
<b style="font-size: 18.6667px;">Configuration Steps: </b></div>
<div>
<ul>
<li><span style="font-size: 18.6667px;">Let's create new Jenkins jobs. Goto <b>Jenkins </b>-> <b>New Item</b></span></li>
<li><span style="font-size: 14pt; line-height: 19.9733px;">Add name under <b>'Enter an item name</b>', Select pipeline as the type, and click <b>Ok </b>button.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-KXd8LKMiDYI/XrFCzodO0sI/AAAAAAAAKU4/-IVAdcy-sTcmSVTSj23Jm6834wK8zxRDQCLcBGAsYHQ/s1600/jenkinsName.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1003" data-original-width="1089" height="588" src="https://1.bp.blogspot.com/-KXd8LKMiDYI/XrFCzodO0sI/AAAAAAAAKU4/-IVAdcy-sTcmSVTSj23Jm6834wK8zxRDQCLcBGAsYHQ/s640/jenkinsName.JPG" width="640" /></a></div>
<div>
<span style="font-size: 18.6667px;"><br /></span></div>
<ul>
<li><span style="font-size: 18.6667px;">I am skipping the description and others tab here and directly jumping to the <b>Pipeline tab</b> as I already discussed it in my previous blog and we can run pipeline without worrying about it.</span></li>
<li><span style="font-size: 18.6667px;">Add below script and check <b>Use Groovy Sandbox </b>and <b>Save </b>it<b>.</b></span></li>
</ul>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<div>
<span style="color: #073763;"><i>node {</i></span></div>
<div>
<span style="white-space: pre;"><span style="color: #073763;"><i> </i></span></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>// clone the project from Github</i></span></div>
<div>
<span style="color: #073763;"><i> stage('Clone'){</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span> git 'https://github.com/abdulwaheed18/demo.git'</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>}</i></span></div>
<div>
<span style="white-space: pre;"><span style="color: #073763;"><i> </i></span></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>//Build the project</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>stage('Build'){</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span> sh "mvn clean install"</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>}</i></span></div>
<div>
<span style="white-space: pre;"><span style="color: #073763;"><i> </i></span></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>// Run Sonar for Code Coverage</i></span></div>
<div>
<span style="color: #073763;"><i> // Ignore this stage if sonar instance is not present</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>stage('Sonar') {</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>sh "mvn sonar:sonar"</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>}</i></span></div>
<div>
<span style="white-space: pre;"><span style="color: #073763;"><i> </i></span></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>// Run code check</i></span></div>
<div>
<span style="color: #073763;"><i><span style="white-space: pre;"> </span>stage("Checkstyle") {</i></span></div>
<div>
<span style="color: #073763;"><i> sh "mvn checkstyle:checkstyle"</i></span></div>
<div>
<span style="color: #073763;"><i> </i></span></div>
<div>
<span style="color: #073763;"><i> step([$class: 'CheckStylePublisher',</i></span></div>
<div>
<span style="color: #073763;"><i> canRunOnFailed: true,</i></span></div>
<div>
<span style="color: #073763;"><i> defaultEncoding: '',</i></span></div>
<div>
<span style="color: #073763;"><i> healthy: '100',</i></span></div>
<div>
<span style="color: #073763;"><i> pattern: '**/target/checkstyle-result.xml',</i></span></div>
<div>
<span style="color: #073763;"><i> unHealthy: '90',</i></span></div>
<div>
<span style="color: #073763;"><i> useStableBuildAsReference: true</i></span></div>
<div>
<span style="color: #073763;"><i> ])</i></span></div>
<div>
<span style="color: #073763;"><i> }</i></span></div>
<div>
<span style="white-space: pre;"><span style="color: #073763;"><i> </i></span></span></div>
<div>
<span style="color: #073763;"><i> //package the application</i></span></div>
<div>
<span style="color: #073763;"><i> stage('Package') {</i></span></div>
<div>
<span style="color: #073763;"><i> junit '**/target/surefire-reports/TEST-*.xml'</i></span></div>
<div>
<span style="color: #073763;"><i> archiveArtifacts 'target/*.jar'</i></span></div>
<div>
<span style="color: #073763;"><i> }</i></span></div>
<div>
<span style="color: #073763;"><i>}</i></span></div>
<div>
<br /></div>
<div>
<span style="color: #073763;"><i><br /></i></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-jtp6XAVLh1Q/XrFJ5oGUHvI/AAAAAAAAKVE/ivtfMS-naa4otB4DYpX0BaS92WBDrpMRwCLcBGAsYHQ/s1600/SavePipeline.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="938" data-original-width="978" height="612" src="https://1.bp.blogspot.com/-jtp6XAVLh1Q/XrFJ5oGUHvI/AAAAAAAAKVE/ivtfMS-naa4otB4DYpX0BaS92WBDrpMRwCLcBGAsYHQ/s640/SavePipeline.JPG" width="640" /></a></div>
<div>
<span style="color: #073763;"><i><br /></i></span></div>
</div>
<ul>
<li><span style="font-size: 18.6667px;">To configure Sonarqube URL, Goto<b> Jenkins -> Manage Jenkins -> Configure System </b>and set Server URL and save it. </span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-dCqKes7KeF8/XrFOUYsfI9I/AAAAAAAAKVo/lWohzCdkS8gXGIM44I4hqK5_WT39awy8ACLcBGAsYHQ/s1600/SonarServerURL.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="367" data-original-width="1559" height="150" src="https://1.bp.blogspot.com/-dCqKes7KeF8/XrFOUYsfI9I/AAAAAAAAKVo/lWohzCdkS8gXGIM44I4hqK5_WT39awy8ACLcBGAsYHQ/s640/SonarServerURL.JPG" width="640" /></a></div>
<ul>
<li><span style="font-size: 18.6667px;">You can see your newly created pipeline on the Jenkins dashboard</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-5fpOIh01arY/XrFKupi-UbI/AAAAAAAAKVM/WQJ_LPlbk9Ipk3bbEgKlJZYrDN6x5rJpgCLcBGAsYHQ/s1600/jenkinsPipeline.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="510" data-original-width="1600" height="202" src="https://1.bp.blogspot.com/-5fpOIh01arY/XrFKupi-UbI/AAAAAAAAKVM/WQJ_LPlbk9Ipk3bbEgKlJZYrDN6x5rJpgCLcBGAsYHQ/s640/jenkinsPipeline.JPG" width="640" /></a></div>
<div>
<span style="font-size: 18.6667px;"><br /></span></div>
<ul>
<li><span style="font-size: 18.6667px;">Click on Jenkins-pipeline-demo and then on the right side, click on Build now to build the project, to start the Jenkins pipelines.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-vDI8mr91Wq0/XrFLOD8plCI/AAAAAAAAKVU/H6XIRC4wrk8Khr_LJysQoVovBr0Tkle2QCLcBGAsYHQ/s1600/JenkinsBuildNow.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="416" data-original-width="911" height="292" src="https://1.bp.blogspot.com/-vDI8mr91Wq0/XrFLOD8plCI/AAAAAAAAKVU/H6XIRC4wrk8Khr_LJysQoVovBr0Tkle2QCLcBGAsYHQ/s640/JenkinsBuildNow.JPG" width="640" /></a></div>
<div>
<span style="font-size: 18.6667px;"><br /></span></div>
<ul>
<li><span style="font-size: 18.6667px;">Once your job is completed, you will see below screen </span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-n7kHHthPo3I/XrFLqJGJRCI/AAAAAAAAKVc/zGW_s5JI02kJzQW5eQxbrGn77KEwehoLQCLcBGAsYHQ/s1600/BuildSuccessFul.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="669" data-original-width="1600" height="266" src="https://1.bp.blogspot.com/-n7kHHthPo3I/XrFLqJGJRCI/AAAAAAAAKVc/zGW_s5JI02kJzQW5eQxbrGn77KEwehoLQCLcBGAsYHQ/s640/BuildSuccessFul.JPG" width="640" /></a></div>
<div>
<span style="font-size: 18.6667px;"><br /></span></div>
<ul>
<li><span style="font-size: 18.6667px;">As the final job was packing as the jar. you can see a blue downward arrow button clicking on which will download your application as a JAR file.</span></li>
<li><span style="font-size: 18.6667px;">you can check the logs by clicking on the blue circle button on the left side or you can hover over a stage cell and click the Logs button</span>.</li>
</ul>
<div>
<br /></div>
<ul>
<li><span style="font-size: 18.6667px;">To Check Sonar report, goto <b>Sonar Server URL</b> that you configured it. It will show you total code coverage, unused import, and bad code.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-KzOwnYTjf6k/XrFOuOOUdHI/AAAAAAAAKVw/ED0PG64hG9k4Moa1w4B4KXQIm3dzSNHMACLcBGAsYHQ/s1600/SonarDashboard.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="702" data-original-width="1600" height="280" src="https://1.bp.blogspot.com/-KzOwnYTjf6k/XrFOuOOUdHI/AAAAAAAAKVw/ED0PG64hG9k4Moa1w4B4KXQIm3dzSNHMACLcBGAsYHQ/s640/SonarDashboard.JPG" width="640" /></a></div>
<div>
<span style="font-size: 18.6667px;"><br /></span></div>
<ul>
<li><span style="font-size: 18.6667px;">We had also added the Checkstyle stage to the pipeline so to check the report. Click on the <b>Checkstyle Warning</b> present below<b> build now</b> link.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-71VExDich0A/XrFQIZtfhVI/AAAAAAAAKV8/jtc-FEtEFCkiS1yvQIK5VXmpfYF7jR5LQCLcBGAsYHQ/s1600/checkstyleWarning.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="833" data-original-width="1600" height="332" src="https://1.bp.blogspot.com/-71VExDich0A/XrFQIZtfhVI/AAAAAAAAKV8/jtc-FEtEFCkiS1yvQIK5VXmpfYF7jR5LQCLcBGAsYHQ/s640/checkstyleWarning.JPG" width="640" /></a></div>
<div>
<span style="font-size: 18.6667px;"><br /></span></div>
<ul>
<li><span style="font-size: 18.6667px;">Here we see 12 High Priority Warning browsable by clicking it. The <b>Details </b>tab gives you more insight into each class error. <div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-STWiYx1Bgvw/XrFQ9AW_NzI/AAAAAAAAKWE/sNmoEstmYz0uYXAj12T9-wT6TLTPlMB7ACLcBGAsYHQ/s1600/ClassWiseWarning.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="802" data-original-width="1600" height="320" src="https://1.bp.blogspot.com/-STWiYx1Bgvw/XrFQ9AW_NzI/AAAAAAAAKWE/sNmoEstmYz0uYXAj12T9-wT6TLTPlMB7ACLcBGAsYHQ/s640/ClassWiseWarning.JPG" width="640" /></a></div>
</span></li>
</ul>
<div>
<b style="font-size: 18.6667px;">Conclusion :</b></div>
<div>
<span style="font-size: 18.6667px;">We are able to set up a simple Jenkins pipeline to show code pull, build, to run sonar, and other code analysis tools, and as always the source code used in this project can be found over on <a href="https://github.com/abdulwaheed18/demo" target="_blank">Github</a>.</span></div>
<div>
<br /></div>
</div>
<div>
<b style="font-size: 18.6667px;"><br /></b></div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-62629958637144592612020-04-22T18:22:00.000+05:302020-04-22T18:22:28.202+05:30 Continuous Integration with Jenkins and Spring Boot App<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">Jenkins can
be used for multiple purposes like whenever any developer commits any code
changes to SCM, Jenkins triggers job which can Checkout the code, build it, run
JUnit test case, run tools like sonar or checkmarx and if everything works
properly then deploy it to some instance.</span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">In this
tutorial, I’ll share my knowledge on how can we automate our test process by
introducing CI like Jenkins. We will configure Jenkins such that it should trigger
it whenever any code commits by any developer to SCM, pull out the code from
GIT, run maven to build and test the code.</span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><b>Prerequisite:</b></span></div>
<div class="MsoNormal">
</div>
<ul style="text-align: left;">
<li><span style="font-size: 14pt; text-indent: -18pt;">Code upload on GIT (or use this </span><a href="https://github.com/abdulwaheed18/demo.git" style="font-size: 14pt; text-indent: -18pt;">link</a><span style="font-size: 14pt; text-indent: -18pt;">)</span></li>
<li><span style="font-size: 14pt; line-height: 107%; text-indent: -18pt;">Jenkins up and running. Refer <a href="https://www.waheedtechblog.com/2020/04/jenkins-installation-on-ubuntu.html">here</a>
for installation.</span></li>
</ul>
<div style="text-indent: -24px;">
<span style="font-size: 18.6667px;"> </span><span style="font-size: 14pt;">Once your
Jenkins is up and running then you will see below screen</span></div>
<div class="MsoListParagraph">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-q-TEHL8IQUI/XqAtx835A5I/AAAAAAAAKRI/ns3k7EfWn-kAhW3SHoXoAhxxBk02IfLjwCLcBGAsYHQ/s1600/JenkinsConsole.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="867" data-original-width="1600" height="346" src="https://1.bp.blogspot.com/-q-TEHL8IQUI/XqAtx835A5I/AAAAAAAAKRI/ns3k7EfWn-kAhW3SHoXoAhxxBk02IfLjwCLcBGAsYHQ/s640/JenkinsConsole.png" width="640" /></a></div>
<div style="text-indent: -24px;">
<span style="font-size: 18.6667px;"><b><br /></b></span></div>
<div style="text-indent: -24px;">
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><b> Configuration
Steps:</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> <b> </b></span></span><span style="font-size: 14.0pt; line-height: 107%;"><b>Install the required plugin.</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Make
sure all the required plugins like GIT, Maven are already present<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Goto
<b>Manage Jenkins -> manage plugins</b> -> <b>Installed tab</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-6fpfv5o1bYk/XqA6QQuRXRI/AAAAAAAAKR4/leM22hdWQJEaEB3OkDzV-QmROz4jCFfAgCLcBGAsYHQ/s1600/managePlugins.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="857" data-original-width="1600" height="342" src="https://1.bp.blogspot.com/-6fpfv5o1bYk/XqA6QQuRXRI/AAAAAAAAKR4/leM22hdWQJEaEB3OkDzV-QmROz4jCFfAgCLcBGAsYHQ/s640/managePlugins.png" width="640" /></a></div>
<br />
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">In
case, if you don’t find the required plugin then search under the Available tab. E.g.
to install the Maven Integration plugin.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Select
plugin and click on <b>Download now and install after restart.</b><o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-DYttjIoygMg/XqA69nJz3VI/AAAAAAAAKSg/aiq6gQevYbIYy6Y8vpXR5Quu2vjSCtgWACLcBGAsYHQ/s1600/MavenPlugin.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="763" data-original-width="1600" height="304" src="https://1.bp.blogspot.com/-DYttjIoygMg/XqA69nJz3VI/AAAAAAAAKSg/aiq6gQevYbIYy6Y8vpXR5Quu2vjSCtgWACLcBGAsYHQ/s640/MavenPlugin.png" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">It
will take some time to download and install the plugin as per your network bandwidth.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";"><br /><span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-HVyAwKIEi6g/XqA6O8gJDdI/AAAAAAAAKSI/aj-hvs8nafMldzz545uW6qgUNtWfjNbRQCEwYBhgL/s1600/InstallPlugins.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="679" data-original-width="1242" height="348" src="https://1.bp.blogspot.com/-HVyAwKIEi6g/XqA6O8gJDdI/AAAAAAAAKSI/aj-hvs8nafMldzz545uW6qgUNtWfjNbRQCEwYBhgL/s640/InstallPlugins.png" width="640" /></a></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<span style="font-family: Symbol; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;"><b>Set Java and Maven Path</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">by
default, Jenkins pick up the JAVA and Maven path running on Ubuntu instance but
if you have any specific java or maven directory then you can configure those
as well.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Goto
<b>Manage Jenkins -> Global tool configuration</b><o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-_9gea2uzzoI/XqA6N6nYNHI/AAAAAAAAKSI/A6WeWdjiFzYoHIrtwvyFSWFZTqk3yQpXQCEwYBhgL/s1600/GlobalToolConfig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="734" data-original-width="1600" height="292" src="https://1.bp.blogspot.com/-_9gea2uzzoI/XqA6N6nYNHI/AAAAAAAAKSI/A6WeWdjiFzYoHIrtwvyFSWFZTqk3yQpXQCEwYBhgL/s640/GlobalToolConfig.png" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> <b> </b></span></span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<span style="font-family: Symbol; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"><b> </b></span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;"><b>Generate SSH keygen for Jenkins user</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">If
you want to access a private Git repo, for example at GitHub, you need to
generate an ssh key-pair. Create a SSH key with the following command.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-60veZTbU4hY/XqA6RTYB5BI/AAAAAAAAKSY/lK_dWb4yya8MfNM3PlPePOpbGOyLXmpWACEwYBhgL/s1600/sshKeygen.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="552" data-original-width="782" height="450" src="https://1.bp.blogspot.com/-60veZTbU4hY/XqA6RTYB5BI/AAAAAAAAKSY/lK_dWb4yya8MfNM3PlPePOpbGOyLXmpWACEwYBhgL/s640/sshKeygen.png" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">The
public-key must be uploaded to the service you are using, e.g., GitHub.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> <b> </b></span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;"><b>Setting up Jenkins job</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">The
build of a project is handled via jobs in Jenkins. Click New Item. Afterward,
enter a name for the job and select the <b>Freestyle Project</b> and press OK.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-0f7vIjB5R4c/XqA6P6NvuPI/AAAAAAAAKSM/geIIFYLWa-4yq4iaowNT26EGLB4IpqyTgCEwYBhgL/s1600/jobs.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="902" data-original-width="1545" height="372" src="https://1.bp.blogspot.com/-0f7vIjB5R4c/XqA6P6NvuPI/AAAAAAAAKSM/geIIFYLWa-4yq4iaowNT26EGLB4IpqyTgCEwYBhgL/s640/jobs.png" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Add
description of the job<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Check <b>Discard old builds.</b> It will help you in cleaning the stale log. You can choose the log
rotation based on the number of builds or days. Always enable and choose this
option to make sure you are not running out of memory of Jenkins log.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-SlVUpWalgUk/XqA6QSSl3zI/AAAAAAAAKSQ/JA_maswd-vMSiig1NxjqtqS7J3d1grYDACEwYBhgL/s1600/logRotation.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="902" data-original-width="1529" height="376" src="https://1.bp.blogspot.com/-SlVUpWalgUk/XqA6QSSl3zI/AAAAAAAAKSQ/JA_maswd-vMSiig1NxjqtqS7J3d1grYDACEwYBhgL/s640/logRotation.png" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Under
Source code Management choose Git as we are going to checkout the code from GIT.SET
git url (<a href="https://github.com/abdulwaheed18/demo.git">https://github.com/abdulwaheed18/demo.git</a>)
and no need of credential as my repo is public and set branch as master.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-GT0EnDofdjQ/XqA6RBofWMI/AAAAAAAAKSc/hAQXC0KIEwcEl_SXkZCRFN-H4grbnvYZwCEwYBhgL/s1600/scm.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="740" data-original-width="1176" height="402" src="https://1.bp.blogspot.com/-GT0EnDofdjQ/XqA6RBofWMI/AAAAAAAAKSc/hAQXC0KIEwcEl_SXkZCRFN-H4grbnvYZwCEwYBhgL/s640/scm.JPG" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Under
<b>Build triggers, </b>choose <b>poll SCM</b> so that it should run this job whenever someone
commit the code to the master branch.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Schedule
value in * which defines the time.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-74EXapfmKWg/XqA6PFsK3lI/AAAAAAAAKSI/XJOygSdWYLQhlsrmTy6sgyGycO01q5YNwCEwYBhgL/s1600/cronSyntax.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="126" data-original-width="820" height="98" src="https://1.bp.blogspot.com/-74EXapfmKWg/XqA6PFsK3lI/AAAAAAAAKSI/XJOygSdWYLQhlsrmTy6sgyGycO01q5YNwCEwYBhgL/s640/cronSyntax.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-cUmhOWQM24M/XqA6PNT4U9I/AAAAAAAAKSE/BSogSu4u3HMB3Pfjj4xX4CZShf4roI3DwCEwYBhgL/s1600/buildTriggers.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="504" data-original-width="1180" height="272" src="https://1.bp.blogspot.com/-cUmhOWQM24M/XqA6PNT4U9I/AAAAAAAAKSE/BSogSu4u3HMB3Pfjj4xX4CZShf4roI3DwCEwYBhgL/s640/buildTriggers.png" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Which
means pull the SCM every day of every month and every minute of every hour.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Select<b>
top-level maven targets under Build</b> and set <b>Goals</b> as clean package.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-hWmj51dlZ78/XqA6OIP3LZI/AAAAAAAAKSc/g8tBYFAlCtEPVuwWNHSLhXL3ek7JRe4PQCEwYBhgL/s1600/BuildClean.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="328" data-original-width="1179" height="178" src="https://1.bp.blogspot.com/-hWmj51dlZ78/XqA6OIP3LZI/AAAAAAAAKSc/g8tBYFAlCtEPVuwWNHSLhXL3ek7JRe4PQCEwYBhgL/s640/BuildClean.png" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Apply
and save the configuration.</span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;"><b>Run the build</b><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Job
is created as jenkins-demo.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-iANyaChZb5s/XqA6PtYTPZI/AAAAAAAAKSQ/rmeV52XCYw449NYeC9R7pRpJTg71aw6xgCEwYBhgL/s1600/jenkinsdemo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="510" data-original-width="1600" height="204" src="https://1.bp.blogspot.com/-iANyaChZb5s/XqA6PtYTPZI/AAAAAAAAKSQ/rmeV52XCYw449NYeC9R7pRpJTg71aw6xgCEwYBhgL/s640/jenkinsdemo.png" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "Courier New"; font-size: 14.0pt; line-height: 107%; mso-fareast-font-family: "Courier New";">o<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;">
</span></span><!--[endif]--><span style="font-size: 14.0pt; line-height: 107%;">Click
on jenkins-demo and then <b>Build now</b> to run the newly created job.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-3KbNZ3_8YEY/XqA6ORNgmMI/AAAAAAAAKSU/LPU5M1-a0u4I8OM_IOsuX-pWi8cXp6fiACEwYBhgL/s1600/BuildNow.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="822" data-original-width="1498" height="350" src="https://1.bp.blogspot.com/-3KbNZ3_8YEY/XqA6ORNgmMI/AAAAAAAAKSU/LPU5M1-a0u4I8OM_IOsuX-pWi8cXp6fiACEwYBhgL/s640/BuildNow.JPG" width="640" /></a></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 72.0pt; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -18.0pt;">
<br /></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: Symbol; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: "Times New Roman"; font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span></span><span style="font-size: 14.0pt; line-height: 107%;">Congratulation! Your first job is created successfully and the blue circle under Build history means there was no issue during job execution and it ran successfully.</span></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
</div>
<div style="text-indent: -24px;">
<span style="font-size: 18.6667px;"><br /></span></div>
<div style="text-indent: -24px;">
<span style="font-size: 18.6667px;"><br /></span></div>
<br />
<br /></div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-53580884935886070322020-04-21T23:42:00.000+05:302020-04-21T23:42:08.070+05:30Jenkins Installation on Ubuntu<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b><span style="color: #222222; font-size: 14.0pt;">Jenkins</span></b><span style="color: #222222; font-size: 14.0pt;"> is an open source Continuous Integration server capable of
orchestrating a chain of actions that help to achieve the Continuous
Integration process (and not only) in an automated fashion.</span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #222222; font-size: 14.0pt;"><br /></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #222222; font-size: 14.0pt;">Jenkins is free and is entirely
written in Java. Jenkins is a widely used application around the world that has
around 300k installations and growing day by day.</span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #222222; font-size: 14.0pt;"><br /></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #222222; font-size: 14.0pt;">It is a server-based application and
requires a web server like Apache Tomcat. The reason Jenkins became so popular
is that of its monitoring of repeated tasks which arise during the development
of a project. For example, if your team is developing a project, Jenkins will
continuously test your project builds and show you the errors in early stages
of your development.</span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #222222; font-size: 14.0pt;"><br /></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #222222; font-size: 14.0pt;">By using Jenkins, software companies
can accelerate their software development process, as Jenkins can automate
build and test at a rapid rate. Jenkins supports the complete development
lifecycle of software from building, testing, documenting the software,
deploying and other stages of a software development lifecycle.</span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #222222; font-size: 14.0pt;"><br /></span></div>
<h4 style="background: white; line-height: normal; text-align: left;">
<span style="color: #222222; font-size: 14.0pt;"><b>Prerequisite</b></span></h4>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
</div>
<ul style="text-align: left;">
<li><span style="color: #222222;"><span style="font-size: 18.6667px;">Make sure you are logged in as a user with sudo privileges</span></span></li>
<li><span style="color: #222222;"><span style="font-size: 18.6667px;">Java 8 or later version up and running</span></span></li>
<ul>
<li><span style="color: #222222;"><span style="font-size: 18.6667px;"><i>sudo apt-get update</i></span></span></li>
<li><span style="color: #222222;"><span style="font-size: 18.6667px;"><i>sudo apt-get install default-jdk</i></span></span></li>
<li><span style="color: #222222;"><span style="font-size: 18.6667px;"><i>sudo java –version</i></span></span><a href="https://1.bp.blogspot.com/-RCzwkaouzbk/Xp8uQqPMviI/AAAAAAAAKPU/VqOE9dUkykk4Y7gQBHJQcv-ZfNqLZDilgCEwYBhgLKs0DAL1OcqwhnV2ftWp7IIiK_htgkCv1R6wzxXc_iPu-s--zn-xi3WSuR3bi1FzuzI3NIOSlc5MAE_l2GGZDXg2yGCZj61EE-i162dg5_nGux0FP7HICWPNV-u5Nr9Iww4Fp5XIDn2lTVty4adH9kH6wqtuk6vmWWsJbwL5T6knLKyTVXb-mcc9viOb1aFKTtcc3bQobXDXoqiI7Xas4vwV80qrj_a-pMYIhP9oQTqv_iIQg0LwiMYMrvjy9qqd4uTAbUebZBKaWIdE_MCbEC6j72aCK2T7Hv0fbVAqqfutjOOOvlLqqRD9i37vrn24ro3ormMEUGJBQphE-VO6pDVxra6jdin8TWjVjlhR7nUbOAJN1yj4t9x--a852vcYjWCK-mdm71EINJGa68qnleV_A7pPvzLwXRd9xe6bEDh_THy5rAs0X-1_JvnNQtdRlZpcFVeaKmCJ0ixRFLT82ynLbeGTRevegaEWSmIg8_zjwFWLkLzezR87mVdYGP94ba9YDsFxtv_FsFnkvU2PDVnpIGvYJ9oYNcXQtEGRzzBn3zDC0Bt6e3cA0TAs-QMnATUQTcKI5v5w8xKwryJ_9-ubXFWtEiax-xez_780j2LMwsuH89AU/s1600/javaVersion.png" style="font-size: 18.6667px; font-style: italic; margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="133" data-original-width="777" height="107" src="https://1.bp.blogspot.com/-RCzwkaouzbk/Xp8uQqPMviI/AAAAAAAAKPU/VqOE9dUkykk4Y7gQBHJQcv-ZfNqLZDilgCEwYBhgLKs0DAL1OcqwhnV2ftWp7IIiK_htgkCv1R6wzxXc_iPu-s--zn-xi3WSuR3bi1FzuzI3NIOSlc5MAE_l2GGZDXg2yGCZj61EE-i162dg5_nGux0FP7HICWPNV-u5Nr9Iww4Fp5XIDn2lTVty4adH9kH6wqtuk6vmWWsJbwL5T6knLKyTVXb-mcc9viOb1aFKTtcc3bQobXDXoqiI7Xas4vwV80qrj_a-pMYIhP9oQTqv_iIQg0LwiMYMrvjy9qqd4uTAbUebZBKaWIdE_MCbEC6j72aCK2T7Hv0fbVAqqfutjOOOvlLqqRD9i37vrn24ro3ormMEUGJBQphE-VO6pDVxra6jdin8TWjVjlhR7nUbOAJN1yj4t9x--a852vcYjWCK-mdm71EINJGa68qnleV_A7pPvzLwXRd9xe6bEDh_THy5rAs0X-1_JvnNQtdRlZpcFVeaKmCJ0ixRFLT82ynLbeGTRevegaEWSmIg8_zjwFWLkLzezR87mVdYGP94ba9YDsFxtv_FsFnkvU2PDVnpIGvYJ9oYNcXQtEGRzzBn3zDC0Bt6e3cA0TAs-QMnATUQTcKI5v5w8xKwryJ_9-ubXFWtEiax-xez_780j2LMwsuH89AU/s640/javaVersion.png" width="640" /></a></li>
</ul>
</ul>
<ul style="text-align: left;">
<li><span style="color: #222222;"><span style="font-size: 18.6667px;">Maven is up & running</span></span></li>
<ul>
<li><span style="color: #222222; font-size: 18.6667px;">Sudo apt-get install maven</span></li>
<li><span style="color: #222222; font-size: 18.6667px;">Sudo mvn --version</span></li>
</ul>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-fhf7Ir7ipy4/Xp8uQjSvf0I/AAAAAAAAKPY/hynhwNH3gE4syXVbaKowJQn7RohaXQMuACEwYBhgLKs0DAL1OcqymvPJOGalVJZcZbI9xW574AiVG2dAHagWpMOt-dlmQ6IJdNYPzN3efnkcbQwkwpfml2lZL5ONsCS7UpO0zmh2RZhM1EzgVeMR11Pkw5EfN7xCBrTYSKDpXwFFpH54hiQU8UHWRqMHunRPEnmALBcGoZOuvlrpB5ZOWggHQwcr0ap0NoWlHCqN-cggzvVDy8XRI3JOrjqKzqwdX0C2xm9hhewtyqe3tJcvz2BQrktgcd0kS1usafO70gjUhD-uF46MDmY-g6YfmhrygxaTmlbzl1duDGPMvfIJAZoK1e1r_ZXyZjk5NnQJkq50lsPOnWMAGGIpY70GJfAoqN9STnlDmv6Jq8ABeWVLFXV5dORB0PkkwgfN21NjCB3RzbUgHWmdgt-GfvN-SUcVpc4gHhOKpeWmlt4AzPFa1FCs9wlBAsi1KO6QeZfXd9AKwkLMswBbZbl5d9DVgIW7v-qF7ThLwDOzjze_BfppHbs4J6wuxgF_o5ZgseTd4iTTaKpDn2XLjMKempybPExzV35NEnxJiwVEDKyCsjM_KBDpDttSX9Ou1SVSaIQ6wnf-07Fk7rSf1-HSXBheSHsdtfbWij1dKXj0TkoiD3Ogw0uH89AU/s1600/mvnVersion.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="162" data-original-width="666" height="154" src="https://1.bp.blogspot.com/-fhf7Ir7ipy4/Xp8uQjSvf0I/AAAAAAAAKPY/hynhwNH3gE4syXVbaKowJQn7RohaXQMuACEwYBhgLKs0DAL1OcqymvPJOGalVJZcZbI9xW574AiVG2dAHagWpMOt-dlmQ6IJdNYPzN3efnkcbQwkwpfml2lZL5ONsCS7UpO0zmh2RZhM1EzgVeMR11Pkw5EfN7xCBrTYSKDpXwFFpH54hiQU8UHWRqMHunRPEnmALBcGoZOuvlrpB5ZOWggHQwcr0ap0NoWlHCqN-cggzvVDy8XRI3JOrjqKzqwdX0C2xm9hhewtyqe3tJcvz2BQrktgcd0kS1usafO70gjUhD-uF46MDmY-g6YfmhrygxaTmlbzl1duDGPMvfIJAZoK1e1r_ZXyZjk5NnQJkq50lsPOnWMAGGIpY70GJfAoqN9STnlDmv6Jq8ABeWVLFXV5dORB0PkkwgfN21NjCB3RzbUgHWmdgt-GfvN-SUcVpc4gHhOKpeWmlt4AzPFa1FCs9wlBAsi1KO6QeZfXd9AKwkLMswBbZbl5d9DVgIW7v-qF7ThLwDOzjze_BfppHbs4J6wuxgF_o5ZgseTd4iTTaKpDn2XLjMKempybPExzV35NEnxJiwVEDKyCsjM_KBDpDttSX9Ou1SVSaIQ6wnf-07Fk7rSf1-HSXBheSHsdtfbWij1dKXj0TkoiD3Ogw0uH89AU/s640/mvnVersion.JPG" width="640" /></a></div>
<div>
<span style="color: #222222;"><span style="font-size: 18.6667px;"><br /></span></span></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br />
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b><span style="color: #222222; font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Installation
steps:</span></b></div>
<div class="MsoNormal" style="background: white; line-height: normal; text-indent: 0px;">
</div>
<ul style="text-align: left;">
<li><span style="color: #222222; font-size: 14pt; text-indent: -18pt;">Add repository key to System</span></li>
<ul>
<li><span style="color: #0b5394;"><span style="font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span><span style="font-size: 14pt; text-indent: -18pt;"><i>wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo
apt-key add -</i></span></span></li>
</ul>
<li><span style="color: #222222; font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Append the Debian package repository address to the server’s
sources.list:</span></li>
<ul>
<li><i><span style="color: #0b5394;"><span style="font-size: 7pt; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal;"> </span><span style="font-size: 14pt; text-indent: -18pt;">sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ >
/etc/apt/sources.list.d/jenkins.list'</span></span></i></li>
</ul>
<li><span style="font-size: 14pt; text-indent: -18pt;"><i><span style="color: #0b5394;">sudo apt-get update</span></i></span></li>
<li><span style="font-size: 14pt; text-indent: -18pt;"><i><span style="color: #0b5394;">sudo apt-get install Jenkins</span></i></span></li>
<li><span style="color: #222222; font-size: 14pt; text-indent: -18pt;">Start the Jenkins</span></li>
<ul>
<li><span style="font-size: 14pt; text-indent: -18pt;"><i><span style="color: #0b5394;">sudo service jenkins start</span></i></span></li>
</ul>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-tJUMUSkeJrU/Xp8wheWmgVI/AAAAAAAAKPk/oeMnJL0DPWc4XmZmWbIZ7PCWbBinPIWawCLcBGAsYHQ/s1600/jenkinsInstall.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="332" data-original-width="1115" height="190" src="https://1.bp.blogspot.com/-tJUMUSkeJrU/Xp8wheWmgVI/AAAAAAAAKPk/oeMnJL0DPWc4XmZmWbIZ7PCWbBinPIWawCLcBGAsYHQ/s640/jenkinsInstall.png" width="640" /></a></div>
<div style="text-indent: -24px;">
<span style="color: #222222;"><span style="font-size: 18.6667px;"><i><br /></i></span></span></div>
<div style="text-indent: -24px;">
<span style="color: #222222;"><span style="font-size: 18.6667px;"><i><br /></i></span></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;">By default, Jenkins will start on port
8080, find the IP address of your ubuntu using ifconfig command and try hitting </span><a href="http://ip:8080/" style="font-size: 14pt;">http://ip:8080</a><span style="color: #222222; font-size: 14pt;"> from your browser to view the Jenkins dashboard.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-atq7Le-qBGI/Xp8xmrJTSBI/AAAAAAAAKPw/M1L9CB-wiK45DyohNSMsxfQvd_UZn-4ywCLcBGAsYHQ/s1600/ifconfig.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="382" data-original-width="998" height="244" src="https://1.bp.blogspot.com/-atq7Le-qBGI/Xp8xmrJTSBI/AAAAAAAAKPw/M1L9CB-wiK45DyohNSMsxfQvd_UZn-4ywCLcBGAsYHQ/s640/ifconfig.png" width="640" /></a></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: normal;">
<span style="color: #222222; font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"></span></div>
<br /></div>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-3xt3HP6e-jo/Xp8xswXHGkI/AAAAAAAAKP0/VajBSn7oXMMUHWqN5hxj9L4jw5mD13qGACEwYBhgLKs0DAL1OcqwMroMyH207GTZs1D7YuP-FoxzcBaydJ12920yOPhYAyJJ90jHuTv1eHJIwQ0pjBlRQf5XecLG30JDSJoHGhHMWT_-lT5I-zM5zI4L5OjBsIFJaQZlTrGgKKjZIHiAr0K1d8mO2z3bxwHXXwHFTiv3rq1hXn_xhaFcoCTmyAtcfRrbz_Hrm7HE0MJrzEG9SYPnp5CQnU9v12A4mvpk4Efj8BHpM6G6DjOu_y69Pqrv4W8aTH_Rm446b37EBs344xJ4VR6EFGAyGsmDeeXI4T45_5i-enNz9YcqJIGF9-FD32ZnXkVdSHNUgqUVs-bIImoFXUJWs2Bf-ycnw5Vf7BXAStiAVI1VMBBHa3t3adcs9XsnZojdoS7P9ukP9etX5YWQvEKmPIRuFNCVmvY5KkLcneQ6fssYMF_SxZKl85pCK7dZe9pBJfFN6Xp1eQ4MFgqqCs5nDVNaNbTpl20-5XS9Ifrx3r4wDyPBPsvUOLbd19-vjoqgUj3EzX6TI09v7I5yMgivGIwmLKvsOYxK6Mu5GSi1Mu9uwGUvwzf9pWNTq3F9_ze5QgZk-UNiqc_OjC820fh8teHbo7h79LWnTbY3YLvo6Bqkjyl8wtuj89AU/s1600/dashboard.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1004" data-original-width="1584" height="404" src="https://1.bp.blogspot.com/-3xt3HP6e-jo/Xp8xswXHGkI/AAAAAAAAKP0/VajBSn7oXMMUHWqN5hxj9L4jw5mD13qGACEwYBhgLKs0DAL1OcqwMroMyH207GTZs1D7YuP-FoxzcBaydJ12920yOPhYAyJJ90jHuTv1eHJIwQ0pjBlRQf5XecLG30JDSJoHGhHMWT_-lT5I-zM5zI4L5OjBsIFJaQZlTrGgKKjZIHiAr0K1d8mO2z3bxwHXXwHFTiv3rq1hXn_xhaFcoCTmyAtcfRrbz_Hrm7HE0MJrzEG9SYPnp5CQnU9v12A4mvpk4Efj8BHpM6G6DjOu_y69Pqrv4W8aTH_Rm446b37EBs344xJ4VR6EFGAyGsmDeeXI4T45_5i-enNz9YcqJIGF9-FD32ZnXkVdSHNUgqUVs-bIImoFXUJWs2Bf-ycnw5Vf7BXAStiAVI1VMBBHa3t3adcs9XsnZojdoS7P9ukP9etX5YWQvEKmPIRuFNCVmvY5KkLcneQ6fssYMF_SxZKl85pCK7dZe9pBJfFN6Xp1eQ4MFgqqCs5nDVNaNbTpl20-5XS9Ifrx3r4wDyPBPsvUOLbd19-vjoqgUj3EzX6TI09v7I5yMgivGIwmLKvsOYxK6Mu5GSi1Mu9uwGUvwzf9pWNTq3F9_ze5QgZk-UNiqc_OjC820fh8teHbo7h79LWnTbY3YLvo6Bqkjyl8wtuj89AU/s640/dashboard.png" width="640" /></a></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: normal;">
<span style="color: #222222; font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Above screen is asking for Jenkins initial
password which can be retrieved from initialAdminPassword file.</span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: normal;">
<span style="color: #222222; font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><br /></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: normal; text-align: center;">
<span style="font-size: 14pt;"><span style="color: #0b5394;"><i>sudo cat
/var/lib/jenkins/secrets/initialAdminPassword</i><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: normal; text-align: center;">
<span style="color: #222222; font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><i><br /></i></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-kwhVp7mHyNc/Xp8yinfI8wI/AAAAAAAAKQA/0gvZ6gk6gSYaVDPh5iwPVwMUzTbn8Mr7QCLcBGAsYHQ/s1600/password.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="56" data-original-width="843" height="42" src="https://1.bp.blogspot.com/-kwhVp7mHyNc/Xp8yinfI8wI/AAAAAAAAKQA/0gvZ6gk6gSYaVDPh5iwPVwMUzTbn8Mr7QCLcBGAsYHQ/s640/password.png" width="640" /></a></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: normal; text-align: left;">
<span style="color: #222222; font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><i><br /></i></span></div>
<div class="MsoNormal" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; line-height: normal; text-align: left;">
<br /></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">From the next screen, click on install
suggested plugin which will immediately begin the installation
process:<o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-XoZh1Ttic7s/Xp80UkPmc2I/AAAAAAAAKQQ/89rkzTtJG4gSjzjS0PTIhIqNPufrqrCXwCLcBGAsYHQ/s1600/JenkinsPlugin.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="759" data-original-width="1234" height="392" src="https://1.bp.blogspot.com/-XoZh1Ttic7s/Xp80UkPmc2I/AAAAAAAAKQQ/89rkzTtJG4gSjzjS0PTIhIqNPufrqrCXwCLcBGAsYHQ/s640/JenkinsPlugin.png" width="640" /></a></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-bm5O33R-Lbs/Xp80UQeyTzI/AAAAAAAAKQM/LUPL2x825QEmOKgI5cUW7BVlN7aLmFEUgCEwYBhgLKs0DAL1OcqyJOwFdVFs6_Ey42qSpq1XkQHHxnKWeD_EJm1Pty8zJEJsuqoGTtv3ZTavNm9J_I0aFBSSN0pcDxZS2uN3e30QuxtQsj_2QvE4Z5nRWp2Sdnor3ZMWrWm03bH8mkcZR4ywBhypLGjpo6cCYP5siunbHel8kFGeA8-pBLV-wESd2IzVOBAjjipw2ILX046QRYbjN2iXFkQ4VTFDH3vtGikgCzbqBjFi9STzcklNmB32I5eGAXU2WI2xo-xz6kTWh62-CbK1Ic9SRGeYIErq4udVj7x2hbzfAq7tsGZ3LFpoEH_BPUZiPTHibK_z5UnMIPnvMQzjrkaG-JCpsooP3oF6gZsYe0AMI-SAI6BocUQecmaUrEFNRymQqb3Lsrb2eiiY4x_wPZHcPQjprmAhZzeGHo5obcla4cTKVCFvM3wIumFGi2JEvDUciWokDWHq2O2w1tnraPTOnfrSd-SDUiB_gdzJMhYFi2CWHBUaZu5Wl2ZEBd8Yfu9FIAmYlOk-4Sog-so48oCzkRMiSuZ0WgnBwZoaaR4Duai2if708RL227FFqyfSCKrX1YmWcRCztaIwqYz1aN4vg_nmxHYpAY-rrYl6P1UJBqxUwuu389AU/s1600/JenkinsPlugin2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="858" data-original-width="1243" height="440" src="https://1.bp.blogspot.com/-bm5O33R-Lbs/Xp80UQeyTzI/AAAAAAAAKQM/LUPL2x825QEmOKgI5cUW7BVlN7aLmFEUgCEwYBhgLKs0DAL1OcqyJOwFdVFs6_Ey42qSpq1XkQHHxnKWeD_EJm1Pty8zJEJsuqoGTtv3ZTavNm9J_I0aFBSSN0pcDxZS2uN3e30QuxtQsj_2QvE4Z5nRWp2Sdnor3ZMWrWm03bH8mkcZR4ywBhypLGjpo6cCYP5siunbHel8kFGeA8-pBLV-wESd2IzVOBAjjipw2ILX046QRYbjN2iXFkQ4VTFDH3vtGikgCzbqBjFi9STzcklNmB32I5eGAXU2WI2xo-xz6kTWh62-CbK1Ic9SRGeYIErq4udVj7x2hbzfAq7tsGZ3LFpoEH_BPUZiPTHibK_z5UnMIPnvMQzjrkaG-JCpsooP3oF6gZsYe0AMI-SAI6BocUQecmaUrEFNRymQqb3Lsrb2eiiY4x_wPZHcPQjprmAhZzeGHo5obcla4cTKVCFvM3wIumFGi2JEvDUciWokDWHq2O2w1tnraPTOnfrSd-SDUiB_gdzJMhYFi2CWHBUaZu5Wl2ZEBd8Yfu9FIAmYlOk-4Sog-so48oCzkRMiSuZ0WgnBwZoaaR4Duai2if708RL227FFqyfSCKrX1YmWcRCztaIwqYz1aN4vg_nmxHYpAY-rrYl6P1UJBqxUwuu389AU/s640/JenkinsPlugin2.png" width="640" /></a></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<div class="MsoNormal">
<span style="color: #222222; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Once done with the installation, you will
be asked to set up the first administrative user. You can skip this step and continue
as admin using the initial password we used above or we can create the Jenkins user.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-UX-eOl0HbCw/Xp81eWdQhSI/AAAAAAAAKQg/ssZo_SubyMcoFnVtkvIr6k-HbmIxqGHegCLcBGAsYHQ/s1600/createUser.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="408" data-original-width="727" height="358" src="https://1.bp.blogspot.com/-UX-eOl0HbCw/Xp81eWdQhSI/AAAAAAAAKQg/ssZo_SubyMcoFnVtkvIr6k-HbmIxqGHegCLcBGAsYHQ/s640/createUser.JPG" width="640" /></a></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Update all the fields and click on
save and continue button. The next</span><span style="color: #222222; font-size: 14pt;"> screen will be </span><b style="color: #222222; font-size: 14pt;">instance Configuration</b><span style="color: #222222; font-size: 14pt;">
page that will ask to confirm the preferred URL for your Jenkins instance. Click
</span><b style="color: #222222; font-size: 14pt;">Save and Finish.</b></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-kvhZjLNToiM/Xp82j9C9rfI/AAAAAAAAKQs/WIr-3a9qu28TrNeYzoCFe7gMjobJnLcLwCLcBGAsYHQ/s1600/configurationScreen.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="837" data-original-width="1234" height="434" src="https://1.bp.blogspot.com/-kvhZjLNToiM/Xp82j9C9rfI/AAAAAAAAKQs/WIr-3a9qu28TrNeYzoCFe7gMjobJnLcLwCLcBGAsYHQ/s640/configurationScreen.png" width="640" /></a></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-NRN9vrb1QoM/Xp82j3hFmpI/AAAAAAAAKQw/hCVIPaC6H54mDtEonXCTfMHi2MJBajGhACEwYBhgLKs0DAL1OcqzyIe0c6Kt1Rog9BXcmPx_IF57_XWhRr22kzY8_RxDpdcg2gN9W_QJuboJZVkU0Vx0hpbT4BVCX7ecAErQtdIC98glgQ9VyJXra1UVti96WmoB1hk0nSh3kB3bDOkiwMT45EJYI5dby3lgXEBZnHV_ghBmMaNuE4J9_AxQNkqd6f8VvK_YLDTJqlg5wvIuKeGupMtk8W6jGGzPZJplM-lhWfhdOaZGFKEFpX5XdQFJKJ225YqDNLuyRs7HO9-LeDxfCFQAUq691NoONpTudFEOfybwRDujvYmPyj6h_4_sD5YXbknB9UaoA-LecahqtGB2Gxof8s0T8lJ3vJUBxZafKc_IDF6p_m_8owcL7QwTKNogK71l_Fg4ZnHx85TNBcRnNjiOLEOyOtx8sbTNO-ULoMwktmB75NM0f250Jt2sadm5bg0RbPhL1OqtzHEfQ4Gnc17QmpTTok7wZTIZezDh2kIl7M_eAfeWzcwA65QCnmBoMTl-HMnu-qrMXgoiwPedKYVRcmzJllRAK32-FNV-_VvTDs_qSGHrh0rhAOoFA3EMO1G-6bnl-ApPdYeI5_smzGp2DPavNY6cBoeZmZLyM601QNyhC_lYwkvL89AU/s1600/jenkinsReadyScreen.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="850" data-original-width="1241" height="438" src="https://1.bp.blogspot.com/-NRN9vrb1QoM/Xp82j3hFmpI/AAAAAAAAKQw/hCVIPaC6H54mDtEonXCTfMHi2MJBajGhACEwYBhgLKs0DAL1OcqzyIe0c6Kt1Rog9BXcmPx_IF57_XWhRr22kzY8_RxDpdcg2gN9W_QJuboJZVkU0Vx0hpbT4BVCX7ecAErQtdIC98glgQ9VyJXra1UVti96WmoB1hk0nSh3kB3bDOkiwMT45EJYI5dby3lgXEBZnHV_ghBmMaNuE4J9_AxQNkqd6f8VvK_YLDTJqlg5wvIuKeGupMtk8W6jGGzPZJplM-lhWfhdOaZGFKEFpX5XdQFJKJ225YqDNLuyRs7HO9-LeDxfCFQAUq691NoONpTudFEOfybwRDujvYmPyj6h_4_sD5YXbknB9UaoA-LecahqtGB2Gxof8s0T8lJ3vJUBxZafKc_IDF6p_m_8owcL7QwTKNogK71l_Fg4ZnHx85TNBcRnNjiOLEOyOtx8sbTNO-ULoMwktmB75NM0f250Jt2sadm5bg0RbPhL1OqtzHEfQ4Gnc17QmpTTok7wZTIZezDh2kIl7M_eAfeWzcwA65QCnmBoMTl-HMnu-qrMXgoiwPedKYVRcmzJllRAK32-FNV-_VvTDs_qSGHrh0rhAOoFA3EMO1G-6bnl-ApPdYeI5_smzGp2DPavNY6cBoeZmZLyM601QNyhC_lYwkvL89AU/s640/jenkinsReadyScreen.png" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="color: #222222; font-size: 14pt; text-align: left;">Click </span><b style="color: #222222; font-size: 14pt; text-align: left;">Start using Jenkins</b><span style="color: #222222; font-size: 14pt; text-align: left;"> to visit the main Jenkins dashboard:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-O58ZhR8voqg/Xp82kNjWkSI/AAAAAAAAKQ0/IJfD_5mcjgEBKMJLigzUA2fOdm0NejwwACLcBGAsYHQ/s1600/JenkinsConsole.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="867" data-original-width="1600" height="346" src="https://1.bp.blogspot.com/-O58ZhR8voqg/Xp82kNjWkSI/AAAAAAAAKQ0/IJfD_5mcjgEBKMJLigzUA2fOdm0NejwwACLcBGAsYHQ/s640/JenkinsConsole.png" width="640" /></a></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #222222; font-size: 14pt;">Congratulation! your Jenkins is up and running on your Ubuntu instance.</span></div>
<div class="MsoNormal">
<br /></div>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-13242916600678755162020-01-08T23:45:00.001+05:302020-01-09T01:25:32.520+05:30Setting up Lombok with SpringToolSuite and Intellij Idea<div dir="ltr" style="text-align: left;" trbidi="on">
<h4 style="text-align: left;">
<span style="font-weight: normal;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-size: large;">Lombok is a java library that you can plug into your editor which will automatically generate code in .class file instead of in source file.<br /> </span><span style="font-size: large;">E.g: </span><span style="font-size: large;"> getters, setters toString, equals, hashcode, builder, loggers, and many others.</span></span></span></h4>
<h4 style="text-align: left;">
<span style="font-weight: normal;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-size: large;">In this tutorial, I’ll talk about configuring it in two of the most popular IDEs- IntelliJ IDEA and Spring Tool Suite.</span></span></span></h4>
<div>
<span style="color: #20124d; font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Check my Github repo to learn project <a href="https://github.com/abdulwaheed18/project-lombok" target="_blank">Lombok </a>using java source code.</b></span></div>
<h4 style="text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-size: large;">Note:<span style="font-weight: normal;"> Step for installing the plugin for Eclipse and Spring tool Suite (STS) are the same.</span></span></span></h4>
<h4 style="text-align: left;">
</h4>
<h3 style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Steps to configure Lombok in STS</span></span></h3>
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: "trebuchet ms" , sans-serif;">
</span>
</span><br />
<ul style="text-align: left;"><span style="font-family: "arial" , "helvetica" , sans-serif;">
<li><span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-size: large; font-weight: normal;">Download <a href="https://projectlombok.org/download" target="_blank">Lombok </a>jar from the Lombok site.</span></span></li>
<li><span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-size: large; font-weight: normal;">Double click on Lombok jar which will open below Installer wizard, Choose IDEs in which you want to install. If your not IDE is not listed then you can browse using Specify location tab.</span></span></li>
</span></ul>
<span style="font-family: "arial" , "helvetica" , sans-serif;">
</span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://1.bp.blogspot.com/-k_jPlPMTi3Q/XhYbmYuxFnI/AAAAAAAAKCE/riKsWnWiu8cbACqSlcCH0p3qThW4d2ZHACEwYBhgL/s1600/Screen1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="594" data-original-width="955" height="398" src="https://1.bp.blogspot.com/-k_jPlPMTi3Q/XhYbmYuxFnI/AAAAAAAAKCE/riKsWnWiu8cbACqSlcCH0p3qThW4d2ZHACEwYBhgL/s640/Screen1.png" width="640" /></a></span></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;">
</span>
<ul style="text-align: left;"><span style="font-family: "arial" , "helvetica" , sans-serif;">
<li><span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-size: large; font-weight: normal;">Once selected, click on Install/update button and you are done.</span></span></li>
</span></ul>
<span style="font-family: "arial" , "helvetica" , sans-serif;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-CFK8cHdk9KM/XhYbmVyV6UI/AAAAAAAAKCA/47HegLKOF4o_9xaen3ifm5rhdHblmVjCgCEwYBhgL/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="400" data-original-width="678" height="377" src="https://1.bp.blogspot.com/-CFK8cHdk9KM/XhYbmVyV6UI/AAAAAAAAKCA/47HegLKOF4o_9xaen3ifm5rhdHblmVjCgCEwYBhgL/s640/2.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<span style="font-size: large; font-weight: normal;"><br /></span></span><br />
<h3 style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Steps to configure Lombok in IntelliJ IDEA</span></span></h3>
<ul style="text-align: left;"><span style="font-family: "arial" , "helvetica" , sans-serif;">
<li><span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-size: large; font-weight: normal;">Open IntelliJ Idea and click on File-> Settings…</span></span></li>
<li><span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-size: large; font-weight: normal;">Click on Plugin option and then search for Lombok</span></span></li>
<li><span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-size: large; font-weight: normal;">Click on the Install button on the plugin page</span></span></li>
</span></ul>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: "trebuchet ms" , sans-serif;">
</span>
</span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://1.bp.blogspot.com/-Slyn1fwfsF4/XhYbmBmydcI/AAAAAAAAKB8/1-ykEhmA1DYJr5arsLYFLx3zOJQ_frAfQCEwYBhgL/s1600/IntelliJ.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="812" data-original-width="1328" height="391" src="https://1.bp.blogspot.com/-Slyn1fwfsF4/XhYbmBmydcI/AAAAAAAAKB8/1-ykEhmA1DYJr5arsLYFLx3zOJQ_frAfQCEwYBhgL/s640/IntelliJ.png" width="640" /></a></span></div>
<span style="font-family: "arial" , "helvetica" , sans-serif;">
</span>
<br />
<div>
<span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></span></div>
<span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif;">
</span></span>
<ul style="text-align: left;"><span style="font-family: "trebuchet ms" , sans-serif;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large; font-weight: normal;">Once done with the installation, click on the restart IDE button.</span></li>
</span></ul>
<span style="font-family: "trebuchet ms" , sans-serif;">
</span></div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-24976034457819044422019-11-08T00:55:00.001+05:302019-11-08T01:13:48.675+05:30Streaming Spring boot logs to ELK stack<div dir="ltr" style="text-align: left;" trbidi="on">
<div bis_size="{"x":16,"y":7,"w":653,"h":112,"abs_x":293,"abs_y":160}">
<span bis_size="{"x":16,"y":7,"w":641,"h":112,"abs_x":293,"abs_y":160}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">In my previous <a bis_size="{"x":181,"y":7,"w":45,"h":28,"abs_x":458,"abs_y":160}" href="http://www.waheedtechblog.com/2019/11/elk-elasticsearch-logstash-and-kibana.html" target="_blank">blog</a>, we have done ELK installation on windows 10 and we have even tried to push messages from input console to Elastic Search and finally viewed on Kibana Server.</span></div>
<div bis_size="{"x":16,"y":119,"w":653,"h":56,"abs_x":293,"abs_y":272}">
<span bis_size="{"x":16,"y":119,"w":0,"h":28,"abs_x":293,"abs_y":272}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":119,"w":0,"h":28,"abs_x":293,"abs_y":272}" /></span>
<span bis_size="{"x":16,"y":147,"w":549,"h":28,"abs_x":293,"abs_y":300}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">I will write a separate blog on why do we need ELK?</span></div>
<div bis_size="{"x":16,"y":175,"w":653,"h":168,"abs_x":293,"abs_y":328}">
<span bis_size="{"x":16,"y":175,"w":0,"h":28,"abs_x":293,"abs_y":328}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":175,"w":0,"h":28,"abs_x":293,"abs_y":328}" /></span>
<span bis_size="{"x":16,"y":203,"w":647,"h":140,"abs_x":293,"abs_y":356}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">In this blog, I’ll show you how can we push spring boot application log directly to Elastic search using Logstash which we can analyze on Kibana and If you don’t know how to install ELK on windows 10 then you can refer my previous <a bis_size="{"x":16,"y":315,"w":51,"h":28,"abs_x":293,"abs_y":468}" href="http://www.waheedtechblog.com/2019/11/elk-elasticsearch-logstash-and-kibana.html" target="_blank">blog </a>and start Elastic Search and Kibana server.</span></div>
<div bis_size="{"x":16,"y":343,"w":653,"h":28,"abs_x":293,"abs_y":496}">
<span bis_size="{"x":16,"y":343,"w":0,"h":28,"abs_x":293,"abs_y":496}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":343,"w":0,"h":28,"abs_x":293,"abs_y":496}" /></span>
</div>
<h3 bis_size="{"x":16,"y":390,"w":653,"h":28,"abs_x":293,"abs_y":543}" style="text-align: left;">
<span bis_size="{"x":16,"y":390,"w":153,"h":28,"abs_x":293,"abs_y":543}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Prerequisite</span></h3>
<div bis_size="{"x":16,"y":437,"w":653,"h":18,"abs_x":293,"abs_y":590}">
<br bis_size="{"x":16,"y":437,"w":0,"h":17,"abs_x":293,"abs_y":590}" /></div>
<ul bis_size="{"x":16,"y":471,"w":653,"h":56,"abs_x":293,"abs_y":624}" style="text-align: left;">
<li bis_size="{"x":56,"y":471,"w":613,"h":28,"abs_x":333,"abs_y":624}"><span bis_size="{"x":56,"y":471,"w":551,"h":28,"abs_x":333,"abs_y":624}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Elastic Search and Kibana running on your machine</span></li>
<li bis_size="{"x":56,"y":499,"w":613,"h":28,"abs_x":333,"abs_y":652}"><span bis_size="{"x":56,"y":499,"w":456,"h":28,"abs_x":333,"abs_y":652}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Basic knowledge of Spring boot application</span></li>
</ul>
<div bis_size="{"x":16,"y":543,"w":653,"h":18,"abs_x":293,"abs_y":696}">
<br bis_size="{"x":16,"y":543,"w":0,"h":17,"abs_x":293,"abs_y":696}" /></div>
<div bis_size="{"x":16,"y":562,"w":653,"h":112,"abs_x":293,"abs_y":715}">
<span bis_size="{"x":16,"y":562,"w":0,"h":28,"abs_x":293,"abs_y":715}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":562,"w":0,"h":28,"abs_x":293,"abs_y":715}" /></span>
<span bis_size="{"x":16,"y":590,"w":639,"h":84,"abs_x":293,"abs_y":743}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">If you don’t want to start your application from scratch then you can download one spring boot application from my <a bis_size="{"x":16,"y":646,"w":85,"h":28,"abs_x":293,"abs_y":799}" href="https://github.com/abdulwaheed18/spring-boot-tutorial/tree/master/spring-logger" target="_blank">GitHub </a>repository as well.</span></div>
<div bis_size="{"x":16,"y":674,"w":653,"h":112,"abs_x":293,"abs_y":827}">
<span bis_size="{"x":16,"y":674,"w":0,"h":28,"abs_x":293,"abs_y":827}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":674,"w":0,"h":28,"abs_x":293,"abs_y":827}" /></span>
<span bis_size="{"x":16,"y":702,"w":641,"h":84,"abs_x":293,"abs_y":855}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">I am assuming that the Elastic Search and Kibana server are running on your machine and you have a fair idea of how to start the Logstash server and what is Logstash conf file.</span></div>
<div bis_size="{"x":16,"y":786,"w":653,"h":224,"abs_x":293,"abs_y":939}">
<span bis_size="{"x":16,"y":786,"w":0,"h":28,"abs_x":293,"abs_y":939}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":786,"w":0,"h":28,"abs_x":293,"abs_y":939}" /></span>
<span bis_size="{"x":16,"y":814,"w":653,"h":84,"abs_x":293,"abs_y":967}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">So, to push spring boot logs continuously to Elastic Server, We have to open one TCP port in Logstash server and for that we have to create one </span><span bis_size="{"x":16,"y":870,"w":634,"h":140,"abs_x":293,"abs_y":1023}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Logstash config file (say elklogstash.conf) under ${LOGSTASH_HOME}/conf directory mentioning on which port TCP port should be listening under input filter and where to push the data once we received under Output filter.</span></div>
<div bis_size="{"x":16,"y":1010,"w":653,"h":56,"abs_x":293,"abs_y":1163}">
<span bis_size="{"x":16,"y":1010,"w":0,"h":28,"abs_x":293,"abs_y":1163}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":1010,"w":0,"h":28,"abs_x":293,"abs_y":1163}" /></span>
<span bis_size="{"x":16,"y":1038,"w":612,"h":28,"abs_x":293,"abs_y":1191}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">For simplicity, I am skipping the filter tag as it is optional.</span></div>
<div bis_size="{"x":16,"y":1066,"w":653,"h":28,"abs_x":293,"abs_y":1219}">
<span bis_size="{"x":16,"y":1066,"w":0,"h":28,"abs_x":293,"abs_y":1219}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":1066,"w":0,"h":28,"abs_x":293,"abs_y":1219}" /></span>
</div>
<h3 bis_size="{"x":16,"y":1112,"w":653,"h":28,"abs_x":293,"abs_y":1265}" style="text-align: left;">
<span bis_size="{"x":16,"y":1112,"w":201,"h":28,"abs_x":293,"abs_y":1265}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">elklogstash.conf</span></h3>
<div bis_size="{"x":16,"y":1159,"w":653,"h":0,"abs_x":293,"abs_y":1312}" class="separator" style="clear: both; text-align: center;">
</div>
<div bis_size="{"x":16,"y":1159,"w":653,"h":0,"abs_x":293,"abs_y":1312}" class="separator" style="clear: both; text-align: center;">
</div>
<div bis_size="{"x":16,"y":1159,"w":653,"h":18,"abs_x":293,"abs_y":1312}">
<br bis_size="{"x":16,"y":1159,"w":0,"h":17,"abs_x":293,"abs_y":1312}" /></div>
<div bis_size="{"x":16,"y":1178,"w":653,"h":498,"abs_x":293,"abs_y":1331}" class="separator" style="clear: both; text-align: center;">
<a bis_size="{"x":32,"y":1661,"w":640,"h":17,"abs_x":309,"abs_y":1814}" href="https://1.bp.blogspot.com/-TGFlOGelJ9s/XcRlHWF29HI/AAAAAAAAJ-k/louNN2-C6ww61jpvyZRak6B4ebEgbKWtgCEwYBhgL/s1600/elklogstash.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img bis_size="{"x":32,"y":1178,"w":640,"h":498,"abs_x":309,"abs_y":1331}" border="0" data-original-height="395" data-original-width="505" height="498" src="https://1.bp.blogspot.com/-TGFlOGelJ9s/XcRlHWF29HI/AAAAAAAAJ-k/louNN2-C6ww61jpvyZRak6B4ebEgbKWtgCEwYBhgL/s640/elklogstash.JPG" width="640" /></a></div>
<div bis_size="{"x":16,"y":1676,"w":653,"h":28,"abs_x":293,"abs_y":1829}">
<div bis_size="{"x":16,"y":1676,"w":653,"h":28,"abs_x":293,"abs_y":1829}">
<span bis_size="{"x":16,"y":1676,"w":0,"h":28,"abs_x":293,"abs_y":1829}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":1676,"w":0,"h":28,"abs_x":293,"abs_y":1829}" /></span></div>
</div>
<div bis_size="{"x":16,"y":1704,"w":653,"h":28,"abs_x":293,"abs_y":1857}">
<div bis_size="{"x":16,"y":1704,"w":653,"h":28,"abs_x":293,"abs_y":1857}">
<span bis_size="{"x":16,"y":1704,"w":0,"h":28,"abs_x":293,"abs_y":1857}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":1704,"w":0,"h":28,"abs_x":293,"abs_y":1857}" /></span></div>
</div>
<div bis_size="{"x":16,"y":1732,"w":653,"h":56,"abs_x":293,"abs_y":1885}">
<span bis_size="{"x":16,"y":1732,"w":635,"h":56,"abs_x":293,"abs_y":1885}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Now start the Logstash server bypassing newly created conf file.</span></div>
<div bis_size="{"x":16,"y":1788,"w":653,"h":28,"abs_x":293,"abs_y":1941}" style="text-align: center;">
<div bis_size="{"x":16,"y":1788,"w":653,"h":28,"abs_x":293,"abs_y":1941}">
<span bis_size="{"x":117,"y":1788,"w":449,"h":28,"abs_x":394,"abs_y":1941}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"> <i bis_size="{"x":134,"y":1788,"w":432,"h":28,"abs_x":411,"abs_y":1941}">bin\logstash -f .\config\elklogstash.conf</i></span></div>
</div>
<div bis_size="{"x":16,"y":1816,"w":653,"h":28,"abs_x":293,"abs_y":1969}" style="text-align: center;">
<div bis_size="{"x":16,"y":1816,"w":653,"h":28,"abs_x":293,"abs_y":1969}">
<span bis_size="{"x":342,"y":1816,"w":0,"h":28,"abs_x":619,"abs_y":1969}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><i bis_size="{"x":342,"y":1816,"w":0,"h":28,"abs_x":619,"abs_y":1969}"><br bis_size="{"x":342,"y":1816,"w":0,"h":28,"abs_x":619,"abs_y":1969}" /></i></span></div>
</div>
<div bis_size="{"x":16,"y":1844,"w":653,"h":242,"abs_x":293,"abs_y":1997}" class="separator" style="clear: both; text-align: center;">
<a bis_size="{"x":32,"y":2071,"w":640,"h":17,"abs_x":309,"abs_y":2224}" href="https://1.bp.blogspot.com/-qHTABDTVBEA/XcRl3EKryBI/AAAAAAAAJ-o/rNsE2OHfW6gPHq9oCzGClaUWh2EbJFvhgCLcBGAsYHQ/s1600/logstashserver.JPG" style="margin-left: 1em; margin-right: 1em;"><img bis_size="{"x":32,"y":1844,"w":640,"h":242,"abs_x":309,"abs_y":1997}" border="0" data-original-height="519" data-original-width="1372" height="242" src="https://1.bp.blogspot.com/-qHTABDTVBEA/XcRl3EKryBI/AAAAAAAAJ-o/rNsE2OHfW6gPHq9oCzGClaUWh2EbJFvhgCLcBGAsYHQ/s640/logstashserver.JPG" width="640" /></a></div>
<div bis_size="{"x":16,"y":2086,"w":653,"h":18,"abs_x":293,"abs_y":2239}">
<br bis_size="{"x":16,"y":2086,"w":0,"h":17,"abs_x":293,"abs_y":2239}" /></div>
<div bis_size="{"x":16,"y":2104,"w":653,"h":18,"abs_x":293,"abs_y":2257}">
<br bis_size="{"x":16,"y":2104,"w":0,"h":17,"abs_x":293,"abs_y":2257}" /></div>
<div bis_size="{"x":16,"y":2122,"w":653,"h":140,"abs_x":293,"abs_y":2275}">
<span bis_size="{"x":16,"y":2122,"w":653,"h":140,"abs_x":293,"abs_y":2275}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Cool! Now Logstash server is also up and running and if you observe the log, you will realize that it is also listening on port 4560 as mentioned in the conf file. Configure the newly created index (elkbootlogs) on Kibana as we have done during the ELK setup.</span></div>
<div bis_size="{"x":16,"y":2262,"w":653,"h":84,"abs_x":293,"abs_y":2415}">
<span bis_size="{"x":16,"y":2262,"w":0,"h":28,"abs_x":293,"abs_y":2415}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":2262,"w":0,"h":28,"abs_x":293,"abs_y":2415}" /></span>
<span bis_size="{"x":16,"y":2290,"w":644,"h":56,"abs_x":293,"abs_y":2443}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Now let's do some changes to spring boot application so that it can push all the logs to 4056 TCP port.</span></div>
<div bis_size="{"x":16,"y":2346,"w":653,"h":84,"abs_x":293,"abs_y":2499}">
<span bis_size="{"x":16,"y":2346,"w":0,"h":28,"abs_x":293,"abs_y":2499}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":2346,"w":0,"h":28,"abs_x":293,"abs_y":2499}" /></span>
<span bis_size="{"x":16,"y":2374,"w":621,"h":56,"abs_x":293,"abs_y":2527}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">For this tutorial, I am using <a bis_size="{"x":313,"y":2374,"w":142,"h":28,"abs_x":590,"abs_y":2527}" href="https://github.com/abdulwaheed18/spring-boot-tutorial/tree/master/spring-logger" target="_blank">spring-logger</a> project from my Github repository.</span></div>
<div bis_size="{"x":16,"y":2430,"w":653,"h":84,"abs_x":293,"abs_y":2583}">
<span bis_size="{"x":16,"y":2430,"w":0,"h":28,"abs_x":293,"abs_y":2583}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":2430,"w":0,"h":28,"abs_x":293,"abs_y":2583}" /></span>
<span bis_size="{"x":16,"y":2458,"w":576,"h":56,"abs_x":293,"abs_y":2611}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Add below dependency to the <b bis_size="{"x":333,"y":2458,"w":116,"h":28,"abs_x":610,"abs_y":2611}">pom.xml </b>file. We need Logstash encoder to encode messages.</span></div>
<div bis_size="{"x":16,"y":2514,"w":653,"h":28,"abs_x":293,"abs_y":2667}">
<span bis_size="{"x":16,"y":2514,"w":0,"h":28,"abs_x":293,"abs_y":2667}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":2514,"w":0,"h":28,"abs_x":293,"abs_y":2667}" /></span>
</div>
<div bis_size="{"x":16,"y":2542,"w":653,"h":28,"abs_x":293,"abs_y":2695}" style="text-align: justify;">
<div bis_size="{"x":16,"y":2542,"w":653,"h":28,"abs_x":293,"abs_y":2695}">
<span bis_size="{"x":16,"y":2542,"w":383,"h":28,"abs_x":293,"abs_y":2695}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><i bis_size="{"x":16,"y":2542,"w":383,"h":28,"abs_x":293,"abs_y":2695}"><span bis_size="{"x":16,"y":2542,"w":5,"h":28,"abs_x":293,"abs_y":2695}" style="white-space: pre;"> </span><span bis_size="{"x":21,"y":2542,"w":378,"h":28,"abs_x":298,"abs_y":2695}" style="color: #38761d;"><!-- Added for logstash Encoder--></span></i></span></div>
</div>
<div bis_size="{"x":16,"y":2570,"w":653,"h":28,"abs_x":293,"abs_y":2723}" style="text-align: justify;">
<div bis_size="{"x":16,"y":2570,"w":653,"h":28,"abs_x":293,"abs_y":2723}">
<span bis_size="{"x":16,"y":2570,"w":164,"h":28,"abs_x":293,"abs_y":2723}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><i bis_size="{"x":16,"y":2570,"w":164,"h":28,"abs_x":293,"abs_y":2723}"><span bis_size="{"x":16,"y":2570,"w":5,"h":28,"abs_x":293,"abs_y":2723}" style="white-space: pre;"> </span><span bis_size="{"x":21,"y":2570,"w":158,"h":28,"abs_x":298,"abs_y":2723}" style="color: #20124d;"><dependency></span></i></span></div>
</div>
<div bis_size="{"x":16,"y":2598,"w":653,"h":28,"abs_x":293,"abs_y":2751}" style="text-align: justify;">
<div bis_size="{"x":16,"y":2598,"w":653,"h":28,"abs_x":293,"abs_y":2751}">
<span bis_size="{"x":16,"y":2598,"w":482,"h":28,"abs_x":293,"abs_y":2751}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><i bis_size="{"x":16,"y":2598,"w":482,"h":28,"abs_x":293,"abs_y":2751}"><span bis_size="{"x":16,"y":2598,"w":11,"h":28,"abs_x":293,"abs_y":2751}" style="white-space: pre;"> </span><groupId>net.logstash.logback</groupId></i></span></div>
</div>
<div bis_size="{"x":16,"y":2626,"w":653,"h":28,"abs_x":293,"abs_y":2779}" style="text-align: justify;">
<div bis_size="{"x":16,"y":2626,"w":653,"h":28,"abs_x":293,"abs_y":2779}">
<span bis_size="{"x":16,"y":2626,"w":570,"h":28,"abs_x":293,"abs_y":2779}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><i bis_size="{"x":16,"y":2626,"w":570,"h":28,"abs_x":293,"abs_y":2779}"><span bis_size="{"x":16,"y":2626,"w":11,"h":28,"abs_x":293,"abs_y":2779}" style="white-space: pre;"> </span><artifactId>logstash-logback-encoder</artifactId></i></span></div>
</div>
<div bis_size="{"x":16,"y":2654,"w":653,"h":28,"abs_x":293,"abs_y":2807}" style="text-align: justify;">
<div bis_size="{"x":16,"y":2654,"w":653,"h":28,"abs_x":293,"abs_y":2807}">
<span bis_size="{"x":16,"y":2654,"w":277,"h":28,"abs_x":293,"abs_y":2807}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><i bis_size="{"x":16,"y":2654,"w":277,"h":28,"abs_x":293,"abs_y":2807}"><span bis_size="{"x":16,"y":2654,"w":11,"h":28,"abs_x":293,"abs_y":2807}" style="white-space: pre;"> </span><version>6.2</version></i></span></div>
</div>
<div bis_size="{"x":16,"y":2682,"w":653,"h":18,"abs_x":293,"abs_y":2835}">
<i bis_size="{"x":16,"y":2682,"w":0,"h":0,"abs_x":293,"abs_y":2835}"><span bis_size="{"x":16,"y":2682,"w":0,"h":0,"abs_x":293,"abs_y":2835}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"></span></i><br bis_size="{"x":16,"y":2682,"w":0,"h":17,"abs_x":293,"abs_y":2835}" /></div>
<div bis_size="{"x":16,"y":2701,"w":653,"h":28,"abs_x":293,"abs_y":2854}" style="text-align: justify;">
<div bis_size="{"x":16,"y":2701,"w":653,"h":28,"abs_x":293,"abs_y":2854}">
<span bis_size="{"x":16,"y":2701,"w":175,"h":28,"abs_x":293,"abs_y":2854}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><i bis_size="{"x":16,"y":2701,"w":175,"h":28,"abs_x":293,"abs_y":2854}"><span bis_size="{"x":16,"y":2701,"w":5,"h":28,"abs_x":293,"abs_y":2854}" style="white-space: pre;"> </span></dependency></i></span></div>
</div>
<div bis_size="{"x":16,"y":2729,"w":653,"h":140,"abs_x":293,"abs_y":2882}">
<span bis_size="{"x":16,"y":2729,"w":0,"h":28,"abs_x":293,"abs_y":2882}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":2729,"w":0,"h":28,"abs_x":293,"abs_y":2882}" /></span>
<span bis_size="{"x":16,"y":2757,"w":652,"h":112,"abs_x":293,"abs_y":2910}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Open <b bis_size="{"x":79,"y":2757,"w":238,"h":28,"abs_x":356,"abs_y":2910}">logback-spring.xml</b> file which is under the <b bis_size="{"x":16,"y":2785,"w":115,"h":28,"abs_x":293,"abs_y":2938}">resource </b>folder and create new appender (say elk). The task of this appender is to push logs to the destination TCP socket and under this appender, compulsory use LogstashEncoder.</span></div>
<div bis_size="{"x":16,"y":2869,"w":653,"h":18,"abs_x":293,"abs_y":3022}">
<br bis_size="{"x":16,"y":2869,"w":0,"h":17,"abs_x":293,"abs_y":3022}" /></div>
<div bis_size="{"x":16,"y":2887,"w":653,"h":84,"abs_x":293,"abs_y":3040}">
<span bis_size="{"x":16,"y":2887,"w":652,"h":84,"abs_x":293,"abs_y":3040}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><appender name="elk" class="net.logstash.logback.appender.LogstashTcpSocketAppender"></span></div>
<div bis_size="{"x":16,"y":2971,"w":653,"h":28,"abs_x":293,"abs_y":3124}">
<span bis_size="{"x":16,"y":2971,"w":492,"h":28,"abs_x":293,"abs_y":3124}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"> <destination>localhost:4560</destination></span></div>
<div bis_size="{"x":16,"y":2999,"w":653,"h":28,"abs_x":293,"abs_y":3152}">
<span bis_size="{"x":16,"y":2999,"w":314,"h":28,"abs_x":293,"abs_y":3152}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"> <!-- encoder is required --></span></div>
<div bis_size="{"x":16,"y":3027,"w":653,"h":56,"abs_x":293,"abs_y":3180}">
<span bis_size="{"x":16,"y":3027,"w":615,"h":56,"abs_x":293,"abs_y":3180}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"> <encoder class="net.logstash.logback.encoder.LogstashEncoder" /></span></div>
<div bis_size="{"x":16,"y":3083,"w":653,"h":18,"abs_x":293,"abs_y":3236}">
<span bis_size="{"x":16,"y":3083,"w":0,"h":0,"abs_x":293,"abs_y":3236}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"></span><br bis_size="{"x":16,"y":3083,"w":0,"h":17,"abs_x":293,"abs_y":3236}" /></div>
<div bis_size="{"x":16,"y":3102,"w":653,"h":28,"abs_x":293,"abs_y":3255}">
<span bis_size="{"x":16,"y":3102,"w":142,"h":28,"abs_x":293,"abs_y":3255}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"></appender></span></div>
<div bis_size="{"x":16,"y":3130,"w":653,"h":56,"abs_x":293,"abs_y":3283}">
<span bis_size="{"x":16,"y":3130,"w":0,"h":28,"abs_x":293,"abs_y":3283}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":3130,"w":0,"h":28,"abs_x":293,"abs_y":3283}" /></span>
<span bis_size="{"x":16,"y":3158,"w":330,"h":28,"abs_x":293,"abs_y":3311}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Add new appender to root level</span></div>
<div bis_size="{"x":16,"y":3186,"w":653,"h":56,"abs_x":293,"abs_y":3339}">
<span bis_size="{"x":16,"y":3186,"w":0,"h":28,"abs_x":293,"abs_y":3339}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":3186,"w":0,"h":28,"abs_x":293,"abs_y":3339}" /></span>
<span bis_size="{"x":16,"y":3214,"w":469,"h":28,"abs_x":293,"abs_y":3367}" style="color: #38761d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><span bis_size="{"x":16,"y":3214,"w":5,"h":28,"abs_x":293,"abs_y":3367}" style="white-space: pre;"> </span><!-- LOGGING everything at INFO level --></span></div>
<div bis_size="{"x":16,"y":3242,"w":653,"h":28,"abs_x":293,"abs_y":3395}">
<span bis_size="{"x":16,"y":3242,"w":212,"h":28,"abs_x":293,"abs_y":3395}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><span bis_size="{"x":16,"y":3242,"w":5,"h":28,"abs_x":293,"abs_y":3395}" style="white-space: pre;"> </span><span bis_size="{"x":21,"y":3242,"w":206,"h":28,"abs_x":298,"abs_y":3395}" style="color: #20124d;"><root level="info"></span></span></div>
<div bis_size="{"x":16,"y":3270,"w":653,"h":28,"abs_x":293,"abs_y":3423}">
<span bis_size="{"x":16,"y":3270,"w":385,"h":28,"abs_x":293,"abs_y":3423}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><span bis_size="{"x":16,"y":3270,"w":11,"h":28,"abs_x":293,"abs_y":3423}" style="white-space: pre;"> </span><appender-ref ref="RollingFile" /></span></div>
<div bis_size="{"x":16,"y":3298,"w":653,"h":28,"abs_x":293,"abs_y":3451}">
<span bis_size="{"x":16,"y":3298,"w":352,"h":28,"abs_x":293,"abs_y":3451}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><span bis_size="{"x":16,"y":3298,"w":11,"h":28,"abs_x":293,"abs_y":3451}" style="white-space: pre;"> </span><appender-ref ref="Console" /></span></div>
<div bis_size="{"x":16,"y":3326,"w":653,"h":28,"abs_x":293,"abs_y":3479}">
<span bis_size="{"x":16,"y":3326,"w":299,"h":28,"abs_x":293,"abs_y":3479}" style="color: #20124d; font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><span bis_size="{"x":16,"y":3326,"w":11,"h":28,"abs_x":293,"abs_y":3479}" style="white-space: pre;"> </span><appender-ref ref="elk" /></span></div>
<div bis_size="{"x":16,"y":3354,"w":653,"h":28,"abs_x":293,"abs_y":3507}">
<span bis_size="{"x":16,"y":3362,"w":91,"h":17,"abs_x":293,"abs_y":3515}" style="color: #20124d;"><span bis_size="{"x":16,"y":3354,"w":5,"h":28,"abs_x":293,"abs_y":3507}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large; white-space: pre;"> </span><span bis_size="{"x":21,"y":3354,"w":86,"h":28,"abs_x":298,"abs_y":3507}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"></root></span></span></div>
<div bis_size="{"x":16,"y":3382,"w":653,"h":112,"abs_x":293,"abs_y":3535}">
<span bis_size="{"x":16,"y":3382,"w":0,"h":28,"abs_x":293,"abs_y":3535}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":3382,"w":0,"h":28,"abs_x":293,"abs_y":3535}" /></span>
<span bis_size="{"x":16,"y":3410,"w":645,"h":84,"abs_x":293,"abs_y":3563}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Save all files and start your application. So, we are done with all the setup. Its time to check whether all the changes are done properly or not.</span></div>
<div bis_size="{"x":16,"y":3494,"w":653,"h":112,"abs_x":293,"abs_y":3647}">
<span bis_size="{"x":16,"y":3494,"w":0,"h":28,"abs_x":293,"abs_y":3647}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":3494,"w":0,"h":28,"abs_x":293,"abs_y":3647}" /></span>
<span bis_size="{"x":16,"y":3522,"w":647,"h":84,"abs_x":293,"abs_y":3675}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Open Kibana on your browser (http://localhost:5601) and select your index under the Discover tab. You will see all logs are populating on Kibana as well.</span></div>
<div bis_size="{"x":16,"y":3606,"w":653,"h":28,"abs_x":293,"abs_y":3759}">
<span bis_size="{"x":16,"y":3606,"w":0,"h":28,"abs_x":293,"abs_y":3759}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":3606,"w":0,"h":28,"abs_x":293,"abs_y":3759}" /></span>
</div>
<div bis_size="{"x":16,"y":3634,"w":653,"h":344,"abs_x":293,"abs_y":3787}" class="separator" style="clear: both; text-align: center;">
<a bis_size="{"x":32,"y":3963,"w":640,"h":17,"abs_x":309,"abs_y":4116}" href="https://1.bp.blogspot.com/-AwDvJsJVUT8/XcRs2riAP6I/AAAAAAAAJ-0/vLIMYBSsyQEk6U0dlrG5mCSOMMOG8GjgQCLcBGAsYHQ/s1600/kibanaConsole.JPG" style="margin-left: 1em; margin-right: 1em;"><img bis_size="{"x":32,"y":3634,"w":640,"h":344,"abs_x":309,"abs_y":3787}" border="0" data-original-height="863" data-original-width="1600" height="344" src="https://1.bp.blogspot.com/-AwDvJsJVUT8/XcRs2riAP6I/AAAAAAAAJ-0/vLIMYBSsyQEk6U0dlrG5mCSOMMOG8GjgQCLcBGAsYHQ/s640/kibanaConsole.JPG" width="640" /></a></div>
<div bis_size="{"x":16,"y":3978,"w":653,"h":112,"abs_x":293,"abs_y":4131}">
<span bis_size="{"x":16,"y":3978,"w":0,"h":28,"abs_x":293,"abs_y":4131}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":3978,"w":0,"h":28,"abs_x":293,"abs_y":4131}" /></span>
<span bis_size="{"x":16,"y":4006,"w":0,"h":28,"abs_x":293,"abs_y":4159}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":4006,"w":0,"h":28,"abs_x":293,"abs_y":4159}" /></span>
<span bis_size="{"x":16,"y":4034,"w":653,"h":56,"abs_x":293,"abs_y":4187}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">Congratulations! Our configuration is working absolutely fine and it is pushing logs to Elastic Search. </span></div>
<div bis_size="{"x":16,"y":3978,"w":653,"h":112,"abs_x":293,"abs_y":4131}">
<span bis_size="{"x":16,"y":4034,"w":653,"h":56,"abs_x":293,"abs_y":4187}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br /></span></div>
<div bis_size="{"x":16,"y":3978,"w":653,"h":112,"abs_x":293,"abs_y":4131}">
<span bis_size="{"x":16,"y":4034,"w":653,"h":56,"abs_x":293,"abs_y":4187}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;">You can download the source code from <a href="https://github.com/abdulwaheed18/spring-boot-tutorial/tree/elkstack/spring-logger" target="_blank">here</a>, ELK code chnages are under elkstack branch.</span></div>
<div bis_size="{"x":16,"y":4090,"w":653,"h":56,"abs_x":293,"abs_y":4243}">
<span bis_size="{"x":16,"y":4090,"w":0,"h":28,"abs_x":293,"abs_y":4243}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":4090,"w":0,"h":28,"abs_x":293,"abs_y":4243}" /></span>
<span bis_size="{"x":16,"y":4118,"w":0,"h":28,"abs_x":293,"abs_y":4271}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":4118,"w":0,"h":28,"abs_x":293,"abs_y":4271}" /></span>
</div>
<div bis_size="{"x":16,"y":4146,"w":653,"h":112,"abs_x":293,"abs_y":4299}">
<span bis_size="{"x":16,"y":4146,"w":0,"h":28,"abs_x":293,"abs_y":4299}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":4146,"w":0,"h":28,"abs_x":293,"abs_y":4299}" /></span>
<span bis_size="{"x":16,"y":4174,"w":0,"h":28,"abs_x":293,"abs_y":4327}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":4174,"w":0,"h":28,"abs_x":293,"abs_y":4327}" /></span>
<span bis_size="{"x":16,"y":4202,"w":0,"h":28,"abs_x":293,"abs_y":4355}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":4202,"w":0,"h":28,"abs_x":293,"abs_y":4355}" /></span>
<span bis_size="{"x":16,"y":4230,"w":0,"h":28,"abs_x":293,"abs_y":4383}" style="font-family: 'georgia' , 'times new roman' , serif; font-size: large;"><br bis_size="{"x":16,"y":4230,"w":0,"h":28,"abs_x":293,"abs_y":4383}" /></span>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com12tag:blogger.com,1999:blog-630363181754150660.post-74930541531792467812019-11-03T03:33:00.000+05:302019-11-03T03:33:29.309+05:30ELK (ElasticSearch Logstash and Kibana ) Installation on Windows 10<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">In this blog, I’ll show you how can we install ELK on our windows 10 machine - that is ElasticSearch, Logstash, and Kibana.<br /><br />These three different products are most commonly used together for log analysis. Using ELK stack, we can achieve centralized logging which helps in identifying the problems. </span><div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">ELK is heavily used in microservices architecture where your docker images are running on 1000's of POD and you can't go to each pod to trace the logs.</span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><b>Logstash:</b></span></h3>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">It is the data collection pipeline tool. It is the first component of ELK Stack which collects data inputs and feeds it to the Elasticsearch. It collects various types of data from different sources, all at once and makes it available immediately for further use.</span><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /><br /></span><h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><b>Elasticsearch:</b></span></h3>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br />It is a NoSQL database which is based on Lucene search engine and is built with RESTful APIs. It is a highly flexible and distributed search and analytics engine. Also, it provides simple deployment, maximum reliability, and easy management through horizontal scalability. It provides advanced queries to perform detailed analysis and stores all the data centrally for quick search of the documents. <br /><br /></span><h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><b>Kibana:</b></span></h3>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br />Kibana is a data visualization tool. It is used for visualizing the Elasticsearch documents and helps the developers to have an immediate insight into it. Kibana dashboard provides various interactive diagrams, geospatial data, timelines, and graphs to visualize the complex queries done using Elasticsearch. Using Kibana you can create and save custom graphs according to your specific needs.<br /><br /></span><div>
<h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Download</span></h3>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">You can download all the zip from here <br /><ul style="text-align: left;">
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><a href="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-windows-x86_64.zip">https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-windows-x86_64.zip</a></span></li>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><a href="https://artifacts.elastic.co/downloads/logstash/logstash-7.4.2.zip">https://artifacts.elastic.co/downloads/logstash/logstash-7.4.2.zip</a></span></li>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><a href="https://artifacts.elastic.co/downloads/kibana/kibana-7.4.2-windows-x86_64.zip">https://artifacts.elastic.co/downloads/kibana/kibana-7.4.2-windows-x86_64.zip</a></span></li>
</ul>
</span></div>
<div style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Unzip all the three folders to get their folder files.</span></div>
<div style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Install ElasticSearch</span></h3>
<div style="text-align: left;">
<ul style="text-align: left;">
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Open ElasticSearch folder and go to its bin folder.</span></li>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Run ElasticSearch to start the ElasticSearch server.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-wtqV5A6K-vU/Xb3wMyWyK5I/AAAAAAAAJ88/4o2JAGCiWxoZ-IzfHT-piYWZUhToKqgfQCLcBGAsYHQ/s1600/ELKbat.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="435" data-original-width="1298" height="214" src="https://1.bp.blogspot.com/-wtqV5A6K-vU/Xb3wMyWyK5I/AAAAAAAAJ88/4o2JAGCiWxoZ-IzfHT-piYWZUhToKqgfQCLcBGAsYHQ/s640/ELKbat.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<ul style="text-align: left;">
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Once started, go to browser and type localhost:9200</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-2v4vfRWEe5s/Xb3wM79lc_I/AAAAAAAAJ84/11R-ZEejAIgAGYPScJjknAmNooRDzLcBgCEwYBhgL/s1600/elastic9200.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="428" data-original-width="475" height="574" src="https://1.bp.blogspot.com/-2v4vfRWEe5s/Xb3wM79lc_I/AAAAAAAAJ84/11R-ZEejAIgAGYPScJjknAmNooRDzLcBgCEwYBhgL/s640/elastic9200.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Install Kibana</span></h3>
</div>
<div style="text-align: left;">
<ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Open Kibana folder and go to its bin folder.</span></li>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Run kibana.bat file to start the Kibana server.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-aYfZMmNpMtY/Xb3x9H51ZrI/AAAAAAAAJ9Q/Ah7HksHSK94PnhxvrgoWzWXbEccLKERVwCLcBGAsYHQ/s1600/KibanaBat.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="604" data-original-width="1351" height="286" src="https://1.bp.blogspot.com/-aYfZMmNpMtY/Xb3x9H51ZrI/AAAAAAAAJ9Q/Ah7HksHSK94PnhxvrgoWzWXbEccLKERVwCLcBGAsYHQ/s640/KibanaBat.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Once started, go to browser and type localhost:5601</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-cbCIlJzThm0/Xb3x9DcEYyI/AAAAAAAAJ9M/MnSnQZG0vz48opcsOchFCLLpDDbSleOWgCEwYBhgL/s1600/KIbana5601.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="818" data-original-width="1600" height="326" src="https://1.bp.blogspot.com/-cbCIlJzThm0/Xb3x9DcEYyI/AAAAAAAAJ9M/MnSnQZG0vz48opcsOchFCLLpDDbSleOWgCEwYBhgL/s640/KIbana5601.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: Georgia, "Times New Roman", serif; font-size: large;">Install Logstash</span></h3>
<div>
<ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Logstash is a pipeline that pushes data to elasticSearch. So,</span><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> before starting the Logstash. We have to create one config file.</span></li>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Logstash config file will be having three parts i.e. input, filter (Optional) & output.</span></li>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Create logstash.conf file under ${logstash}/conf folder. it will simply take the input from the console and push it to ElasticSearch.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-MpzLC8c92Ss/Xb338FGzabI/AAAAAAAAJ9g/7eU-RzMDj7gIHRO8ifobuFg6fF8Q6j0YACLcBGAsYHQ/s1600/logstashconf.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="288" data-original-width="429" height="428" src="https://1.bp.blogspot.com/-MpzLC8c92Ss/Xb338FGzabI/AAAAAAAAJ9g/7eU-RzMDj7gIHRO8ifobuFg6fF8Q6j0YACLcBGAsYHQ/s640/logstashconf.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Run below command to start Logstash server and it will wait for the input to push it to elasticsearch.</span></li>
</ul>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><div style="text-align: center;">
<i>bin\logstash -f .\config\logstash.conf</i></div>
<div style="text-align: center;">
<i><br /></i></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-7QZnYbegC9w/Xb338ZHE0pI/AAAAAAAAJ9s/DOdkpf2FaGUVSO-19o9e7taY-DENctj9QCEwYBhgL/s1600/logstashBat.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="736" data-original-width="1600" height="294" src="https://1.bp.blogspot.com/-7QZnYbegC9w/Xb338ZHE0pI/AAAAAAAAJ9s/DOdkpf2FaGUVSO-19o9e7taY-DENctj9QCEwYBhgL/s640/logstashBat.JPG" width="640" /></a></div>
</span><ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Once started, go to browser and type localhost:9600</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-r-z_fgUFrTY/Xb338KEr2KI/AAAAAAAAJ9o/0xZWItRfkKQasLW4WPteIdIzVEmKoDC4QCEwYBhgL/s1600/Logstash9600.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="575" data-original-width="770" height="476" src="https://1.bp.blogspot.com/-r-z_fgUFrTY/Xb338KEr2KI/AAAAAAAAJ9o/0xZWItRfkKQasLW4WPteIdIzVEmKoDC4QCEwYBhgL/s640/Logstash9600.JPG" width="640" /></a></div>
<ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">To push the data, I have copied the log file of one project to the console.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-8QqjDBGLih0/Xb36R4iCTqI/AAAAAAAAJ-A/5df-w2t3JyoG7pbmpMLW38POrCJjN9HpQCLcBGAsYHQ/s1600/loglogfile.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="759" data-original-width="1600" height="302" src="https://1.bp.blogspot.com/-8QqjDBGLih0/Xb36R4iCTqI/AAAAAAAAJ-A/5df-w2t3JyoG7pbmpMLW38POrCJjN9HpQCLcBGAsYHQ/s640/loglogfile.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Once done, go to Kibana portal, Management-> Index Patterns -> Create Index pattern. You will observe that <b>logstashdemo</b> which we have set in logstash.conf file is already present here. Now define Kibana index by setting the same name and click on n<b>ext step button.</b></span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-9k6S5-t5_UA/Xb36QpzXeCI/AAAAAAAAJ94/GcBCQwIPQAc-qbeIX9eeQ3rioQB8vPVFwCEwYBhgL/s1600/KIbanaIndexing1.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="680" data-original-width="1600" height="270" src="https://1.bp.blogspot.com/-9k6S5-t5_UA/Xb36QpzXeCI/AAAAAAAAJ94/GcBCQwIPQAc-qbeIX9eeQ3rioQB8vPVFwCEwYBhgL/s640/KIbanaIndexing1.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Add @timestamp to set Default time and click on Create Index Pattern.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ffZvtV77Hpg/Xb36Qqb7jFI/AAAAAAAAJ-I/EKKhTX5zt3Mw6pK3Nh8Ii5hI4FStxY4dQCEwYBhgL/s1600/KIbanaIndexing2.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="703" data-original-width="1600" height="280" src="https://1.bp.blogspot.com/-ffZvtV77Hpg/Xb36Qqb7jFI/AAAAAAAAJ-I/EKKhTX5zt3Mw6pK3Nh8Ii5hI4FStxY4dQCEwYBhgL/s640/KIbanaIndexing2.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<ul>
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Index has been created. Now, to view the data, go to discover tab and click on message (All the logs will be pushed under message index)</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Mrq-_HXMGUQ/Xb36QtpSm5I/AAAAAAAAJ-M/dGf_xR7veuEG9T-I9fwqKrmrdKttXAxEwCEwYBhgL/s1600/kibanafinale.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="966" data-original-width="1600" height="386" src="https://1.bp.blogspot.com/-Mrq-_HXMGUQ/Xb36QtpSm5I/AAAAAAAAJ-M/dGf_xR7veuEG9T-I9fwqKrmrdKttXAxEwCEwYBhgL/s640/kibanafinale.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<div style="text-align: center;">
Congratulation! We are done with the ELK Setup on Windows 10</div>
</span><div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
</div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-71405957721793935732019-11-03T00:18:00.000+05:302019-11-03T11:40:38.690+05:30How to create Docker Image and push java app in a Docker Engine<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">In this blog, I am going to share my knowledge on the creation of a docker image and how can we run in a Docker Engine. <br /><br /><b>Prerequisite</b></span><br />
<ul><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">
<li><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Basic Knowledge of Docker </span></li>
<li>Docker must be running on your machine.</li>
<li>Good to aware of Spring boot application.</li>
</span></ul>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">
I already have one spring boot application in my IntelliJ which expose one endpoint /users/{id}. We will see how can we push and run this application in a docker container. </span><br />
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ljDZ1DykyEs/Xb3CDb6zanI/AAAAAAAAJ6Q/soFeP9V_iBI9dYu9yeOzc3kDeJ_UefIwQCLcBGAsYHQ/s1600/Docker.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="559" data-original-width="802" height="446" src="https://1.bp.blogspot.com/-ljDZ1DykyEs/Xb3CDb6zanI/AAAAAAAAJ6Q/soFeP9V_iBI9dYu9yeOzc3kDeJ_UefIwQCLcBGAsYHQ/s640/Docker.JPG" width="640" /></a></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /><br />We need to create one file named Dockerfile to add docker instruction (Check above image).</span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-otxRDIxYEXQ/Xb3EJO2XVwI/AAAAAAAAJ6c/ov6Vt2kgtV4VRFNyEsrQPvwHBJlgzA-0ACLcBGAsYHQ/s1600/Dockerfile.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="179" data-original-width="668" height="170" src="https://1.bp.blogspot.com/-otxRDIxYEXQ/Xb3EJO2XVwI/AAAAAAAAJ6c/ov6Vt2kgtV4VRFNyEsrQPvwHBJlgzA-0ACLcBGAsYHQ/s640/Dockerfile.JPG" width="640" /></a></div>
<div>
<br /></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Now go to Terminal and check whether the docker is running or not on your machine.</span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-zfIVw0DOSO0/Xb3Em_Z5V0I/AAAAAAAAJ6k/Yp2dfwxlcrMA5IAEei11dlYGvq7FASVKgCLcBGAsYHQ/s1600/dockerVersion.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="66" data-original-width="436" height="96" src="https://1.bp.blogspot.com/-zfIVw0DOSO0/Xb3Em_Z5V0I/AAAAAAAAJ6k/Yp2dfwxlcrMA5IAEei11dlYGvq7FASVKgCLcBGAsYHQ/s640/dockerVersion.JPG" width="640" /></a></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Run docker build to create an image and push it to the container using the command.</span></div>
<blockquote class="tr_bq">
<span style="color: #20124d; font-family: "georgia" , "times new roman" , serif; font-size: large;"><i>docker build -f Dockerfile -t docker-spring-ehcache .</i></span></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-gb56m-Oy0SY/Xb3Em3mSZ4I/AAAAAAAAJ6o/Zcd2g6VBcCsaJ0h9x8S9rxd6b2qGJENlgCLcBGAsYHQ/s1600/dockerBuild.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="597" data-original-width="713" height="534" src="https://1.bp.blogspot.com/-gb56m-Oy0SY/Xb3Em3mSZ4I/AAAAAAAAJ6o/Zcd2g6VBcCsaJ0h9x8S9rxd6b2qGJENlgCLcBGAsYHQ/s640/dockerBuild.JPG" width="640" /></a></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">The above command will execute all the operations that we have mentioned in our Dockerfile like pulling OpenJDK 8 from the docker hub if not exist.</span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Let's see if our image got pushed to docker containers or not by listing all docker images.</span></div>
<blockquote class="tr_bq" style="text-align: center;">
<span style="color: #20124d; font-family: "georgia" , "times new roman" , serif; font-size: large;"><i>docker images</i></span></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-DRiFU4jd-lA/Xb3Gdr-0GyI/AAAAAAAAJ64/1nB5GIo8oLQE8XW9brnW3FMc1yxew4bHwCLcBGAsYHQ/s1600/dockerImages.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="315" data-original-width="853" height="236" src="https://1.bp.blogspot.com/-DRiFU4jd-lA/Xb3Gdr-0GyI/AAAAAAAAJ64/1nB5GIo8oLQE8XW9brnW3FMc1yxew4bHwCLcBGAsYHQ/s640/dockerImages.JPG" width="640" /></a></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Great! Our image is present in the docker container. Let's run it.</span></div>
<blockquote class="tr_bq">
<span style="color: #20124d; font-family: "georgia" , "times new roman" , serif; font-size: large;"><i>docker run -p 8070:8085 docker-spring-ehcache</i></span></blockquote>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Over here, we are telling the Docker to start the application and map docker container port 8085 to our local port 8070. </span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><b>Note: </b>Make sure your application has started at 8085 in docker container else it won't be able to map it. Spring boot by default start application on port 8080 so please specify server.port-8050 in application.properties file.</span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-j5YbeDuxOS8/Xb3ODYU_W4I/AAAAAAAAJ7E/-JTHtsNdR5soMUkL91bGZw43LmDlb1jxwCLcBGAsYHQ/s1600/dockerRUn.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="553" data-original-width="1321" height="266" src="https://1.bp.blogspot.com/-j5YbeDuxOS8/Xb3ODYU_W4I/AAAAAAAAJ7E/-JTHtsNdR5soMUkL91bGZw43LmDlb1jxwCLcBGAsYHQ/s640/dockerRUn.JPG" width="640" /></a></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div>
<br /></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Now go to your browser and hit the endpoint and see if we are getting the response from localhost:8070 or not.</span></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-jI1fl0AfpLk/Xb3OfFJbYzI/AAAAAAAAJ7M/quzBY-ZaLogkWZsZf1kdXwsaJrSc1J5RQCLcBGAsYHQ/s1600/DockerBrowser.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="255" data-original-width="349" height="466" src="https://1.bp.blogspot.com/-jI1fl0AfpLk/Xb3OfFJbYzI/AAAAAAAAJ7M/quzBY-ZaLogkWZsZf1kdXwsaJrSc1J5RQCLcBGAsYHQ/s640/DockerBrowser.JPG" width="640" /></a></div>
<blockquote class="tr_bq">
<div style="text-align: center;">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"></span><br />
<div style="text-align: center;">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Happy Coding!!!</span></div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">
</span></blockquote>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-12724816904036637702019-11-01T01:19:00.000+05:302019-11-01T01:19:22.425+05:30Sonar Integration with Maven <div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">In my previous <a href="http://www.waheedtechblog.com/2019/11/sonarqube-setup-on-windows-10.html" target="_blank">blog</a>, we have already seen how to setup SonarQube server on Windows 10. We have also seen that how can we generate sonar report using <a href="http://www.waheedtechblog.com/2019/11/code-analysis-using-sonarscanner-on.html" target="_blank">sonar-scanner</a>. In this blog, I’ll show you how to generate sonar report by configuring sonar dependency to maven project. </span><div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span><h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Steps to setup sonar in Maven </span></h3>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><ul style="text-align: left;">
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">We have to configure <b>pluginManagement </b>and <b>Profile </b>for Sonar in pom.xml file</span></li>
<li>Add below pluginManagement dependency to your pom.xml </li>
</ul>
</span><blockquote class="tr_bq">
<span style="font-family: Georgia, Times New Roman, serif;"><pluginManagement><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <plugins><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <plugin><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <groupId>org.apache.maven.plugins</groupId><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <artifactId>maven-compiler-plugin</artifactId><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <version>3.8.1</version><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </plugin><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <plugin><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <groupId>org.sonarsource.scanner.maven</groupId><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <artifactId>sonar-maven-plugin</artifactId><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <version>3.6.0.1398</version><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </plugin><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <plugin><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <groupId>org.jacoco</groupId><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <artifactId>jacoco-maven-plugin</artifactId><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <version>0.8.4</version><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </plugin><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </plugins><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </pluginManagement></span></blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-vKhQQCshdzI/Xbs5uVfE0FI/AAAAAAAAJ5w/EvCX0TkRmP4cTzfVPiOLTXGL7PKUvakiACLcBGAsYHQ/s1600/pom1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="549" data-original-width="621" height="564" src="https://1.bp.blogspot.com/-vKhQQCshdzI/Xbs5uVfE0FI/AAAAAAAAJ5w/EvCX0TkRmP4cTzfVPiOLTXGL7PKUvakiACLcBGAsYHQ/s640/pom1.JPG" width="640" /></a></div>
<br />
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /><ul style="text-align: left;">
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Add Profile to pom.xml file </span></li>
</ul>
</span><blockquote class="tr_bq">
<span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"><profiles><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <profile><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <id>coverage</id><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <activation><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <activeByDefault>true</activeByDefault><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </activation><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <build><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <plugins><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <plugin><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <groupId>org.jacoco</groupId><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <artifactId>jacoco-maven-plugin</artifactId><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <executions><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <execution><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <id>prepare-agent</id><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <goals><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <goal>prepare-agent</goal><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </goals><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </execution><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <execution><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <id>report</id><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <goals><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> <goal>report</goal><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </goals><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </execution><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </executions><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </plugin><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </plugins><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </build><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </profile><br /> </span><span style="font-family: Georgia, Times New Roman, serif;"><br /></span><span style="font-family: Georgia, Times New Roman, serif;"> </profiles> </span></blockquote>
<span style="font-family: Georgia, Times New Roman, serif;"><div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-R2ZwZ0vhf0c/Xbs5ue81RxI/AAAAAAAAJ5s/LbOwpUg9kS49HBbYAFr36sML7kfQfopSACEwYBhgL/s1600/pom2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="627" data-original-width="683" height="586" src="https://1.bp.blogspot.com/-R2ZwZ0vhf0c/Xbs5ue81RxI/AAAAAAAAJ5s/LbOwpUg9kS49HBbYAFr36sML7kfQfopSACEwYBhgL/s640/pom2.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif;"><br /></span></div>
<br /><ul style="text-align: left;">
<li><span style="font-size: large;">Build the project, execute all the tests and analyze the project with SonarQube Scanner for Maven:</span></li>
</ul>
<div>
<span style="font-size: large; text-align: center;"> mvn clean verify sonar:sonar</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-2r7yMfRNVXw/Xbs6Gl3yXSI/AAAAAAAAJ58/b2vjvrXalgga-W5AKU4V6BcL_9w8XxOzgCLcBGAsYHQ/s1600/sonarmaven.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="660" data-original-width="1600" height="262" src="https://1.bp.blogspot.com/-2r7yMfRNVXw/Xbs6Gl3yXSI/AAAAAAAAJ58/b2vjvrXalgga-W5AKU4V6BcL_9w8XxOzgCLcBGAsYHQ/s640/sonarmaven.JPG" width="640" /></a></div>
<div>
<span style="font-size: large; text-align: center;"><br /></span></div>
<ul style="text-align: left;">
<li><span style="font-size: large;">Once done, Check your SonarQube which will generate the code analysis report for your current project. My project name was api-gateway so it generated with the name api-gateway.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-kKyeKs9O9fc/Xbs6bkMrBEI/AAAAAAAAJ6E/3OOb6FtMR1076FAHE4IbA_lsL8ITbN1mQCLcBGAsYHQ/s1600/sonarserver.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="424" data-original-width="1255" height="216" src="https://1.bp.blogspot.com/-kKyeKs9O9fc/Xbs6bkMrBEI/AAAAAAAAJ6E/3OOb6FtMR1076FAHE4IbA_lsL8ITbN1mQCLcBGAsYHQ/s640/sonarserver.JPG" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
</span><blockquote class="tr_bq" style="text-align: center;">
<br /></blockquote>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0India20.593684 78.962880000000041-8.6041045000000018 37.654286000000042 49.7914725 120.27147400000004tag:blogger.com,1999:blog-630363181754150660.post-32741788023747449662019-11-01T00:45:00.000+05:302019-11-01T00:45:15.516+05:30Code Analysis using SonarScanner on Windows 10<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">In my previous <a href="http://www.waheedtechblog.com/2019/11/sonarqube-setup-on-windows-10.html" target="_blank">blog</a>, we have already seen how to setup SonarQube server on Windows 10. In this blog, I’ll show you how to generate sonar report using SonarScanner. </span><div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span><h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Step to setup SonarQube </span></h3>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><ul style="text-align: left;">
<li><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Download SonarScanner from <a href="https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/">https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/</a>.</span></li>
<li>Set SonarScanner to PATH under Environment Variable.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-acTeh_PGlH4/XbssnkG4WHI/AAAAAAAAJ4o/VPAlXAC5TjQ-isdpDFsK8AyeYXy8uXEQQCLcBGAsYHQ/s1600/pathVariable.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="143" data-original-width="582" height="156" src="https://1.bp.blogspot.com/-acTeh_PGlH4/XbssnkG4WHI/AAAAAAAAJ4o/VPAlXAC5TjQ-isdpDFsK8AyeYXy8uXEQQCLcBGAsYHQ/s640/pathVariable.JPG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>Unzip it and open sonar-scanner.properties which are under conf directory.</li>
<li>Edit the below lines</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-kj9gLIGfVs0/XbswBcqh6jI/AAAAAAAAJ5A/KFF3H4vQ4HgayOmMx37LCppQCPtwHC1AACLcBGAsYHQ/s1600/sonarscannerprop.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="302" data-original-width="1182" height="162" src="https://1.bp.blogspot.com/-kj9gLIGfVs0/XbswBcqh6jI/AAAAAAAAJ5A/KFF3H4vQ4HgayOmMx37LCppQCPtwHC1AACLcBGAsYHQ/s640/sonarscannerprop.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>Now, go to your project folder directory, open command prompt and run sonar-scanner.bat.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-FhYfcrgeM-g/Xbsww7V8QxI/AAAAAAAAJ5I/h5eK946tveIpnx3ISld3Nd7xXAY2tnQ8ACLcBGAsYHQ/s1600/sonarscannerbat.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="426" data-original-width="1452" height="186" src="https://1.bp.blogspot.com/-FhYfcrgeM-g/Xbsww7V8QxI/AAAAAAAAJ5I/h5eK946tveIpnx3ISld3Nd7xXAY2tnQ8ACLcBGAsYHQ/s640/sonarscannerbat.JPG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>It will do the analysis and then post the result to the SonarQube server http://locathost:9000/ having the project name as sonar key that we have configured in sonar-scanner.properties file.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-VMlhPZrHYbY/XbsxwJmckFI/AAAAAAAAJ5U/MtQzDOtSTp42ciU9MwFQi78isA0N2AR8QCLcBGAsYHQ/s1600/sonarresult1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="400" data-original-width="1600" height="160" src="https://1.bp.blogspot.com/-VMlhPZrHYbY/XbsxwJmckFI/AAAAAAAAJ5U/MtQzDOtSTp42ciU9MwFQi78isA0N2AR8QCLcBGAsYHQ/s640/sonarresult1.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-_Dy8vIV3iaQ/XbsxwKPn1II/AAAAAAAAJ5Y/jWLW3QvBr1kJIqcxEUSWQ-G6kkelcPKJgCEwYBhgL/s1600/sonarresult2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="785" data-original-width="1600" height="312" src="https://1.bp.blogspot.com/-_Dy8vIV3iaQ/XbsxwKPn1II/AAAAAAAAJ5Y/jWLW3QvBr1kJIqcxEUSWQ-G6kkelcPKJgCEwYBhgL/s640/sonarresult2.JPG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>You can check the JUnit test code coverage as well by clicking on Coverage.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Pl1vff4MdsU/XbsxwEmwIWI/AAAAAAAAJ5k/fN1-eX42oNoBiZE-n2JlNUpCEufE9TyoQCEwYBhgL/s1600/sonarresult3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="725" data-original-width="1600" height="290" src="https://1.bp.blogspot.com/-Pl1vff4MdsU/XbsxwEmwIWI/AAAAAAAAJ5k/fN1-eX42oNoBiZE-n2JlNUpCEufE9TyoQCEwYBhgL/s640/sonarresult3.JPG" width="640" /></a></div>
<div>
<br /></div>
<div style="text-align: center;">
Happy Coding..!!!</div>
</span></div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0India20.593684 78.962880000000041-8.6041045000000018 37.654286000000042 49.7914725 120.27147400000004tag:blogger.com,1999:blog-630363181754150660.post-39538073590444859222019-11-01T00:08:00.000+05:302019-11-01T00:08:59.425+05:30SonarQube setup on windows 10<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Overview </span></h3>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><a href="http://www.sonarqube.org/">SonarQube</a> is an automatic code review tool to detect bugs, vulnerabilities and code smell in your code. It can integrate with your existing workflow to enable continuous code inspection across your project branches and pull requests. </span><div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span><h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Prerequisite </span></h3>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Make sure you have JAVA 11 or higher version installed on your window machine.</span><div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Dc2IXM_RbSw/XbsnblHsNzI/AAAAAAAAJ34/hQkkEXB6itAjGR-cdPn_3VGBwZWPkuuUgCLcBGAsYHQ/s1600/javaVersion.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="129" data-original-width="794" height="102" src="https://1.bp.blogspot.com/-Dc2IXM_RbSw/XbsnblHsNzI/AAAAAAAAJ34/hQkkEXB6itAjGR-cdPn_3VGBwZWPkuuUgCLcBGAsYHQ/s640/javaVersion.JPG" width="640" /></a></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span><h3 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Step to setup SonarQube</span></h3>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><ul style="text-align: left;">
<li><span style="font-family: Georgia, "Times New Roman", serif; font-size: large;">Download Community edition from </span><a href="https://www.sonarqube.org/downloads/" style="font-family: Georgia, "Times New Roman", serif; font-size: x-large;">https://www.sonarqube.org/downloads/</a></li>
<li>Extract it and go to the bin folder.</li>
<li>Choose windows-x86–32 or windows-x86–64 based on your machine configuration.</li>
<li>Run StartSonar.bat which will start the SonarQube server. </li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-vGReIP1tUso/Xbsn3nkQqQI/AAAAAAAAJ4A/Oi9DIjWwcS4Q2cy5ZhiZXMzTXXHJrt0TgCLcBGAsYHQ/s1600/sonarbat.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="530" data-original-width="1428" height="236" src="https://1.bp.blogspot.com/-vGReIP1tUso/Xbsn3nkQqQI/AAAAAAAAJ4A/Oi9DIjWwcS4Q2cy5ZhiZXMzTXXHJrt0TgCLcBGAsYHQ/s640/sonarbat.JPG" width="640" /></a></div>
<ul style="text-align: left;">
<li>Open browser and hit http://localhost:9000</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-uUEMsy1jKm4/XbspMFFLVyI/AAAAAAAAJ4Q/XXXQziWz-qog6r3rDz0FKGWgurKyYJ-RgCLcBGAsYHQ/s1600/localhost.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="729" data-original-width="1600" height="290" src="https://1.bp.blogspot.com/-uUEMsy1jKm4/XbspMFFLVyI/AAAAAAAAJ4Q/XXXQziWz-qog6r3rDz0FKGWgurKyYJ-RgCLcBGAsYHQ/s640/localhost.JPG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>If you want, you can start the sonarQube server to a different port by just updating the port number (sonar.web.port=9070) to sonar.properties which is present under conf directory.</li>
<li>You can login to the portal using default credential (admin:admin).</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-9XWkahOXTK0/XbspmhVN1xI/AAAAAAAAJ4c/L4eRrNQQdlQh2WpLQL7cmTU4IsQmoHYGQCLcBGAsYHQ/s1600/serverup.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="511" data-original-width="1600" height="204" src="https://1.bp.blogspot.com/-9XWkahOXTK0/XbspmhVN1xI/AAAAAAAAJ4c/L4eRrNQQdlQh2WpLQL7cmTU4IsQmoHYGQCLcBGAsYHQ/s640/serverup.JPG" width="640" /></a></div>
<div>
<br /></div>
<div style="text-align: center;">
Congratulation! SonarQube server is up and running on localhost:9000.</div>
</span></div>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0India20.593684 78.962880000000041-8.6041045000000018 37.654286000000042 49.7914725 120.27147400000004tag:blogger.com,1999:blog-630363181754150660.post-72607044332491938052019-10-12T18:24:00.000+05:302019-10-12T18:24:04.808+05:30Postman API – Tips and Tricks<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">I have seen many people using POSTMAN tools but very few of them know how to exactly use all the features of POSTMAN application. So, in this article, I am going to share a few tips/tricks which can be really helpful in our API testing.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<h3 style="text-align: left;">
<ul style="text-align: left;">
<li><span style="color: #20124d; font-family: Arial, Helvetica, sans-serif; font-size: large;">Set Environment Variables</span></li>
</ul>
</h3>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Let’s assume we have an endpoint to get some data after authenticating yourself bypassing username/password.<br /><br />Now, you have to test this endpoint which is deployed on multiple environments like a local machine, test environment and on SIT environment as well. Also, the credential is different for each environment.<br /><br />So, how are we going to test it?<br /><br />Most of the time, I have seen that people create one-one requests for each environment or create one request and then modify the existing username/password and hostname to point to a different environment.<br /><br />The Simple Solution is to set changing parameters as an Environment variable and switch environment to test for different regions.<br /><br />E.g. <a href="http://%3Chostname:POST%3e/token">http://<HOSTNAME:POST>/token</a> and <username>/<password> as basic Authentication </span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<h4>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">How to set environment variables?</span></h4>
<ul>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Click "Manage Environments" icon in the upper right corner of the Postman app.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Click the Add button.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Click "Environment" and enter a name for the new environment.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Add the variables you want to save as key-value pairs.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Click the Add button.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-MNhIkMt-_yA/XZ-FFAXUcxI/AAAAAAAAJ1g/-hecpNGISFAb2-y3pQqFFQiDK2xqs5vwQCEwYBhgL/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="67" data-original-width="1512" height="28" src="https://1.bp.blogspot.com/-MNhIkMt-_yA/XZ-FFAXUcxI/AAAAAAAAJ1g/-hecpNGISFAb2-y3pQqFFQiDK2xqs5vwQCEwYBhgL/s640/1.JPG" width="640" /></span></a></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-OVjWI0U7B94/XZ-FGfBZJbI/AAAAAAAAJ1w/-Yevhggy1WURO3rfrVYW4alMTLC4FjwFQCEwYBhgL/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="672" data-original-width="902" height="475" src="https://1.bp.blogspot.com/-OVjWI0U7B94/XZ-FGfBZJbI/AAAAAAAAJ1w/-Yevhggy1WURO3rfrVYW4alMTLC4FjwFQCEwYBhgL/s640/2.JPG" width="640" /></span></a></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-qg_-bEvNMhQ/XZ-FGqEFLqI/AAAAAAAAJ10/q78vs2JdsHwBKwxo0DcVBgY1T_KDDcvZwCEwYBhgL/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="672" data-original-width="909" height="472" src="https://1.bp.blogspot.com/-qg_-bEvNMhQ/XZ-FGqEFLqI/AAAAAAAAJ10/q78vs2JdsHwBKwxo0DcVBgY1T_KDDcvZwCEwYBhgL/s640/3.JPG" width="640" /></span></a></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
</span><br />
<h3>
<span style="color: #20124d; font-family: Arial, Helvetica, sans-serif; font-size: large;">Selecting an active environment</span></h3>
<ul>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Click the dropdown menu in the upper right corner of the Postman app to select an active environment, or type in the environment name.</span></li>
<li><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Once you select an environment, you can access variables in the active environment scope.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-6vqgBEVo5Hw/XZ-FHayTMdI/AAAAAAAAJ2g/Am6Nsj2TL-UXmPPJFjNLTBOpu_Bzjb_KwCEwYBhgL/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="516" data-original-width="1504" height="218" src="https://1.bp.blogspot.com/-6vqgBEVo5Hw/XZ-FHayTMdI/AAAAAAAAJ2g/Am6Nsj2TL-UXmPPJFjNLTBOpu_Bzjb_KwCEwYBhgL/s640/4.JPG" width="640" /></span></a></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">All the parameters get changed as we switch from one environment to another one.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<h3>
<ul style="text-align: left;">
<li><span style="color: #20124d; font-family: Arial, Helvetica, sans-serif; font-size: large;">Set Global variable</span></li>
</ul>
</h3>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br />Global variables provide a set of variables that are available in all scopes. You can have multiple environments, but only one environment can be active at a time with one set of global variables.<br /><br />To manage global variables, click the gear icon in the upper right corner of the Postman app and select "Manage Environments".<br /><br />Click the Globals button at the bottom of the modal to bring up a key-value editor to add, edit, and delete global variables.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /><img border="0" src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image010.jpg" /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-o-4yKRa48iY/XZ-FHv5gnwI/AAAAAAAAJ2c/OnpWCgtNaPAN1zw5nlWFZ680cgALWNMTACEwYBhgL/s1600/5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="837" data-original-width="1423" height="376" src="https://1.bp.blogspot.com/-o-4yKRa48iY/XZ-FHv5gnwI/AAAAAAAAJ2c/OnpWCgtNaPAN1zw5nlWFZ680cgALWNMTACEwYBhgL/s640/5.JPG" width="640" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-YerC02mXo0Y/XZ-FHkPNxSI/AAAAAAAAJ2g/N8wQPjBmvFEpTRdpsWoanxhij1MefKLUwCEwYBhgL/s1600/6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="663" data-original-width="904" height="469" src="https://1.bp.blogspot.com/-YerC02mXo0Y/XZ-FHkPNxSI/AAAAAAAAJ2g/N8wQPjBmvFEpTRdpsWoanxhij1MefKLUwCEwYBhgL/s640/6.JPG" width="640" /></span></a></div>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"> </span></span><br />
<h3>
<ul style="text-align: left;">
<li><span style="color: #20124d; font-family: Arial, Helvetica, sans-serif; font-size: large;">Set Response to the global variable</span></li>
</ul>
</h3>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br />There are so many scenarios where we wanted to add one of the API responses as a request parameter to the second request like getting token from one API and then passing this token to another endpoint to access the resources.<br /><br />Assuming, I am hitting API to get access token and then setting access-token as a global variable. </span><br />
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-xzhoQzKwfXQ/XZ-FIV46-wI/AAAAAAAAJ2U/I7748RgKNzM1gER6hRVae76UhiF54GTcQCEwYBhgL/s1600/7.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="739" data-original-width="1488" height="316" src="https://1.bp.blogspot.com/-xzhoQzKwfXQ/XZ-FIV46-wI/AAAAAAAAJ2U/I7748RgKNzM1gER6hRVae76UhiF54GTcQCEwYBhgL/s640/7.JPG" width="640" /></span></a></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /><img border="0" src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image014.jpg" /></span><br />
<ul><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Once you get the access_token in your response then go to Tests tab.</span></li>
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Click on ‘set a global variable’ or add scripts as shown below</span></li>
<ul>
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">let response = pm.response.json();</span></li>
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">pm.globals.set("access_token", response.access_token);</span></li>
</ul>
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">To access this variable in some other request, just pass the access_token parameter as <b>{{access_token}}</b> as we have done something similar for dev_hostname.</span></li>
</span></ul>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
E.g. </span></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Azo86ewkfog/XZ-FIZePt2I/AAAAAAAAJ2Y/Jtc03Yvr_54V4awbbc1wRq8SVpRFA44tQCEwYBhgL/s1600/8.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="775" data-original-width="1396" height="354" src="https://1.bp.blogspot.com/-Azo86ewkfog/XZ-FIZePt2I/AAAAAAAAJ2Y/Jtc03Yvr_54V4awbbc1wRq8SVpRFA44tQCEwYBhgL/s640/8.JPG" width="640" /></span></a></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span>
<h3>
<ul style="text-align: left;">
<li><span style="color: #20124d; font-family: Arial, Helvetica, sans-serif; font-size: large;"><img border="0" src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image016.jpg" />How to pass the path variable dynamically</span></li>
</ul>
</h3>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">I guess this is one of the major mistakes I have seen people doing it i.e. passing hardcoded path variable in the URL request<br /><br />The below diagram will show you the correct way of passing it. Using this, you can update params value very easily.<br /><br /><a href="http://hostname/users/:userId">http://hostname/users/:userId</a><br /><br />To edit the path variable, click on Params to see it already entered as the key. Update the value as needed.<br /><br /><img border="0" src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image018.jpg" /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><a href="https://1.bp.blogspot.com/-LiRL-Zfz8CI/XZ-FImS0y8I/AAAAAAAAJ2s/SJ-TipV4edg58-YtWZJXtLL5Q8x-16n_ACEwYBhgL/s1600/9.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="587" data-original-width="1480" height="253" src="https://1.bp.blogspot.com/-LiRL-Zfz8CI/XZ-FImS0y8I/AAAAAAAAJ2s/SJ-TipV4edg58-YtWZJXtLL5Q8x-16n_ACEwYBhgL/s640/9.JPG" width="640" /></a></span></div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
</span><br />
<h3>
<ul style="text-align: left;">
<li><span style="color: #20124d; font-family: Arial, Helvetica, sans-serif; font-size: large;">Save custom headers</span></li>
</ul>
</h3>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">You can save commonly used headers together in a header preset. Under the Headers tab, you can add a header preset to your request when you select "Manage Presets" from the Presets dropdown on the right. </span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-2FCDt4pQ1uw/XZ-FFS54CYI/AAAAAAAAJ2k/XOOTpu5fHpwgRdnBWiUAgrfDENJIJo1bACEwYBhgL/s1600/10.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Arial, Helvetica, sans-serif;"><img border="0" data-original-height="708" data-original-width="1403" height="322" src="https://1.bp.blogspot.com/-2FCDt4pQ1uw/XZ-FFS54CYI/AAAAAAAAJ2k/XOOTpu5fHpwgRdnBWiUAgrfDENJIJo1bACEwYBhgL/s640/10.JPG" width="640" /></span></a></div>
<div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /><img border="0" src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image020.jpg" /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><a href="https://1.bp.blogspot.com/-jPlaAaOur_M/XZ-FFJnaX3I/AAAAAAAAJ2o/RN1fAtySiIIgGyz5WbPotkey6inVkTWeACEwYBhgL/s1600/11.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="773" data-original-width="1474" height="334" src="https://1.bp.blogspot.com/-jPlaAaOur_M/XZ-FFJnaX3I/AAAAAAAAJ2o/RN1fAtySiIIgGyz5WbPotkey6inVkTWeACEwYBhgL/s640/11.JPG" width="640" /></a></span></div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">
</span><br />
<h3>
<span style="color: #20124d; font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></h3>
<h3>
<ul style="text-align: left;">
<li><span style="color: #20124d; font-family: Arial, Helvetica, sans-serif; font-size: large;">Check all request/response send to API</span></li>
</ul>
</h3>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">Goto View-> Show Postman Console<br /><br /><img border="0" src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image024.jpg" /></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><a href="https://1.bp.blogspot.com/-E804Dq7tNm8/XZ-FGQmOZiI/AAAAAAAAJ2Q/MZWJmRanKCICbSnklRGziG0moxwNNGr3gCEwYBhgL/s1600/12.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="797" data-original-width="928" height="548" src="https://1.bp.blogspot.com/-E804Dq7tNm8/XZ-FGQmOZiI/AAAAAAAAJ2Q/MZWJmRanKCICbSnklRGziG0moxwNNGr3gCEwYBhgL/s640/12.JPG" width="640" /></a></span></div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
</div>
<div style="text-align: left;">
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-52959772378333796612019-09-08T12:58:00.000+05:302019-09-08T12:58:32.734+05:30Spring Boot Tutorial<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Prerequisite: </b>Basic knowledge of Spring boot application<br /><br />I am working on a series of implementing frameworks with Spring boot application but not getting enough time to blog it and post it here or on my LinkedIn profile.<br /><br />So, I have started uploading my work on my <a href="https://github.com/abdulwaheed18" target="_blank">GitHub </a>repository from where it can be downloaded easily. I tried my best to add short notes for each annotation/configuration/properties in README and even I have uploaded a few screenshots to understand in a more better way. <br /><br />Try it out and Please do let me know in case of any confusion.</span><div>
<ol style="text-align: left;">
<li><span style="font-family: Trebuchet MS, sans-serif;"><a href="https://github.com/abdulwaheed18/spring-boot-tutorial" target="_blank">Spring Boot Actuator</a></span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;"><a href="https://github.com/abdulwaheed18/spring-boot-tutorial" target="_blank">Spring Boot Ehcache</a></span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;"><a href="https://github.com/abdulwaheed18/spring-boot-tutorial" target="_blank">Spring Boot Swagger</a></span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;"><a href="https://github.com/abdulwaheed18/spring-boot-tutorial" target="_blank">Spring Boot JPA</a></span></li>
</ol>
<div>
<br /></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Will keep uploading with others framework as well.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Feedback is also most welcome.<br /><br />Thank you.<br />Happy Learning!</span></div>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com2tag:blogger.com,1999:blog-630363181754150660.post-51617402948988274032019-08-29T23:18:00.001+05:302019-08-29T23:18:39.560+05:30MicroServices: Spring cloud ribbon with Discovery Server<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: large;">In this article, I am going to share my knowledge on <b>Spring Cloud Ribbon </b>and how can we use Ribbon with RestTemplate as well as with Feign Client. We will also see how Enabling discovery Sever will improve the scalability of Microservice.<br /><br />Before jumping into Spring Cloud, I am assuming you must be having knowledge of Eureka Server, Feign Client, and Client-Side load balancer. If not then read my below blog before jumping to Spring Cloud ribbon. Also, I am going to use my existing code to implement <b>Ribbon</b>. <br /><br />URLs: <br /><ul style="text-align: left;">
<li><span style="font-size: large;"><a href="http://www.waheedtechblog.com/2019/08/declarative-rest-client-feign.html">Declarative REST Client: Feign</a> </span></li>
<li><span style="font-size: large;"><a href="http://www.waheedtechblog.com/2019/08/microservices-service-registry-and.html">Microservices: Service Registry and Discovery</a> </span></li>
<li><span style="font-size: large;"><a href="http://www.waheedtechblog.com/2019/06/netflix-hystrix-circuit-breaker.html">Netflix Hystrix Circuit Breaker</a> </span></li>
</ul>
In my previous blog, I have already talked about the Eureka Server and how other applications are taking advantages of Eureka Server to fetch the host/port of client application. <br /><br />We have seen that three microservices application are up and running i.e. <br /><ul style="text-align: left;">
<li><span style="font-size: large;">Discovery Server </span></li>
<li><span style="font-size: large;">Product Service </span></li>
<li><span style="font-size: large;">Price Service </span></li>
</ul>
Where Product and Price service will register themselves to Discovery Server and Product-service will always communicate to Discovery Server to get the exact location of Price-service and then only it will talk to the price-service application. <br /><br />Imagine there is a high load on the price-service application and to handle it, we have started two more instances of price-service.<br /><br /><ul style="text-align: left;">
<li><span style="font-size: large;">How will you make sure your product-service should talk to all three instances of price-service and divides the load equally to each server?</span></li>
<li><span style="font-size: large;">How will you manage the heartbeat of the application so that product-service should not hit INACTIVE instance of price-service which just got shut down because of some internal reason?</span></li>
<li><span style="font-size: large;">How will you get to know how many instances are up and running of price-service?</span></li>
</ul>
For all the question, there is only answer which is <b>Netflix Cloud Ribbon.</b> It's a Spring cloud library which primarily provides <b>client-side load balancing</b> algorithms. <br /><br />let's implement it and see how it can solve our problem.<br /><br />Add below dependency to product-server pom.xml file as it is the one which is going to consume price-service API.<br /><br /><div style="text-align: justify;">
<span style="color: #0b5394;"><dependency></span></div>
<div style="text-align: justify;">
<span style="color: #0b5394;"><groupId>org.springframework.cloud</groupId></span></div>
<div style="text-align: justify;">
<span style="color: #0b5394;"><artifactId>spring-cloud-starter-ribbon</artifactId></span></div>
<div style="text-align: justify;">
<span style="color: #0b5394;"></dependency></span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<br /><b>Case 1: Ribbon + Eureka Server + RestTemplate</b><br /><br />As our application is already acting as Eureka Client and using RestTemplate to fetch price record. Let's just add <b>@LoadBalanced </b>annotation to RestTemplate to enables Ribbon functionality. <br /><br />It will allow the product-service application to use price-service as the address of price-service application and will discover the host/port of all instances of price-service from discovery-server.<br /><br /><a href="https://1.bp.blogspot.com/-1poYneMo6Ko/XWf33IqhTVI/AAAAAAAAJuU/__qs12J4TUAnztqEBXbvfuvHQusjhU26gCLcBGAs/s1600/product-server.PNG"><img border="0" src="https://1.bp.blogspot.com/-1poYneMo6Ko/XWf33IqhTVI/AAAAAAAAJuU/__qs12J4TUAnztqEBXbvfuvHQusjhU26gCLcBGAs/s640/product-server.PNG" /></a><br /><b><br />Note:</b><br />@EnableCircuitBreaker <-> Used to enable Netflix Hystrix<br />@EnableHystrixDashboard <-> Used to check circuit state on Dashboard.<br />@EnableFeignClients <-> To enable feign client (Needed for case 2 scenario)<br /><br />Start discovery-server, product-service and start two instances of price-service. You can do it easily by just overriding port number under Eclipse <b>Run As</b> Configuration.<br /><a href="https://1.bp.blogspot.com/-6JjR-JhL3hQ/XWf6xioyAcI/AAAAAAAAJug/Z-1k0ewLl1wj2MBUT2Aiay2ZohQze5S3QCLcBGAs/s1600/price-server-port.PNG"><img border="0" src="https://1.bp.blogspot.com/-6JjR-JhL3hQ/XWf6xioyAcI/AAAAAAAAJug/Z-1k0ewLl1wj2MBUT2Aiay2ZohQze5S3QCLcBGAs/s640/price-server-port.PNG" /></a><br /><br /><br />Let's confirm it, whether all the instances are up and running or not by hitting discovery-server URL (<a href="http://localhost:8761/">http://localhost:8761/</a>)<br /><br /><a href="https://1.bp.blogspot.com/-q4t3KDaaONc/XWf7edFSaHI/AAAAAAAAJuo/JuWN8YoeUHQYuEffKOZA5Ykwro81ZcnCQCLcBGAs/s1600/discovery-List.PNG"><img border="0" src="https://1.bp.blogspot.com/-q4t3KDaaONc/XWf7edFSaHI/AAAAAAAAJuo/JuWN8YoeUHQYuEffKOZA5Ykwro81ZcnCQCLcBGAs/s640/discovery-List.PNG" /></a><br /><br />Now hit product-service URL multiple times from the browser and then go and check both the price-service logs. you will observe that few requests are coming to one instance and others on second one.<br /><br /><a href="https://1.bp.blogspot.com/-y1_yfP81C0A/XWf9a1daJQI/AAAAAAAAJu0/A74bHPyKCysK14oELxgLyRNTK-WzrySgQCLcBGAs/s1600/product-api.PNG"><img border="0" src="https://1.bp.blogspot.com/-y1_yfP81C0A/XWf9a1daJQI/AAAAAAAAJu0/A74bHPyKCysK14oELxgLyRNTK-WzrySgQCLcBGAs/s640/product-api.PNG" /></a><br /><br /><b>Great!</b> Netflix Cloud Ribbon is successfully implemented and working absolutely fine.<br /><br />If you start another price-service instance and hit the product-service URL again then you will find the request logs in the third instance too without doing any modification/configuration to any files.</span><div>
<span style="font-size: large;"><br /><br /><b>Case 2: Ribbon + Eureka Server + Feign Client</b><br /><br />If you are not aware of the feign client then you can read my blog <a href="http://www.waheedtechblog.com/2019/08/declarative-rest-client-feign.html">here</a>.<br /><br />I'll just talk about Ribbon Integration with existing FeignClient application assuming you are already aware of Feign Client and implemented it.<br /><br />In product-service application, I have already exposed another Endpoint (<span style="color: #0b5394;">http://localhost:7001/products/feign/1</span>) which consume price-service API using Feign Client. <br /><br />To enable Netflix Ribbon, Add <b>@RibbonClient</b> annotation to the feighClient interface and pass your consuming service name (price-service).<br /><br /><a href="https://1.bp.blogspot.com/-bpTVxaj-j4c/XWgAEskdCBI/AAAAAAAAJvA/njYnX8kQduYTiwBlSQGCsvC0ThiCiGioACLcBGAs/s1600/FeignClient.PNG"><img border="0" src="https://1.bp.blogspot.com/-bpTVxaj-j4c/XWgAEskdCBI/AAAAAAAAJvA/njYnX8kQduYTiwBlSQGCsvC0ThiCiGioACLcBGAs/s640/FeignClient.PNG" /></a><br /><br />Now restart your application and hit new endpoint. you will observe that the requests are distributed to all the instances of price-service.<br /><br /><b>Case 3: Ribbon + (RestTemaple/FeignClient) + NO Eureka Server</b><br /><br /><br />Can we use <b>Netflix ribbon</b> without integrating Eureka Server, The answer is YES but it would not be a good design. So, I would not recommend it.<br /><br />When your application is not integrated with Eureka Server, in that case you have to list down all the address manually to properties file.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Remove <b>@RibbonClients</b> annotation.<br />Add below entry to your application.properties file under </span><span style="font-size: large;">product-service.</span><span style="font-size: large;"><br /><br /><span style="color: #38761d;">#Enable this property if you are not using Eureka Server</span><br /><span style="color: #0b5394;">price-service.ribbon.listOfServers=http://localhost:8002,http://localhost:7002</span><br /><br /> Imagine there are 1000 instances of price-services are up and running so we have to add all the instances manually. It could be a nightmare if we have to do it. :)<br /><br />That's all for Netflix Ribbon now and do let me know if you have any confusion/query or you think I am not right somewhere. Please feel free to comment. Thank you!<br /><br />As usual, you can download the spring-boot-microservices from <a href="https://github.com/abdulwaheed18/spring-boot-microservices">GITHUB</a>.</span><span style="font-size: medium;">
</span></div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com3tag:blogger.com,1999:blog-630363181754150660.post-31592555720431799742019-08-18T18:15:00.000+05:302019-08-18T18:15:57.062+05:30Declarative REST Client: Feign<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<span style="font-size: large;"><br /></span></div>
<span style="font-size: large;">We already know that how microservices communicate with each other using RestTemplate. In this blog, we will see that how this can happen using Feign Client as well. </span><div>
<span style="font-size: large;"><br /></span><div>
<h3 style="text-align: left;">
<span style="font-size: large;">What is a Feign Client? </span></h3>
<span style="font-size: large;">Feign is an abstraction over REST based call. It makes writing web service clients easier. It Is as easy as creating interface and then annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations. It also supports pluggable encoders and decoders and has supports for Spring MVC annotation. <br /><br />Using Feign, microservices can easily communicate with each other and developers don't have to bother about REST internal details and can only concentrate on business logic. <br />Implementation.<br /><br />I am going to use my previous applications to demonstrate the working of Feign Client. So before starting feign-client application. Make sure all the below three applications are already up and running. </span></div>
<span style="font-size: large;"><ul style="text-align: left;">
<li><span style="font-size: large;"><a href="https://github.com/abdulwaheed18/spring-boot-microservices/tree/master/discovery-server" target="_blank">Discovery-server</a></span></li>
<li><span style="font-size: large;"><a href="https://github.com/abdulwaheed18/spring-boot-microservices/tree/master/product-service" target="_blank">Product-server </a></span></li>
<li><span style="font-size: large;"><a href="https://github.com/abdulwaheed18/spring-boot-microservices/tree/master/price-service" target="_blank">Price-server</a></span></li>
</ul>
</span><h3 style="text-align: left;">
<span style="font-size: large;">Feign Client Implementation </span></h3>
<span style="font-size: large;"><ul style="text-align: left;">
<li><span style="font-size: large;">Create a spring boot application and add Feign starter dependency to our pom.xml file.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-2fqvbzun54w/XVlB6Y7L_RI/AAAAAAAAJoc/5QzNXprZBb43sIzyAWLMfp1JpjcRg4fIwCLcBGAs/s1600/pom.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="131" data-original-width="768" height="108" src="https://1.bp.blogspot.com/-2fqvbzun54w/XVlB6Y7L_RI/AAAAAAAAJoc/5QzNXprZBb43sIzyAWLMfp1JpjcRg4fIwCLcBGAs/s640/pom.PNG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>Add @EnableFeignClients annotation. With this annotation, we enable component scanning for interfaces that declare they are Feign clients. </li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-_UDAP6VeO7A/XVlCLmnF0II/AAAAAAAAJok/dX2Sq713pP8hAe_X_Y1ySRlKQhVjjudbwCLcBGAs/s1600/Mainclass.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="244" data-original-width="716" height="218" src="https://1.bp.blogspot.com/-_UDAP6VeO7A/XVlCLmnF0II/AAAAAAAAJok/dX2Sq713pP8hAe_X_Y1ySRlKQhVjjudbwCLcBGAs/s640/Mainclass.PNG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>Declare a Feign client using the @FeignClient annotation.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-K6n4vJ_xkHA/XVlCVJv2VBI/AAAAAAAAJoo/qe_tbfNcutYWSOCz-Ll-xP5i5W_d3E2dwCLcBGAs/s1600/feignClient.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="220" data-original-width="1013" height="138" src="https://1.bp.blogspot.com/-K6n4vJ_xkHA/XVlCVJv2VBI/AAAAAAAAJoo/qe_tbfNcutYWSOCz-Ll-xP5i5W_d3E2dwCLcBGAs/s640/feignClient.PNG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>Either name or url must be passed under @FeignClient annotation. If name attribute present then it will fetch the service location from service registry and then hit product-service and in case of url, it will directly hit the application to get the data from product-service. In case of both present then it will always first check for the name attribute. </li>
<li>Use Spring Web annotations to declare the APIs that we want to reach out to.</li>
</ul>
</span><span style="font-size: large;"><b>Note:</b> If your application is not registered with service registry then directly use url attribute to get the data but I would recommend to use name attribute and to use name attribute, make sure your application is connecting to Eureka server to get the service location. </span><span style="font-size: large;"><br /><br />Read my <a href="http://www.waheedtechblog.com/2019/08/microservices-service-registry-and.html" target="_blank">blog </a>to understand on how to add support for Eureka Client to your application. <br /><br />Now start your application and you should be able to fetch product-service from feign-client. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-MbhXoH851fo/XVlDLJi2ztI/AAAAAAAAJo4/zDcqAniNUuM23d1WJDIFp0hYvANKysBzwCLcBGAs/s1600/response.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="153" data-original-width="1078" height="90" src="https://1.bp.blogspot.com/-MbhXoH851fo/XVlDLJi2ztI/AAAAAAAAJo4/zDcqAniNUuM23d1WJDIFp0hYvANKysBzwCLcBGAs/s640/response.PNG" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">You can download the source code from here. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<h3 style="text-align: left;">
<span style="font-size: large;">Custom Configuration</span></h3>
<span style="font-size: large;">Feign Client also support for Custom configuration changes like telling Feign to use OkHttpClient instead of the default one in order to support HTTP/2. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">Let’s go deep down to check how can we customize Feign Client. <br /><br />There are two ways to configure it i.e. using properties file or override them using a @Configuration class, which we then need to add to the FeignClient annotation. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<h4 style="text-align: left;">
<span style="font-size: large;">Properties file:</span></h4>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-AFDjz5q3YHc/XVlEL85aqvI/AAAAAAAAJpU/w-92FuZ1Bo4g5zc94EK6PEEMxwFMJprnwCLcBGAs/s1600/properties.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="153" data-original-width="655" height="148" src="https://1.bp.blogspot.com/-AFDjz5q3YHc/XVlEL85aqvI/AAAAAAAAJpU/w-92FuZ1Bo4g5zc94EK6PEEMxwFMJprnwCLcBGAs/s640/properties.PNG" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<h4 style="text-align: left;">
<span style="font-size: large;">Using @Configuration</span></h4>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-m69sEMkkH5o/XVlDnyWwN8I/AAAAAAAAJpA/naNpqjBBmucegDyZxruD9-uYHiGdkkdCwCLcBGAs/s1600/CustomConfig.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="438" data-original-width="595" height="470" src="https://1.bp.blogspot.com/-m69sEMkkH5o/XVlDnyWwN8I/AAAAAAAAJpA/naNpqjBBmucegDyZxruD9-uYHiGdkkdCwCLcBGAs/s640/CustomConfig.PNG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-X8Azd3031YY/XVlD04hAuYI/AAAAAAAAJpE/d2syhb6mN70MVLIa9aEglpAjOfi1htRggCLcBGAs/s1600/ConfigChanges.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="236" data-original-width="1144" height="132" src="https://1.bp.blogspot.com/-X8Azd3031YY/XVlD04hAuYI/AAAAAAAAJpE/d2syhb6mN70MVLIa9aEglpAjOfi1htRggCLcBGAs/s640/ConfigChanges.PNG" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<h3 style="text-align: left;">
<span style="font-size: large;">Logging: </span></h3>
<div>
<span style="font-size: large;">By default, a logger gets created for each </span><span style="font-size: large;">Feign </span><span style="font-size: large;">Client and to enable it, we have to declare it in the application.properties file using the package name of the client interface.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;">logging.level.com.com.waheedtechblog.feignclient=DEBUG</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"><div>
There are four logging levels to choose from:</div>
<div>
<br /></div>
<div>
<b>NONE </b>– no logging, which is the default</div>
<div>
<b>BASIC </b>– log only the request method, URL, and response status</div>
<div>
<b>HEADERS </b>– log the basic information together with request and response headers</div>
<div>
<b>FULL </b>– log the body, headers, and metadata for both request and response</div>
<div>
<br /></div>
<div>
<h3 style="text-align: left;">
Handling Errors with Feign</h3>
<div>
By default, Feign’s default error handler, ErrorDecoder.default, always throws a FeignException.</div>
<div>
<br /></div>
<div>
To customize the Exception thrown, we can override it by writing our own Custom Error class and implements ErrorDecoder and declare this bean under @Configuration as we did earlier.</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ytN_YHB0LjU/XVlGTy6niQI/AAAAAAAAJpg/ZGI7TdiaSC0y05uXoITabW0S_faJIab8QCLcBGAs/s1600/ErrrorDecoder.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="383" data-original-width="657" height="372" src="https://1.bp.blogspot.com/-ytN_YHB0LjU/XVlGTy6niQI/AAAAAAAAJpg/ZGI7TdiaSC0y05uXoITabW0S_faJIab8QCLcBGAs/s640/ErrrorDecoder.PNG" width="640" /></a></div>
<div>
<br /></div>
<div>
<span style="background-color: white; color: #1b3b66; font-family: Calibri; font-size: medium;"><br /></span></div>
<div>
<span style="background-color: white; color: #1b3b66; font-family: Calibri; font-size: medium;">Spring-boot microservices can be downloaded from </span><a href="https://github.com/abdulwaheed18/spring-boot-microservices" style="background-color: white; color: #4d469c; cursor: pointer; font-family: Calibri; font-size: large; text-decoration-line: none;">GITHUB</a><br style="background-color: white; color: #1b3b66; font-family: Calibri; font-size: large;" /><br style="background-color: white; color: #1b3b66; font-family: Calibri; font-size: large;" /><span style="background-color: white; color: #1b3b66; font-family: Calibri; font-size: medium;">Happy Coding...!!!</span></div>
<div>
<div class="MsoNormal">
<br /></div>
<h4 style="text-align: left;">
Reference:</h4>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<a href="https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html">https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html</a><o:p></o:p></div>
</div>
</span></div>
<span style="font-size: large;"> <br /></span></div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-42729713060208309452019-08-18T14:48:00.002+05:302019-08-18T14:48:34.775+05:30Microservices: Service Registry and Discovery<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="font-family: inherit; font-size: large;">In my previous blog, I have already talked about Netflix Hystrix Circuit Breaker Microservices and explained it by creating two applications i.e. <b>Product Service</b> and <b>Price Service.</b><br />In this post, I’ll use both applications to explain what is the Service Registry and Discovery Server.</span><div>
<ul style="text-align: left;">
<li><a href="http://www.waheedtechblog.com/2019/06/circuit-breaker-and-microservices.html"><span style="font-size: large;">Circuit Breaker and Microservices Architecture</span></a></li>
</ul>
<ul style="text-align: left;">
<li><span style="font-size: large;"><a href="http://www.waheedtechblog.com/2019/06/netflix-hystrix-circuit-breaker.html">Netflix Hystrix Circuit Breaker</a> </span></li>
</ul>
<div>
<div>
<h3 style="text-align: left;">
<span style="font-family: inherit; font-size: large;">What is Service Registry and Discovery and why do we need it in the first place?</span></h3>
<span style="font-family: inherit; font-size: large;">In our monolithic application, mostly service invoke one another through language methods or procedure calls and even in traditional distributed system deployment, services run at fixed, well-known locations (hosts and ports) and so can easily call one another using HTTP/REST. Over here the network locations of service instances are relatively static.<br /><br />With the microservice architecture system, this is a much more difficult problem as service instances have dynamically assigned network locations. Service instances change dynamically because of auto-scaling, failure or upgrade. So, you can see that it’s not possible to hard code the locations (hosts and ports) of service instances in our application.<br /><br />Apart from that, most of the time we have to deploy the same instance on multiple hosts (E.g. During Big billions day sale where 1000’s of instances is running to support high demand) which will be again a tedious task for the load balancer to register and deregister itself for all these services.</span> <div>
<br /><h3 style="text-align: left;">
<span style="font-family: inherit; font-size: large;">What is Service Registry and Discovery?</span></h3>
<span style="font-family: inherit; font-size: large;">Service Registry is the server instance where all the service provider register itself when it starts up and deregisters itself when it leaves the system. The service instance’s registration is typically refreshed periodically using a heartbeat mechanism.</span></div>
<div>
<span style="font-family: inherit; font-size: large;"><br />Whenever a client has to communicate with other service instances, it has to first query to Service registry to get the network location and then uses a load-balancing algorithm to select one of the available service instances and invoke a request. </span></div>
<div>
<span style="font-family: inherit; font-size: large;"><br />The above instance discovery pattern is called a <b>Client-Side discovery pattern</b> and this can be easily implemented using <a href="https://github.com/Netflix/eureka">Netflix Eureka</a> as a Service Registry. It provides a REST API for managing service‑instance registration and for querying available instances.</span></div>
<div>
<span style="font-family: inherit; font-size: large;"><br />Netflix also provides <a href="https://github.com/Netflix/ribbon">Netflix Ribbon</a> which is an IPC client that works with Eureka to load balance requests across the available service instances.</span><br /><br /><h3 style="text-align: left;">
<span style="font-size: large;"><span style="font-family: inherit;">Implementation</span></span></h3>
<span style="font-size: large;">As we already have two microservices product-service and price-service and we know product-service is internally invoking price-service to get the price detail of the products. We will do minor changes with these two applications to support service registry.</span><div>
<br /></div>
<h4 style="text-align: left;">
<span style="font-size: large;">Discovery Server Implementation</span></h4>
<h4 style="text-align: left;">
<ul style="text-align: left;">
<li><span style="font-weight: normal;"><span style="font-size: large;">Create a spring boot application and Eureka Server starter dependency to your pom.xml file </span></span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-DopVIjb7tEQ/XVkTLaOMxzI/AAAAAAAAJno/nhctAKQXoogSEHZQnShDOD7NkWfLQOA3wCLcBGAs/s1600/pom.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="134" data-original-width="890" height="96" src="https://1.bp.blogspot.com/-DopVIjb7tEQ/XVkTLaOMxzI/AAAAAAAAJno/nhctAKQXoogSEHZQnShDOD7NkWfLQOA3wCLcBGAs/s640/pom.png" width="640" /></a></div>
<div>
<span style="font-weight: 400;"><br /></span></div>
</h4>
<span style="font-size: large;"><ul>
<li><span style="font-size: large;">Add <b>@EnableEurekaServer</b> annotation to Enable Eureka Server.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-mVcj2AsIkr0/XVkTIDoB6AI/AAAAAAAAJn8/h-q2KoXrOYIjMl7PwtbIb6zThhpdcB-wQCEwYBhgL/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="227" data-original-width="743" height="193" src="https://1.bp.blogspot.com/-mVcj2AsIkr0/XVkTIDoB6AI/AAAAAAAAJn8/h-q2KoXrOYIjMl7PwtbIb6zThhpdcB-wQCEwYBhgL/s640/Capture.PNG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<ul>
<li><span style="font-size: large;"><div class="separator" style="clear: both; text-align: center;">
<span style="text-align: left;">By default, Each Eureka Server is also a Eureka Client which needs at least one service URL to locate service registry. We have to disable this feature as we are creating single node Eureka Server. </span></div>
</span></li>
<li><div class="separator" style="clear: both; text-align: center;">
<span style="text-align: left;">A</span>dd below properties to application.properties file.</div>
</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-grv4rvF-zUM/XVkTJS0pZrI/AAAAAAAAJn0/gHtiUQY78jQviRgIUwbPoVNCWuY3e5KEwCEwYBhgL/s1600/DSapplicationprop.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="89" data-original-width="667" height="84" src="https://1.bp.blogspot.com/-grv4rvF-zUM/XVkTJS0pZrI/AAAAAAAAJn0/gHtiUQY78jQviRgIUwbPoVNCWuY3e5KEwCEwYBhgL/s640/DSapplicationprop.PNG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<br /></div>
<ul>
<li><div class="separator" style="clear: both; text-align: left;">
Now start the discovery-server application and access <a href="http://localhost:8761/">http://localhost:8761</a> which will display the UI similar to below screenshot. </div>
</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-qQ4cltGYmws/XVkUgluPG6I/AAAAAAAAJoQ/5Hna8F92YW0QeD-z_bX6jWZfEJvlAynugCLcBGAs/s1600/InkedDSDashboard_LI.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="806" data-original-width="1600" height="322" src="https://1.bp.blogspot.com/-qQ4cltGYmws/XVkUgluPG6I/AAAAAAAAJoQ/5Hna8F92YW0QeD-z_bX6jWZfEJvlAynugCLcBGAs/s640/InkedDSDashboard_LI.jpg" width="640" /></a></div>
<div style="text-align: left;">
<br /></div>
<ul>
<li><div class="separator" style="clear: both; text-align: left;">
As of now, no application is registered with the Eureka Server. </div>
</li>
</ul>
</span><h4 style="text-align: left;">
<span style="font-size: large;">2. Registering product-service and price-service to Eureka Clients</span></h4>
<span style="font-size: large;"><ul style="text-align: left;">
<li><span style="font-size: large;">Let’s make out product-service and price-service as Eureka Client which should register to Eureka Server itself on starts up.</span></li>
<li>Add Eureka Client dependency on both pom.xml files.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-EiLVJAOtu5E/XVkTJ3mEDoI/AAAAAAAAJn4/ya8-hN4pNLs7Gkw0stw7NFKG1g9qluSrACEwYBhgL/s1600/EurekaClient.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="147" data-original-width="777" height="120" src="https://1.bp.blogspot.com/-EiLVJAOtu5E/XVkTJ3mEDoI/AAAAAAAAJn4/ya8-hN4pNLs7Gkw0stw7NFKG1g9qluSrACEwYBhgL/s640/EurekaClient.PNG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>Configure <b>eureka.client.service-url.defaultZone</b> property in <b>application.properties</b> to automatically register with the Eureka Server. </li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-67B6ONHuZQk/XVkTKBF3AdI/AAAAAAAAJn8/PtsU-4YXNyAkZzos1tr5b7kZr_qzYtchwCEwYBhgL/s1600/EurekaClientApp.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="85" data-original-width="674" height="80" src="https://1.bp.blogspot.com/-67B6ONHuZQk/XVkTKBF3AdI/AAAAAAAAJn8/PtsU-4YXNyAkZzos1tr5b7kZr_qzYtchwCEwYBhgL/s640/EurekaClientApp.PNG" width="640" /></a></div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>Now start<b> product-service</b> and <b>price service</b> application and hit http://localhost:8761. We will see product-service and price-service is registered with <b>SERVICE ID</b> as <b>PRODUCT-SERVICE</b> and <b>PRICE-SERVICE</b> respectively. We can also notice the status as UP(1) which means the services are up and running and only one instance of product and price-service are running. </li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-KdG48oLpHDs/XVkTIdZNfRI/AAAAAAAAJoI/HtIOW-Aq1TseZ41aLUZR3v4I9wGQ-VJHwCEwYBhgL/s1600/DSInstanceRunning.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="207" data-original-width="1600" height="82" src="https://1.bp.blogspot.com/-KdG48oLpHDs/XVkTIdZNfRI/AAAAAAAAJoI/HtIOW-Aq1TseZ41aLUZR3v4I9wGQ-VJHwCEwYBhgL/s640/DSInstanceRunning.PNG" width="640" /></a></div>
<div>
<br /></div>
</span><h4 style="text-align: left;">
<span style="font-size: large;">3. Update hard code URL with application name in product-service and restart the application. </span></h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-QDAfNcPdohA/XVkTL9KLHWI/AAAAAAAAJoE/3_NBknSFE6cjcuVhWS7z39jW2J0RRwY-wCEwYBhgL/s1600/urlupdate.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="105" data-original-width="746" height="90" src="https://1.bp.blogspot.com/-QDAfNcPdohA/XVkTL9KLHWI/AAAAAAAAJoE/3_NBknSFE6cjcuVhWS7z39jW2J0RRwY-wCEwYBhgL/s640/urlupdate.PNG" width="640" /></a></div>
<div>
<br /></div>
<h4 style="text-align: left;">
<span style="font-size: large;">4. Now open browser and hit product URL and you will get the below response.</span></h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-QIYrnnzVfdw/XVkTLj6tE3I/AAAAAAAAJoI/qeedIgQyoDEQfB_XF7YEJV-mx-2VhoDTwCEwYBhgL/s1600/response.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="151" data-original-width="1014" height="94" src="https://1.bp.blogspot.com/-QIYrnnzVfdw/XVkTLj6tE3I/AAAAAAAAJoI/qeedIgQyoDEQfB_XF7YEJV-mx-2VhoDTwCEwYBhgL/s640/response.PNG" width="640" /></a></div>
<div>
<span style="font-size: large; font-weight: normal;"><br /></span></div>
<span style="font-size: large;"><b>Congratulation!!!</b> Our application is perfectly working with Discovery Service. </span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<span style="font-size: large;">Spring-boot microservices can be downloaded from <a href="https://github.com/abdulwaheed18/spring-boot-microservices">GITHUB</a><br /><br />Happy Coding...!!!</span></div>
</div>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com1tag:blogger.com,1999:blog-630363181754150660.post-674458998698779202019-06-16T21:59:00.001+05:302019-06-16T22:03:11.292+05:30Netflix Hystrix Circuit Breaker<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<h3 style="text-align: center;">
<span style="font-family: "verdana" , sans-serif; font-size: large;">Netflix Hystrix Circuit Breaker</span></h3>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br />In one of my <a href="http://www.waheedtechblog.com/2019/06/circuit-breaker-and-microservices.html" target="_blank">previous </a>blogs, I have already discussed the Circuit breaker pattern and its usage, Today, we will see how can we implement it in our application using <b>Spring Cloud Netflix Hystrix</b>. <br /><br />In this document, I’ll walk you through the process of applying circuit breakers to potentially-failing method calls using the Netflix Hystrix fault tolerance library. <br /><br /><a href="https://github.com/Netflix/Hystrix" target="_blank">Hystrix </a>is watching methods for failing calls to related services. If there is such a failure, it will open the circuit and forward the call to a fallback method. <br /><br />To understand it in a better way, I’ll take the same problem statement that I have already discussed in my previous blog i.e. E-commerce Portal. </span><br />
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-3xeb08pelmY/XQZcRdZnq2I/AAAAAAAAJHU/G3I3XPUNWBUIJWxS2AgYEdqAqSCm9T8_gCEwYBhgL/s1600/E-commerce%2BPortal.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="522" data-original-width="594" height="562" src="https://1.bp.blogspot.com/-3xeb08pelmY/XQZcRdZnq2I/AAAAAAAAJHU/G3I3XPUNWBUIJWxS2AgYEdqAqSCm9T8_gCEwYBhgL/s640/E-commerce%2BPortal.png" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br />I am assuming you must be aware of <b>Spring boot framework</b> as this implementation is completely based on it. <br /><br />As per problem statement, we need two applications i.e. <b>Product Service</b> & <b>Price Service</b> but in this tutorial, I’ll talk about just Product Service as Price Service is simple web application exposing a single API and you can clone it from <a href="https://github.com/abdulwaheed18/spring-boot-microservices/tree/master/price-service" target="_blank">GitHub</a>. <br /><br />I’ll talk about Product Service in which we will integrate Circuit breaker pattern and Cache Service implementation and internally, it will invoke Price Service to get the Price Detail. <br /><br /><b>Optional:</b> You can download the below project from <a href="https://github.com/abdulwaheed18/spring-boot-microservices" target="_blank">GitHub </a>or you can try it by creating a new one. I would recommend you to try it from scratch. <br /><br /><b>Product Service: </b><br /><br />Create Spring boot application and add below dependency to your pom.xml file. <br /><br /> </span><br />
<blockquote class="tr_bq">
<span style="color: #0b5394;"><span style="font-family: "verdana" , sans-serif;"> <!-- Optional. Application health monitor check --><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <dependency><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <groupId>org.springframework.boot</groupId><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <artifactId>spring-boot-starter-actuator</artifactId><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> </dependency><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <!-- Compulsory for circuit breaker implementation --><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <dependency><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <groupId>org.springframework.cloud</groupId><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> </dependency><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <!-- Optional. Dashboard in case you want to see the circuit state UI --><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <dependency><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <groupId>org.springframework.cloud</groupId><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId><br /> </span><span style="font-family: "verdana" , sans-serif;"><br /></span><span style="font-family: "verdana" , sans-serif;"> </dependency> </span></span></blockquote>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /><br />To enable Circuit Breaker in spring boot application, add <b>@EnableCircuitBreaker</b> annotation on product-service entry-point class. </span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-TcFhAxuzJQ0/XQZiUSRSzcI/AAAAAAAAJHg/GA8RllLZOhsCDWd3D70XIgrnOe1Mu-JBQCLcBGAs/s1600/productservicemainclass.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="485" data-original-width="774" height="400" src="https://1.bp.blogspot.com/-TcFhAxuzJQ0/XQZiUSRSzcI/AAAAAAAAJHg/GA8RllLZOhsCDWd3D70XIgrnOe1Mu-JBQCLcBGAs/s640/productservicemainclass.PNG" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /><br />Now use <b>@HystrixCommand</b> annotation on themethod we want to apply timeout and fallback method. <br /><br />I have annotated <b>@HystrixCommand(fallbackMethod = “getProductDetailFromCache”)</b> on <b>getProduct(String Id)</b> so that if it doesn’t receive the response within the certain time limit or request get failed while calling price service API then fallback() should get called over here and fetch the price value from Cache Service. </span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;">Make sure, the fallback method should be defined in the same class and should have the same signature.</span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-fHvkmfHOxuQ/XQZi0-OmPFI/AAAAAAAAJHo/pbvTfmT282EyLmtnm-lkFRdbIqbV-USiACLcBGAs/s1600/productServiceHystrixmethod.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="619" data-original-width="1092" height="362" src="https://1.bp.blogspot.com/-fHvkmfHOxuQ/XQZi0-OmPFI/AAAAAAAAJHo/pbvTfmT282EyLmtnm-lkFRdbIqbV-USiACLcBGAs/s640/productServiceHystrixmethod.PNG" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br />We can customize the <b>@HystrixCommand</b> default behavior by configuring properties using <b>@HystrixProperty</b> annotations. Will check in depth in another blog. </span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;">Add RestController class and other required class as per source code present in GitHub.</span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;">Add server.port to the <b>application.properties</b> file.</span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;">Start both applications and try to fetch the product Detail. In our case, our product-service app URL is:</span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><b>http://localhost:7001/products/1</b></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-9kSWSCK1myY/XQZkUKVkbcI/AAAAAAAAJH0/Yrm_sLVF-UwZ3Lz11uiCHOPG9KX_66oRACLcBGAs/s1600/productrestId1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="205" data-original-width="1035" height="124" src="https://1.bp.blogspot.com/-9kSWSCK1myY/XQZkUKVkbcI/AAAAAAAAJH0/Yrm_sLVF-UwZ3Lz11uiCHOPG9KX_66oRACLcBGAs/s640/productrestId1.PNG" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br />Now try to fetch product which does not exist</span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-nj8Ca8yEmIM/XQZkUU18wvI/AAAAAAAAJIA/O0xi3cy3fiAsPPf-iB87TURPmDCaCmkIQCEwYBhgL/s1600/productNotFound.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="224" data-original-width="926" height="153" src="https://1.bp.blogspot.com/-nj8Ca8yEmIM/XQZkUU18wvI/AAAAAAAAJIA/O0xi3cy3fiAsPPf-iB87TURPmDCaCmkIQCEwYBhgL/s640/productNotFound.PNG" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br />You will observe that over here circuit breaker is still in the <b>closed </b>state even after the exception. </span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;">Why? The reason is that </span><span style="font-family: "verdana" , sans-serif; font-size: large;">we have added </span><span style="font-family: "verdana" , sans-serif; font-size: large;"> <b>ignoreExceptions = { ProductNotFoundException.class } </b>to <b>@HystrixCommand </b>so that it should not trip circuit if the product is not present.</span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;">Now, Stop the <b>price-service</b> application and hit the product URL again:</span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-9kSWSCK1myY/XQZkUKVkbcI/AAAAAAAAJH8/FxVm5r9-SqcoAUyTOJ4uUefBtKGKuh-1QCEwYBhgL/s1600/productrestId1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="205" data-original-width="1035" height="126" src="https://1.bp.blogspot.com/-9kSWSCK1myY/XQZkUKVkbcI/AAAAAAAAJH8/FxVm5r9-SqcoAUyTOJ4uUefBtKGKuh-1QCEwYBhgL/s640/productrestId1.PNG" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><b>Check the log:</b></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><b><br /></b></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-_1pAd5IGLFk/XQZmA-uRKZI/AAAAAAAAJII/YTwjua-zTvQTnd9PcfqCUdW5JF4LvW2fgCLcBGAs/s1600/CircuitOpen.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="64" data-original-width="1112" height="36" src="https://1.bp.blogspot.com/-_1pAd5IGLFk/XQZmA-uRKZI/AAAAAAAAJII/YTwjua-zTvQTnd9PcfqCUdW5JF4LvW2fgCLcBGAs/s640/CircuitOpen.PNG" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;">Congratulations! Our application is working as expected.</span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /><b>Monitoring Circuit Breakers using Hystrix Dashboard</b> <br /><br />Hystrix comes with a decent dashboard where we can monitor the status of Hystrix commands <br /><br />To enable it, Add Hystrix dashboard dependency to the pom.xml file </span></div>
<div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "verdana" , sans-serif;"></span><br />
<div>
<span style="font-family: "verdana" , sans-serif;"><span style="color: #0b5394;"><!-- Optional. Application health monitor check --></span></span></div>
<span style="font-family: "verdana" , sans-serif;">
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span><dependency></span></div>
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span><groupId>org.springframework.boot</groupId></span></div>
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span><artifactId>spring-boot-starter-actuator</artifactId></span></div>
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span></dependency></span></div>
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span><!-- Optional. Dashboard in case you want to see the circuit state UI --></span></div>
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span><dependency></span></div>
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span><groupId>org.springframework.cloud</groupId></span></div>
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></span></div>
<div>
<span style="color: #0b5394;"><span style="white-space: pre;"> </span></dependency></span></div>
<span style="color: #0b5394;"><br /></span><br /><span style="font-size: large;">Add <b>@EnableHystrixDashboard</b> annotation on the entry point class </span><br /><br /><span style="font-size: large;">Add <b>management.endpoints.web.exposure.include=hystrix.stream</b> to application.properties file. </span><br /><br /> <br /><br /><span style="font-size: large;">Start the product-service application and then go to </span><a href="http://localhost:port/hystrix" style="font-size: x-large;">http://localhost:port/hystrix</a><span style="font-size: large;"> to view the dashboard. </span></span></div>
<div>
<span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;"><br /></span></span></div>
<div>
<span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-yGfMNEeZVoY/XQZm1OX5hdI/AAAAAAAAJIQ/E2UF_l_FgRkKljyQ1JDf7qsbN_MbakL0QCLcBGAs/s1600/HystrixDashboard.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="847" data-original-width="1553" height="348" src="https://1.bp.blogspot.com/-yGfMNEeZVoY/XQZm1OX5hdI/AAAAAAAAJIQ/E2UF_l_FgRkKljyQ1JDf7qsbN_MbakL0QCLcBGAs/s640/HystrixDashboard.PNG" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif;"><br /><span style="font-size: large;">In Hystrix Dashboard home page enter </span><a href="http://localhost:8181/actuator/hystrix.stream" style="font-size: x-large;">http://localhost:7001/actuator/hystrix.stream</a><span style="font-size: large;"> as stream URL and give Product Service as Title and click on Monitor Stream button. </span></span></div>
<div>
<span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-rkCr-YItPYI/XQZnSMf7_fI/AAAAAAAAJIY/3bLIbUkcCawfEb5EdLKg2G1EAqs-dcw4gCLcBGAs/s1600/HystrixDashboard.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="821" data-original-width="1520" height="344" src="https://1.bp.blogspot.com/-rkCr-YItPYI/XQZnSMf7_fI/AAAAAAAAJIY/3bLIbUkcCawfEb5EdLKg2G1EAqs-dcw4gCLcBGAs/s640/HystrixDashboard.PNG" width="640" /></a></div>
<div>
<span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;"><br /></span><br /> <br /><span style="font-size: large;">Now, we can see that the Circuit status along with how many calls succeed and how many failures occurred, etc. </span></span></div>
<div>
<span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-dfuHBP7wwBw/XQZnpyzEidI/AAAAAAAAJIg/VGFI1fm1ZYIcYvSL7-YsD7K9925n2tnLQCLcBGAs/s1600/HystrixMetric.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="644" data-original-width="884" height="466" src="https://1.bp.blogspot.com/-dfuHBP7wwBw/XQZnpyzEidI/AAAAAAAAJIg/VGFI1fm1ZYIcYvSL7-YsD7K9925n2tnLQCLcBGAs/s640/HystrixMetric.PNG" width="640" /></a></div>
<span style="font-family: "verdana" , sans-serif; font-size: large;"><br />Spring-boot microservices can be downloaded from <a href="https://github.com/abdulwaheed18/spring-boot-microservices">GITHUB</a><br /><br />Happy Coding...!!!</span><span style="font-family: "verdana" , sans-serif; font-size: large;"><b><br /></b></span><br />
<div>
<div>
<br /></div>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com8tag:blogger.com,1999:blog-630363181754150660.post-3227098344119904352019-06-15T22:53:00.001+05:302019-06-16T15:01:12.880+05:30Circuit Breaker and Microservices Architecture<div dir="ltr" style="text-align: left;" trbidi="on">
<div bis_size="{"x":16,"y":8,"w":653,"h":18,"abs_x":485,"abs_y":143}">
<br bis_size="{"x":16,"y":8,"w":0,"h":17,"abs_x":485,"abs_y":143}" /></div>
<div bis_size="{"x":16,"y":26,"w":653,"h":29,"abs_x":485,"abs_y":161}">
<span bis_size="{"x":16,"y":26,"w":0,"h":29,"abs_x":485,"abs_y":161}" style="font-family: 'verdana' , sans-serif; font-size: large;"><br bis_size="{"x":16,"y":26,"w":0,"h":29,"abs_x":485,"abs_y":161}" /></span></div>
<h3 bis_size="{"x":16,"y":73,"w":653,"h":29,"abs_x":485,"abs_y":208}" style="text-align: center;">
<span bis_size="{"x":24,"y":73,"w":635,"h":29,"abs_x":493,"abs_y":208}" style="font-family: 'verdana' , sans-serif; font-size: large;">
Circuit Breaker and Microservices Architecture </span></h3>
<span bis_size="{"x":16,"y":179,"w":653,"h":2690,"abs_x":485,"abs_y":314}" style="font-family: 'verdana' , sans-serif; font-size: large;">
<br bis_size="{"x":16,"y":121,"w":0,"h":29,"abs_x":485,"abs_y":256}" /><br bis_size="{"x":16,"y":150,"w":0,"h":29,"abs_x":485,"abs_y":285}" />In this article, I’ll talk about the <b bis_size="{"x":16,"y":179,"w":603,"h":58,"abs_x":485,"abs_y":314}">Circuit Breaker pattern</b> which is widely used in Microservices but before jumping to Circuit breaker design pattern or microservices. Let’s first understand the requirement so that you should know where we can use it in our application and Of Couse, How 😊<br bis_size="{"x":427,"y":350,"w":0,"h":0,"abs_x":896,"abs_y":485}" /><br bis_size="{"x":16,"y":356,"w":0,"h":29,"abs_x":485,"abs_y":491}" />Let’s understand it with the real scenario as It’s already June month and we know there are so many online summer sales is going to start where they will offer you a various type of deals on their products.<br bis_size="{"x":630,"y":496,"w":0,"h":0,"abs_x":1099,"abs_y":631}" /><br bis_size="{"x":16,"y":501,"w":0,"h":29,"abs_x":485,"abs_y":636}" />And as we know most of the online portal has upgraded their application arch from Monolithic design to Microservices like Amazon, Flipkart, Snapdeal and so on and with that their each service will be running as an independent micro-services in the cloud like Authentication Service using which a user can be logged in to the application, Product Detail Service, Billing Service, Price Service, Card Services, etc.<br bis_size="{"x":179,"y":786,"w":0,"h":0,"abs_x":648,"abs_y":921}" /><br bis_size="{"x":16,"y":791,"w":0,"h":29,"abs_x":485,"abs_y":926}" />Now just imagine the scenario where millions of users are doing online shopping on some online portal and because of load or some other technical issue, their price services goes down for some time. So, what will happen over here if a customer can’t order anything?<br bis_size="{"x":661,"y":960,"w":0,"h":0,"abs_x":1130,"abs_y":1095}" /><br bis_size="{"x":16,"y":965,"w":0,"h":29,"abs_x":485,"abs_y":1100}" /><b bis_size="{"x":16,"y":994,"w":413,"h":29,"abs_x":485,"abs_y":1129}">From a business point of view:</b> it will give the bad impact of the sales as well as it will also decrease sales. Right? <br bis_size="{"x":177,"y":1076,"w":0,"h":0,"abs_x":646,"abs_y":1211}" /><br bis_size="{"x":16,"y":1081,"w":0,"h":29,"abs_x":485,"abs_y":1216}" /><b bis_size="{"x":16,"y":1110,"w":425,"h":29,"abs_x":485,"abs_y":1245}">From a technical point of view: </b>All the request going to Price Service will fail eventually and failure in one part of the system might lead to cascading failures and all the future request will be blocked until the timeout expires and there are high chances that these blocked requests might hold critical system resources such as memory, threads, database connections and so on. Consequently, these resources could become exhausted, causing the failure of other possibly unrelated parts of the system that need to use the same resources.<br bis_size="{"x":468,"y":1424,"w":0,"h":0,"abs_x":937,"abs_y":1559}" /><br bis_size="{"x":16,"y":1429,"w":0,"h":29,"abs_x":485,"abs_y":1564}" /><b bis_size="{"x":16,"y":1458,"w":224,"h":29,"abs_x":485,"abs_y":1593}">How to solve it? </b><br bis_size="{"x":240,"y":1482,"w":0,"h":0,"abs_x":709,"abs_y":1617}" />One simple approach is to return the cached price if the price service goes down and the original price once the price system available.<br bis_size="{"x":404,"y":1569,"w":0,"h":0,"abs_x":873,"abs_y":1704}" /><br bis_size="{"x":16,"y":1574,"w":0,"h":29,"abs_x":485,"abs_y":1709}" /><b bis_size="{"x":16,"y":1603,"w":555,"h":29,"abs_x":485,"abs_y":1738}">How can we achieve the above solution? </b><br bis_size="{"x":571,"y":1627,"w":0,"h":0,"abs_x":1040,"abs_y":1762}" />We can achieve this approach easily by implementing a circuit breaker pattern that allows a fallback when one of the applications goes down.<br bis_size="{"x":436,"y":1714,"w":0,"h":0,"abs_x":905,"abs_y":1849}" /><br bis_size="{"x":16,"y":1719,"w":0,"h":29,"abs_x":485,"abs_y":1854}" />The concept of Circuit breaker is very similar to automatically operated electrical panel switches of our home which goes down after the fault detected (either an electrical storm or power surge) and can be reset (either manually or automatically) to resume normal operation after the fault is involved.<br bis_size="{"x":542,"y":1917,"w":0,"h":0,"abs_x":1011,"abs_y":2052}" /><br bis_size="{"x":16,"y":1922,"w":0,"h":29,"abs_x":485,"abs_y":2057}" />The Circuit breaker pattern helps to prevent such a catastrophic cascading failure across multiple systems. It allows us to build a fault-tolerant and resilient system that can survive gracefully when key services are either unavailable or have high latency.<br bis_size="{"x":644,"y":2091,"w":0,"h":0,"abs_x":1113,"abs_y":2226}" /><br bis_size="{"x":16,"y":2096,"w":0,"h":29,"abs_x":485,"abs_y":2231}" />The concept of circuit breaker is straightforward and has three distinct states:<br bis_size="{"x":317,"y":2178,"w":0,"h":0,"abs_x":786,"abs_y":2313}" /><ol bis_size="{"x":16,"y":2207,"w":653,"h":638,"abs_x":485,"abs_y":2342}" style="text-align: left;">
<li bis_size="{"x":56,"y":2207,"w":613,"h":203,"abs_x":525,"abs_y":2342}"><span bis_size="{"x":56,"y":2207,"w":613,"h":203,"abs_x":525,"abs_y":2342}" style="font-family: 'verdana' , sans-serif; font-size: large;"><b bis_size="{"x":56,"y":2207,"w":98,"h":29,"abs_x":525,"abs_y":2342}">Closed:</b> When everything is normal, the circuit breaker remains in the closed state and all calls pass through to the services according to its lifecycle until it encounters a failure and when the number of failures exceeds a predetermined threshold the breaker trips and the circuit breaker will change the state to the <b bis_size="{"x":394,"y":2381,"w":78,"h":29,"abs_x":863,"abs_y":2516}">Open </b>state.</span></li>
<li bis_size="{"x":56,"y":2410,"w":613,"h":116,"abs_x":525,"abs_y":2545}"><b bis_size="{"x":56,"y":2410,"w":88,"h":29,"abs_x":525,"abs_y":2545}">Open: </b>When the breaker in its open state then the request will not go the service but will acts as a backup plan like throwing error directly or in our case, get the response from the Cache service.</li>
<li bis_size="{"x":56,"y":2526,"w":613,"h":319,"abs_x":525,"abs_y":2661}"><span bis_size="{"x":56,"y":2526,"w":602,"h":319,"abs_x":525,"abs_y":2661}" style="font-family: 'verdana' , sans-serif; font-size: large;"><b bis_size="{"x":56,"y":2526,"w":145,"h":29,"abs_x":525,"abs_y":2661}">Half-Open:</b> A limited number of requests from the application are allowed to pass through and invoke the operation. If these requests are successful, it's assumed that the fault that was previously causing the failure has been fixed and the circuit breaker switches to the <b bis_size="{"x":476,"y":2671,"w":97,"h":29,"abs_x":945,"abs_y":2806}">Closed </b>state (the failure counter is reset). If any request fails, the circuit breaker assumes that the fault is still present so it reverts back to the <b bis_size="{"x":453,"y":2758,"w":78,"h":29,"abs_x":922,"abs_y":2893}">Open </b>state and restarts the timeout timer to give the system a further period of time to recover from the failure. </span></li>
</ol>
</span><div bis_size="{"x":16,"y":2869,"w":653,"h":0,"abs_x":485,"abs_y":3004}">
</div>
<div bis_size="{"x":16,"y":2869,"w":653,"h":970,"abs_x":485,"abs_y":3004}" style="text-align: left;">
<div bis_size="{"x":16,"y":2869,"w":653,"h":677,"abs_x":485,"abs_y":3004}">
<span bis_size="{"x":16,"y":3435,"w":640,"h":111,"abs_x":485,"abs_y":3570}" style="font-family: 'verdana' , sans-serif; font-size: large;"><br bis_size="{"x":16,"y":2869,"w":0,"h":29,"abs_x":485,"abs_y":3004}" /><a bis_size="{"x":16,"y":3435,"w":640,"h":29,"abs_x":485,"abs_y":3570}" href="https://1.bp.blogspot.com/-7lVb2NYFBz0/XQUnL6fGsII/AAAAAAAAJHI/BmlleeCxxQg1hTzBlF_Sn3MwU35vBnSrgCLcBGAs/s1600/E-commerce%2BPortal.png"><img bis_size="{"x":16,"y":2898,"w":640,"h":561,"abs_x":485,"abs_y":3033}" border="0" height="561" src="https://1.bp.blogspot.com/-7lVb2NYFBz0/XQUnL6fGsII/AAAAAAAAJHI/BmlleeCxxQg1hTzBlF_Sn3MwU35vBnSrgCLcBGAs/s640/E-commerce%2BPortal.png" width="640" /></a><br bis_size="{"x":656,"y":3459,"w":0,"h":0,"abs_x":1125,"abs_y":3594}" /><br bis_size="{"x":16,"y":3459,"w":0,"h":29,"abs_x":485,"abs_y":3594}" /><br bis_size="{"x":16,"y":3488,"w":0,"h":29,"abs_x":485,"abs_y":3623}" /><b bis_size="{"x":16,"y":3517,"w":167,"h":29,"abs_x":485,"abs_y":3652}">Advantages:</b> </span></div>
<ol bis_size="{"x":16,"y":3562,"w":653,"h":203,"abs_x":485,"abs_y":3697}" style="text-align: left;"><span bis_size="{"x":56,"y":3562,"w":613,"h":203,"abs_x":525,"abs_y":3697}" style="font-family: 'verdana' , sans-serif; font-size: large;">
<li bis_size="{"x":56,"y":3562,"w":613,"h":87,"abs_x":525,"abs_y":3697}"><span bis_size="{"x":56,"y":3562,"w":597,"h":87,"abs_x":525,"abs_y":3697}" style="font-family: 'verdana' , sans-serif; font-size: large;">Helps to add logic for a fault tolerant system like try to get the data from some other source or from the cache.</span></li>
<li bis_size="{"x":56,"y":3649,"w":613,"h":58,"abs_x":525,"abs_y":3784}"><span bis_size="{"x":56,"y":3649,"w":524,"h":58,"abs_x":525,"abs_y":3784}" style="font-family: 'verdana' , sans-serif; font-size: large;">Handle downtime and slowness of services gracefully</span></li>
<li bis_size="{"x":56,"y":3707,"w":613,"h":58,"abs_x":525,"abs_y":3842}"><span bis_size="{"x":56,"y":3707,"w":577,"h":58,"abs_x":525,"abs_y":3842}" style="font-family: 'verdana' , sans-serif; font-size: large;">It will switch back to the main service once the service is again available automatically.</span></li>
</span></ol>
<span bis_size="{"x":16,"y":3781,"w":653,"h":58,"abs_x":485,"abs_y":3916}" style="font-family: 'verdana' , sans-serif; font-size: large;">
<div bis_size="{"x":16,"y":3781,"w":653,"h":58,"abs_x":485,"abs_y":3916}">
<div bis_size="{"x":16,"y":3781,"w":653,"h":58,"abs_x":485,"abs_y":3916}">
In my next blog, I'll talk about how can we implement circuit pattern using Spring Boot.</div>
</div>
</span><div bis_size="{"x":16,"y":3839,"w":653,"h":0,"abs_x":485,"abs_y":3974}">
</div>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-11837586100076890682019-05-22T21:58:00.000+05:302019-05-22T21:59:09.471+05:30Installing Apache Kafka and Zookeeper on Windows<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<div class="MsoNormal">
<span style="font-size: 14pt;">In this article,
I’ll talk about how to Install, configure and start </span><a href="https://zookeeper.apache.org/" style="font-size: 14pt;">Apache Zookeeper</a><span style="font-size: 14pt;"> and </span><a href="https://kafka.apache.org/" style="font-size: 14pt;">Apache Kafka</a><span style="font-size: 14pt;"> Server on Windows OS.</span></div>
<h1>
Prerequisite<o:p></o:p></h1>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
</div>
<ul style="text-align: left;">
<li><span style="font-size: 14.0pt; line-height: 107%;">JRE running on your machine and path
must set to Environment Variable</span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Any Zip tool like <a href="https://www.7-zip.org/download.html">7-zip</a>, WinZip or WinRAR.</span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Download and Extract <a href="http://zookeeper.apache.org/releases.html#download">Apache Zookeeper</a> using
7-zip.</span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Download and Extract <a href="https://kafka.apache.org/downloads">Apache Kafka</a> using 7-zip</span></li>
</ul>
<br />
<span style="font-size: large;"><b>ZooKeeper Installation Instructions:</b></span><br />
<div class="MsoNormal">
<span style="color: #2f5496; font-family: "calibri light" , sans-serif; font-size: 16.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18.0pt;">
</div>
<ul style="text-align: left;">
<li><span style="font-size: 14.0pt; line-height: 107%;">Go to the <b>conf</b>
directory of your Zookeeper. For me its under D:\Softwares\apache-zookeeper-3.5.5</span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Copy and rename zoo_sample.cfg to zoo.cfg file.</span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">Open and Edit dataDIr=/tmp/zookeeper to dataDir=D:\Softwares\apache-zookeeper-3.5.5</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-88Z_y-xoKu0/XOV2O5_uSfI/AAAAAAAAI_M/KfbHEKWWQDgWlrSmX-VbafA9qUGrlcorgCLcBGAs/s1600/zookeeperConfig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="203" data-original-width="560" height="232" src="https://4.bp.blogspot.com/-88Z_y-xoKu0/XOV2O5_uSfI/AAAAAAAAI_M/KfbHEKWWQDgWlrSmX-VbafA9qUGrlcorgCLcBGAs/s640/zookeeperConfig.png" width="640" /></a></div>
<div>
<span style="font-size: 18.6667px;"><br /></span></div>
<ul style="text-align: left;">
<li><span style="font-size: 12.0pt; line-height: 107%;">Add entries in System Environment Variables</span></li>
<li><span style="font-size: 12.0pt; line-height: 107%;">ZOOKEEPER_HOME=D:\Softwares\apache-zookeeper-3.5.5</span></li>
<li><span style="font-size: 12.0pt; line-height: 107%;">Append D:\Softwares\apache-zookeeper-3.5.5\bin to PATH system
variable.</span></li>
<li><span style="font-size: 12.0pt; line-height: 107%;">Open command prompt and type zkserver to start the Zookeeper
application.</span></li>
<li><span style="font-size: 12pt;">You can easily edit the default port ( 2181) in zoo.cfg file.</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-DkrN6ZhVaQM/XOV2dqyGKVI/AAAAAAAAI_Q/aRBN0h3jcUw4hCeuFJEWDpmCmnm8daKkQCLcBGAs/s1600/zookeeperRunningInstance.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="470" data-original-width="1474" height="204" src="https://1.bp.blogspot.com/-DkrN6ZhVaQM/XOV2dqyGKVI/AAAAAAAAI_Q/aRBN0h3jcUw4hCeuFJEWDpmCmnm8daKkQCLcBGAs/s640/zookeeperRunningInstance.png" width="640" /></a></div>
<div>
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 18.0pt; mso-add-space: auto;">
<span style="font-size: 12.0pt; line-height: 107%;">Congratulations, ZooKeeper
is up and running on port 2181.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 18.0pt; mso-add-space: auto;">
<br />
<br /></div>
<span style="font-size: large;"><b>Installing Apache Kafka Instructions</b></span><br />
<ul style="text-align: left;">
<li><span style="font-size: large;">Please make sure that the Zookeeper instance is up and running before starting any kafka server.</span></li>
<li><span style="font-size: large;">Go to the Kafka Installation directory (D:\Softwares\apache-tomcat-8.5.37) and run below command.</span></li>
<li><span style="font-size: large;">.\bin\windows\kafka-server-start.bat .\config\server.properties</span></li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-IMz7kOZIV_o/XOV2sJ1TCWI/AAAAAAAAI_Y/9g44qsaaFvIQNJQKw1lAqko1wFIjz7ZJACLcBGAs/s1600/KafkaRunningInstance.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="488" data-original-width="1320" height="236" src="https://2.bp.blogspot.com/-IMz7kOZIV_o/XOV2sJ1TCWI/AAAAAAAAI_Y/9g44qsaaFvIQNJQKw1lAqko1wFIjz7ZJACLcBGAs/s640/KafkaRunningInstance.png" width="640" /></a></div>
<div>
<span style="font-size: large;"><br /></span></div>
<span style="font-size: large;">Congratulations, Apache kafka is up and running on port 9092</span><br />
<div class="MsoNormal">
<span style="color: #2f5496; font-family: "calibri light" , sans-serif; font-size: 16.0pt; line-height: 107%;"> </span><span style="color: #2f5496; font-family: "calibri light" , sans-serif; font-size: 16pt;"> </span><br />
<span style="color: #2f5496; font-family: "calibri light" , sans-serif; font-size: 16pt;"><br /></span></div>
<span style="font-size: large;"><b>Create Topic</b></span><br />
<div class="MsoNormal">
<span style="font-size: large; line-height: 107%;">To create a
topic, we need to run the kafka-topics script<o:p></o:p></span></div>
<span style="font-size: large;"></span><br />
<ul style="text-align: left;"><span style="font-size: large;">
<li><span style="font-size: large;">Go to Apache kafka installation directory and navigate to bin\windows folder (D:\Softwares\kafka_2.11-2.2.0\bin\windows).</span></li>
<li><span style="font-size: large;">Execute below command to create topic where <TOPIC_NAME> should be name of your topic</span></li>
<li><span style="font-size: large;">kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic <TOPIC_NAME></span></li>
</span></ul>
<span style="font-size: large;">
</span><br />
<div class="MsoListParagraphCxSpMiddle">
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-sVdTXDFNAys/XOV3CBe7KlI/AAAAAAAAI_k/pJDnpHQV4B4jtGpdzQheCG29cMywd6lmwCLcBGAs/s1600/createTopic.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="95" data-original-width="1016" height="58" src="https://2.bp.blogspot.com/-sVdTXDFNAys/XOV3CBe7KlI/AAAAAAAAI_k/pJDnpHQV4B4jtGpdzQheCG29cMywd6lmwCLcBGAs/s640/createTopic.png" width="640" /></a></div>
<br /></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 18.0pt; mso-add-space: auto;">
<!--[if gte vml 1]><v:shape id="Picture_x0020_4"
o:spid="_x0000_i1027" type="#_x0000_t75" style='width:451.2pt;height:54pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image006.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><span style="font-size: 12.0pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<span style="font-size: large;"><b>Create Producer</b></span><br />
<div class="MsoListParagraphCxSpFirst">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 0cm; mso-add-space: auto;">
<span style="font-size: 12.0pt; line-height: 107%;">Now the topic has been created, Lets
start a producer so that we can published some message against sales topic.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 54.0pt; mso-add-space: auto; mso-list: l1 level1 lfo4; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "symbol"; font-size: 12.0pt; line-height: 107%;">·<span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; line-height: normal;"> </span></span><!--[endif]--><span style="font-size: 12.0pt; line-height: 107%;">Go to Apache kafka installation directory
and navigate to bin\windows folder (D:\Softwares\kafka_2.11-2.2.0\bin\windows).</span></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 54.0pt; mso-add-space: auto; mso-list: l1 level1 lfo4; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "symbol"; font-size: 12.0pt; line-height: 107%;">·<span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; line-height: normal;"> </span></span><!--[endif]--><span style="font-size: 12.0pt; line-height: 107%;">Execute: kafka-console-producer.bat
--broker-list localhost:9092 --topic sales<o:p></o:p></span><br />
<span style="font-size: 12.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_5" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:451.2pt;
height:35.4pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image008.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><span style="font-size: 12.0pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<a href="https://3.bp.blogspot.com/-sOYbVY6UGTs/XOV3CVhPz3I/AAAAAAAAI_o/uPT0GjAKzY0I9Ddn_9XzZjipLxaOnhpmgCEwYBhgL/s1600/CreateProducer.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="55" data-original-width="707" height="48" src="https://3.bp.blogspot.com/-sOYbVY6UGTs/XOV3CVhPz3I/AAAAAAAAI_o/uPT0GjAKzY0I9Ddn_9XzZjipLxaOnhpmgCEwYBhgL/s640/CreateProducer.png" width="640" /></a><br />
<br /></div>
<span style="font-size: large;"><b></b></span><br />
<div>
<span style="font-size: large;"><b><span style="font-size: large;"><b><br /></b></span></b></span></div>
<span style="font-size: large;"><b>
<div>
<span style="font-size: large;"><b><br /></b></span></div>
Create Consumer</b></span></div>
<div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: 0cm; mso-add-space: auto;">
<span style="font-size: 12.0pt; line-height: 107%;">Let’s create a consumer which should subscribe
to sales topic to get all the messages.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 54.0pt; mso-add-space: auto;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 54.0pt; mso-add-space: auto; mso-list: l1 level1 lfo4; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "symbol"; font-size: 12.0pt; line-height: 107%;">·<span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; line-height: normal;"> </span></span><!--[endif]--><span style="font-size: 12.0pt; line-height: 107%;">Go to Apache kafka installation directory
and navigate to bin\windows folder (D:\Softwares\kafka_2.11-2.2.0\bin\windows).<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 54.0pt; mso-add-space: auto; mso-list: l1 level1 lfo4; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="font-family: "symbol"; font-size: 12.0pt; line-height: 107%;">·<span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; line-height: normal;"> </span></span><!--[endif]--><span style="font-size: 12.0pt; line-height: 107%;">Execute: kafka-console-consumer.bat
--bootstrap-server localhost:2181 --topic sales<o:p></o:p></span><br />
<span style="font-size: 12.0pt; line-height: 107%;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-VOHibPRlLrc/XOV3CcPDamI/AAAAAAAAI_4/G47kQB7It1oWyTGgk8Ic9dPBWpZHfmj_QCEwYBhgL/s1600/createConsumer.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="68" data-original-width="739" height="58" src="https://2.bp.blogspot.com/-VOHibPRlLrc/XOV3CcPDamI/AAAAAAAAI_4/G47kQB7It1oWyTGgk8Ic9dPBWpZHfmj_QCEwYBhgL/s640/createConsumer.png" width="640" /></a></div>
<span style="font-size: 12.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 54.0pt; mso-add-space: auto; mso-list: l1 level1 lfo4; text-indent: -18.0pt;">
</div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 54.0pt; mso-add-space: auto; mso-list: l1 level1 lfo4; text-indent: -18.0pt;">
<span style="font-size: 12.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_6" o:spid="_x0000_i1025" type="#_x0000_t75" style='width:451.2pt;
height:41.4pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:/Users/Abdul/AppData/Local/Temp/msohtmlclip1/01/clip_image010.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><span style="font-size: 12.0pt; line-height: 107%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; font-family: "calibri" , sans-serif;"><br /></span>
<span style="background-color: white; font-family: "calibri" , sans-serif;"><br /></span>
<span style="background-color: white; font-family: "calibri" , sans-serif;"><br /></span>
<span style="background-color: white; font-family: "calibri" , sans-serif;"><br /></span>
<span style="background-color: white; font-family: "calibri" , sans-serif;">By running all four components (zookeeper, kafka,
producer, and consumer) in different terminals, we will be able to enter
messages from the producer’s terminal and can see them appearing in the consumer’s
terminal and If everything works fine, you will be able to push and see
messages.</span><br />
<span style="background-color: white; font-family: "calibri" , sans-serif;"><br /></span>
<span style="background-color: white; font-family: "calibri" , sans-serif;"><br /></span></div>
<span style="font-size: large;"><b>Bonus Installation:</b></span><br />
<div class="MsoNormal" id="1f1b" name="1f1b" style="--baseline-multiplier: 0.17; --x-height-multiplier: 0.375; color: rgba(0, 0, 0, 0.84);">
<span style="color: #2f5496; font-family: "calibri light" , sans-serif; font-size: 16.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 12.0pt; line-height: 107%;">There are
multiple UI applications which can be use for monitoring apache kafka. It will
display the information like total brokers, topics, partition and even lets you
view messages as well.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 12.0pt; line-height: 107%;">One of the tools
is Kafdrop which we will install right now and see all those details on UI.<o:p></o:p></span><br />
<span style="font-size: 12.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #2f5496; font-family: "calibri light" , sans-serif; line-height: 107%;"><span style="font-size: large;"><b>Requirements:</b></span><span style="font-size: 16pt;"><o:p></o:p></span></span></div>
<ul type="disc">
<li class="MsoNormal" style="background: white; color: #24292e; line-height: normal; mso-list: l5 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 36.0pt;"><span style="font-family: "segoe ui" , sans-serif; font-size: 12.0pt;">Java
8<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #24292e; line-height: normal; margin-top: 3.0pt; mso-list: l5 level1 lfo5; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt;"><span style="font-family: "segoe ui" , sans-serif; font-size: 12.0pt;">Kafka
(0.8.1 or 0.8.2 is known to work)<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #24292e; line-height: normal; margin-top: 3.0pt; mso-list: l5 level1 lfo5; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt;"><span style="font-family: "segoe ui" , sans-serif; font-size: 12.0pt;">Zookeeper
(3.4.5 or later)<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #24292e; line-height: normal; margin-top: 3.0pt; mso-list: l5 level1 lfo5; mso-margin-bottom-alt: auto; tab-stops: list 36.0pt;"><span style="font-family: "segoe ui" , sans-serif; font-size: 12.0pt;">Download
and Extract <a href="https://github.com/HomeAdvisor/Kafdrop/archive/master.zip">Kafdrop</a>
using 7-zip.<o:p></o:p></span></li>
</ul>
<span style="font-size: large;"><b>Installation</b></span><br />
<div class="MsoListParagraphCxSpFirst" style="background: white; line-height: normal; margin-top: 3.0pt; mso-add-space: auto; mso-list: l3 level1 lfo6; mso-margin-bottom-alt: auto; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="color: #24292e; font-family: "symbol"; font-size: 12.0pt;">·<span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; line-height: normal;"> </span></span><!--[endif]--><span style="color: #24292e; font-family: "segoe ui" , sans-serif; font-size: 12.0pt;">Go to the Kafdrop directory
and run mvn clean package which will generate an executable JAR in target
directory.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="background: white; line-height: normal; margin-top: 3.0pt; mso-add-space: auto; mso-list: l3 level1 lfo6; mso-margin-bottom-alt: auto; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="color: #24292e; font-family: "symbol"; font-size: 12.0pt;">·<span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; line-height: normal;"> </span></span><!--[endif]--><span style="color: #24292e; font-family: "segoe ui" , sans-serif; font-size: 12.0pt;">Go to target
directory and run<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="background: white; line-height: normal; margin-left: 72.0pt; margin-top: 3.0pt; mso-add-space: auto; mso-list: l3 level2 lfo6; mso-margin-bottom-alt: auto; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="color: #24292e; font-family: "courier new"; font-size: 12.0pt;">o<span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; line-height: normal;"> </span></span><!--[endif]--><span style="color: #24292e; font-family: "segoe ui" , sans-serif; font-size: 12.0pt;">java -jar
./target/kafdrop-<version>.jar --zookeeper.connect=localhost:2181<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast" style="background: white; line-height: normal; margin-top: 3.0pt; mso-add-space: auto; mso-list: l3 level1 lfo6; mso-margin-bottom-alt: auto; text-indent: -18.0pt;">
<!--[if !supportLists]--><span style="color: #24292e; font-family: "symbol"; font-size: 12.0pt;">·<span style="font-family: "times new roman"; font-size: 7pt; font-stretch: normal; line-height: normal;"> </span></span><!--[endif]--><span style="color: #24292e; font-family: "segoe ui" , sans-serif; font-size: 12.0pt;">Open a browser and navigate
to <a href="http://localhost:9000/">http://localhost:9000</a> to view the Kafdrop
UI. <o:p></o:p></span><br />
<span style="color: #24292e; font-family: "segoe ui" , sans-serif; font-size: 12.0pt;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-KVQHAjXQujc/XOV30_OcXVI/AAAAAAAAI_8/JDwPwur5ROwqC7tIoqnQNXs45CLreYh9wCLcBGAs/s1600/kafdropUI.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="897" data-original-width="1600" height="358" src="https://1.bp.blogspot.com/-KVQHAjXQujc/XOV30_OcXVI/AAAAAAAAI_8/JDwPwur5ROwqC7tIoqnQNXs45CLreYh9wCLcBGAs/s640/kafdropUI.PNG" width="640" /></a></div>
<span style="color: #24292e; font-family: "segoe ui" , sans-serif; font-size: 12.0pt;"><br /></span>
<span style="color: #24292e; font-family: "segoe ui" , sans-serif; font-size: 12.0pt;"><br /></span>
<span style="color: #24292e; font-family: "segoe ui" , sans-serif; font-size: 12.0pt;"><br /></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-top: 3.0pt; mso-margin-bottom-alt: auto;">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="graf" style="background: white; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 0cm; margin-right: 0cm; margin-top: 15.75pt;">
<br /></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: 0cm; mso-add-space: auto;">
<br /></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 0cm; mso-add-space: auto;">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
</div>
<div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
</div>
</div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-69508211637402326252019-04-23T15:44:00.001+05:302019-04-23T15:44:07.242+05:30JAVA 11 – New String methods<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoTitle" style="text-align: center;">
<span style="font-size: large;">JAVA 11 – New String
methods</span><o:p></o:p></div>
<div class="MsoTitle" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">In this blog, we will discuss about
all six new methods which got introduced with JDK 11.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
</div>
<ul style="text-align: left;">
<li><b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">isBlank():</span></b><span style="font-size: 14pt; line-height: 107%;">
returns true if string is empty otherwise false. White spaces code will also be
considered as empty string.</span></li>
</ul>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// Java 8
Predefine Functional Interface</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// The best
way to learn JAVA 8 is to implement it wherever you can...</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span>BiConsumer<String, String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">msg1</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">msg2</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">) ->
System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.println(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">msg1</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">msg2</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// local variable
type inference</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">var</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">msg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"Welcome to waheedtechblog page"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// String <u>msg</u>
= "Welcome to <u>waheedtechblog</u> page"; both are same</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// Will
return true if string is empty or any white spaces</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">if</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">msg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.isBlank())
{</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 3;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"msg attribute is emty"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">msg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span>} </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">else</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 3;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"1. Hello, "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">msg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">emptyMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">""</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 72.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"2. Is msg Empty: "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">, String.<i>valueOf</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">emptyMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.isBlank()));</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span>String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">whitespacesMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"\n\t"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 72.0pt;">
<span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"2.
Is msg empty: "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">, String.<i>valueOf</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">whitespacesMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">.isBlank()));<o:p></o:p></span></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Output:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-tab-count: 1;"> </span></span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">1. Hello, Welcome to waheedtechblog page</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">2. Is msg Empty: true</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">3.
Is msg empty: true</span><b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"><br /></span></div>
<div class="MsoNormal">
</div>
<ul style="text-align: left;">
<li><b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">lines():</span></b><span style="font-size: 14pt; line-height: 107%;">
This method returns a stream of lines extracted from the string, separated by
line terminators such as \n, \r etc.</span></li>
</ul>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-tab-count: 1;"> </span></span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">lineMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"Welcome\nto\nwaheedtechblog\npage"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"3. Line Msg: \n"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">lineMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// line
returns streams of line extracted from the String</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span>List<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">lines</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">lineMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.lines().collect(Collectors.<i>toList</i>());</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"4.
line as list: "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">lines</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">);<o:p></o:p></span></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Output:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span></span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">3. Line Msg: </span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">Welcome</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">to</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">waheedtechblog</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">page</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">4.
line as list: [Welcome, to, waheedtechblog, page]</span><b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"><br /></span></div>
<div class="MsoNormal">
</div>
<ul style="text-align: left;">
<li><b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">repeat(n):</span></b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">
This method returns the concatenated string of original string repeated the
number of times in the argument.<o:p></o:p></span></li>
</ul>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">var</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">repeatMessage</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"Welcome"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 72.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// returns a new string whose
value is the concatenation of this string repeated</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// ‘n’ times.</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"9.
Repeat msg: "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">, </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">repeatMessage</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">.repeat(5));<o:p></o:p></span></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Output: <o:p></o:p></span></b></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">9.
Repeat msg: WelcomeWelcomeWelcomeWelcomeWelcome</span><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"><br /></span></div>
<div class="MsoNormal">
</div>
<ul style="text-align: left;">
<li><strong><span style="background: white; color: black; font-family: "Calibri",sans-serif; font-size: 14.0pt; line-height: 107%; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Strip(),
StripLeading(),StripTrailing():</span></strong><strong><span style="background: white; color: black; font-family: "Calibri",sans-serif; font-size: 14.0pt; font-weight: normal; line-height: 107%; mso-ascii-theme-font: minor-latin; mso-bidi-font-weight: bold; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> These
method are used to strip white spaces from the String<o:p></o:p></span></strong></li>
</ul>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<strong><span style="background: white; color: black; font-family: "Calibri",sans-serif; font-size: 14.0pt; font-weight: normal; mso-ascii-theme-font: minor-latin; mso-bidi-font-weight: bold; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><span style="mso-tab-count: 1;"> </span></span></strong><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">var</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">stripMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"<span style="mso-spacerun: yes;"> </span>Welcome to<span style="mso-spacerun: yes;">
</span>\t Waheedtechblog page<span style="mso-spacerun: yes;"> </span>"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"5. Normal Print: "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">, </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"$"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">stripMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> + </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">" $"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// As the name suggests, Strip() methods are used to strip <u>whitespaces</u>
from the</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// string.</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"6. Using Strip(): "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">, </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"$"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">stripMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.strip() + </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"$"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"7. Using StripLeading(): "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">, </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"$"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">stripMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.stripLeading() + </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"$"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt; text-indent: 36.0pt;">
<span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">display</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">.accept(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"8. Using StripTrailing: "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">, </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"$"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">stripMsg</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">.stripTrailing() + </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"$"</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt; text-indent: 36.0pt;">
<br /></div>
<div class="MsoNormal">
<b><span style="font-size: large;">Output:</span></b><o:p></o:p></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">5. Normal Print: $<span style="mso-spacerun: yes;">
</span>Welcome to<span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span>Waheedtechblog page<span style="mso-spacerun: yes;"> </span>$</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">6. Using Strip(): $Welcome to<span style="mso-spacerun: yes;">
</span><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span>Waheedtechblog page$</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">7. Using StripLeading(): $Welcome to<span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span>Waheedtechblog page<span style="mso-spacerun: yes;"> </span>$</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">8.
Using StripTrailing: $<span style="mso-spacerun: yes;"> </span>Welcome to<span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span>Waheedtechblog page$</span><strong><span style="font-family: "Calibri",sans-serif; font-size: 14.0pt; line-height: 107%; mso-ascii-theme-font: minor-latin; mso-bidi-font-weight: normal; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><o:p></o:p></span></strong></div>
<div class="MsoListParagraph">
<br /></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: 0cm; mso-add-space: auto;">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">You can download the source code from my
GitHub <a href="https://github.com/abdulwaheed18/java11" target="_blank">repository</a>.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 0cm; mso-add-space: auto;">
<br /></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 0cm; mso-add-space: auto;">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Happy Coding…!!!<o:p></o:p></span></div>
<br /></div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-20873467385123242502019-04-21T21:34:00.001+05:302019-04-21T21:46:28.759+05:30Java 10 - Local Variable Type Inference<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div align="center" class="MsoTitle" style="text-align: center;">
</div>
<div align="center" class="MsoTitle" style="text-align: center;">
<span style="font-size: large;"><strong><span style="color: #002060; font-family: "calibri" , sans-serif;">Java 10 - </span></strong><strong><span style="color: #002060; font-family: "calibri" , sans-serif; mso-ascii-theme-font: minor-latin; mso-bidi-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Local Variable Type
Inference</span></strong></span><strong><span style="color: #002060; font-family: "calibri" , sans-serif; font-weight: normal;"><o:p></o:p></span></strong></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">In one of my
previous blog, I have already discussed about Type Inference. If you don’t have
the idea about Type Inference then you can check my blog <span style="color: #0070c0;"><a href="http://www.waheedtechblog.com/2019/01/java-8-type-inference.html"><span style="color: #0070c0; text-decoration: none;">here</span></a></span>.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">If we want
to understand <b style="mso-bidi-font-weight: normal;">Type Inference</b> in one
line then we can say that It is the capability of the compiler to automatically
detect the datatype of a variable at the compiler time.<o:p></o:p></span></div>
<h2>
<span style="font-size: small;">What is Local Variable type inference?</span><o:p></o:p></h2>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">Java 10
added new feature that allows the developer to skip the type declaration
associated with local variables (those defined inside method definitions,
initialization blocks, for-loops, and other blocks like if-else), and the type
is inferred by the JDK. It will, then, be the job of the compiler to figure out
the datatype of the variable.<o:p></o:p></span></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%;">Until Java 9</span></b><span style="font-size: 14.0pt; line-height: 107%;">, we had to define the type of the
local variable.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="font-size: 14.0pt; line-height: 107%;"><span style="color: #0b5394;">E.g.: String message = “Welcome to Waheedtechblog.com”;</span><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">The above
statement is right as that’s how things have been since the inception of java but
if you observe, the type of the object at right side is clearing mentioning the
type of data that we have defined at left side which makes the variable
redundant.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">So with Java
10, We can declare a <b style="mso-bidi-font-weight: normal;">local</b> variable
without defining its data type at left side.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><span style="color: #0b5394;"> Var message = “Welcome to Waheedtechblog.com”;</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%;">Over here, we
don’t have to provide the data type of String to local variable message. Compiler
will get the datatype based on right hand side value.</span><br />
<b style="font-size: 14pt;"><br /></b>
<b style="font-size: 14pt;">Note:</b></div>
<div class="MsoNormal">
<div class="MsoNormal" style="margin-left: 18.0pt;">
</div>
<ul style="text-align: left;">
<li><span style="font-size: 14.0pt; line-height: 107%;">This feature is available only for local variables with the
initializer. It cannot be used for <b>member
variables, method parameters, return types,</b> etc as the initializer is
required as without which compiler won’t be able to infer the type.</span></li>
<li><span style="font-size: 14.0pt; line-height: 107%;">To support backward compatibility, var is not a java reserved
keyword. So, we can create variable with name var as it is allowed.</span></li>
</ul>
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%;">Let’s see where all we can use var <o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">package</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">
com.waheedtechblog.typeinference;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">import</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> java.util.function.BiConsumer;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">import</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> java.util.function.Consumer;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">public</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">class</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> TypeInferenceExample {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">static</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 10.0pt;">// static
block variable</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">var</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">staticVaribale</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"var in static block"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>Consumer<String> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">msg</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> -> {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 3;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.println(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">msg</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>};</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.accept(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">staticVaribale</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">public</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">static</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">void</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">args</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">) {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>TypeInferenceExample </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">inferenceExample</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">new</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> TypeInferenceExample();</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>BiConsumer<String, String> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = (</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">str</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">msg</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">) -> {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 3;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">out</span></i></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.println(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">str</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">msg</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>};</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 10.0pt;">// Before
Java 10</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>String </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">message</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Welcome
to Waheedtechblog.com"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.accept(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Before JDK 10: "</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">message</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 10.0pt;">// Using JDK
10, Local Variable</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">var</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">message10</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Welcome to
Waheedtechblog.com"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.accept(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"With JDK 10: "</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">message</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 10.0pt;">// local
variable declaration in enhanced loops</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>String[] </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">countryName</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = { </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"India"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Japan"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"UAE"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"USA"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"UK"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> };</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.accept(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">""</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"List of Country using
enhanced loop"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">for</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> (</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">var</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">country</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> : </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">countryName</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">) {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 3;"> </span></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.accept(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">""</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">country</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>}</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 10.0pt;">// basic for
loop</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.accept(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">""</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"List of Country using basic
loop"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">for</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> (</span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">var</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">i</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = 0; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">i</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> < </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">countryName</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #0000c0; font-family: "consolas"; font-size: 10.0pt;">length</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">; </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">i</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">++) {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 3;"> </span></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.accept(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">""</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">, </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">countryName</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">[</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">i</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">]);</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>}</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">displayOnConsole</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.accept(</span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"Length of string '"</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> + </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">message10</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> + </span><span style="color: #2a00ff; font-family: "consolas"; font-size: 10.0pt;">"' is: "</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">,</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 3;"> </span><span style="mso-tab-count: 1;"> </span>String.<i>valueOf</i>(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">inferenceExample</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.getLenth(</span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">message10</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">)));</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span><br />
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><br /></span>
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><br /></span>
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="font-family: "consolas";"><span style="font-size: 13.3333px;">// var is not keyword, so you can create variable with name var as well.</span></span><br />
<span style="font-family: "consolas";"><span style="font-size: 13.3333px;"><span style="white-space: pre;"> </span> String var = "var is not keyword";</span></span><br />
<span style="font-family: "consolas";"><span style="font-size: 13.3333px;"><span style="white-space: pre;"> </span> displayOnConsole.accept("", var);</span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #3f7f5f; font-family: "consolas"; font-size: 10.0pt;">// can return
<u>var</u> type as well</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">private</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">int</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> getLenth(String </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">msg</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">) {</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">var</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">length</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> = </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">msg</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">.length();</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">return</span></b><span style="color: black; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #6a3e3e; font-family: "consolas"; font-size: 10.0pt;">length</span><span style="color: black; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 10.0pt;">}</span><span style="font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%;">Output:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">var
in static block<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">Before
JDK 10: Welcome to Waheedtechblog.com<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">With
JDK 10: Welcome to Waheedtechblog.com<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">List
of Country using enhanced loop<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">India<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">Japan<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">UAE<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">USA<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">UK<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">List
of Country using basic loop<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">India<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">Japan<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">UAE<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">USA<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">UK<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "calibri light" , sans-serif;"><span style="color: #0b5394;">Length
of string 'Welcome to Waheedtechblog.com' is: 29</span><span style="color: #0070c0; font-size: 10pt;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
var is not keyword</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%;">Illegal use of Var:<o:p></o:p></span></b></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%;"><br /></span></b></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;">1.<span style="font: 7.0pt "Times New Roman";">
</span></span></span></b><!--[endif]--><b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%;">Can’t use as a class field<o:p></o:p></span></b></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">Class Test {<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;"><span style="mso-tab-count: 1;"> </span><span style="color: red;">Var
msg; // not allowed as it is local variable inference</span><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">}<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;">2.<span style="font: 7.0pt "Times New Roman";">
</span></span></span></b><!--[endif]--><b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; line-height: 107%;">Local variable without initialization<o:p></o:p></span></b></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">Private void getOTP(){<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;"><span style="mso-tab-count: 1;"> </span><span style="color: red;">Var
otp ; // cant use without initializer</span><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">}<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><strong><span style="font-family: "calibri" , sans-serif; font-size: 14.0pt; line-height: 107%;"><span style="mso-list: Ignore;">3.<span style="font: 7.0pt "Times New Roman";"> </span></span></span></strong><!--[endif]--><strong><span style="background: white; border: none 1.0pt; font-family: "roboto"; padding: 0cm;">Not allowed as parameter for any methods</span></strong><strong><span style="font-family: "calibri" , sans-serif; font-size: 14.0pt; line-height: 107%;"><o:p></o:p></span></strong></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">Private void getOTP(var secretKey){<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="color: red; font-size: 12.0pt; line-height: 107%;"><span style="mso-tab-count: 1;"> </span>//Error,
cannot use var on method parameter<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">}</span><strong><span style="font-family: "calibri" , sans-serif; font-size: 14.0pt; line-height: 107%;"><o:p></o:p></span></strong></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><strong><span style="font-family: "calibri" , sans-serif; font-size: 14.0pt; line-height: 107%;"><span style="mso-list: Ignore;">4.<span style="font: 7.0pt "Times New Roman";"> </span></span></span></strong><!--[endif]--><strong><span style="background: white; border: none 1.0pt; font-family: "roboto"; padding: 0cm;">Not permitted in method return type</span></strong><strong><span style="font-family: "calibri" , sans-serif; font-size: 14.0pt; line-height: 107%;"><o:p></o:p></span></strong></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">Private var getOTP(String secretKey){<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;"><span style="mso-tab-count: 1;"> </span><span style="color: red;">//Error,
Method return type cannot be var<o:p></o:p></span></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">}<b style="mso-bidi-font-weight: normal;"><o:p></o:p></b></span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -18.0pt;">
<!--[if !supportLists]--><strong><span style="font-family: "calibri" , sans-serif; font-size: 14.0pt; line-height: 107%;"><span style="mso-list: Ignore;">5.<span style="font: 7.0pt "Times New Roman";"> </span></span></span></strong><!--[endif]--><strong><span style="background: white; border: none 1.0pt; font-family: "roboto"; padding: 0cm;">Not permitted with variable initialized with
‘NULL’</span></strong><strong><span style="font-family: "calibri" , sans-serif; font-size: 14.0pt; line-height: 107%;"><o:p></o:p></span></strong></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">Private String getOTP(String secretKey){<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;"><span style="mso-tab-count: 1;"> </span>Var msg = null; <span style="color: red;">Error, cant initialize as null<o:p></o:p></span></span></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">}<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="font-size: 12.0pt; line-height: 107%;">You can download the source code from my <a href="https://github.com/abdulwaheed18/java10/tree/master/src/com/waheedtechblog/typeinference" target="_blank">GitHub </a>repository.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpLast">
<span style="font-size: 12.0pt; line-height: 107%;">Happy Coding..!!!<b style="mso-bidi-font-weight: normal;"><o:p></o:p></b></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<br /></div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-55414459956848475222019-04-20T01:09:00.000+05:302019-04-20T01:09:12.472+05:30Java 8 - Optional<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h2 style="text-align: left;">
Java 8 - Optional</h2>
<span style="font-size: large;">In this blog, I’ll discuss about Optional class which was introduced in JDK8 under java.util.package. Optional class is used to represent a value is present or absent.<br /><br />With Optional class, developers have to less worry about NullPointerException and can work on neat and clean code. It contains at most one value.</span><br /><br /><span style="font-size: large;">Advantages:<br />· No need to check for null<br />· No more NullPointerException at runtime</span><br /><blockquote class="tr_bq">
Public final class Optional<T> extends Object {<br />}</blockquote>
<span style="font-size: large;"><b>Let’s understand all its usage with the help of example</b></span><br /><br /><span style="font-size: large;"><b>1. Optional.empty()</b></span><br /><br /><span style="font-size: large;">To create an empty Optional object we simply need to write</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// How to
create empty Optional</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> Optional<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">optional</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>empty</i>();</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-ansi-language: EN-IN; mso-bidi-font-family: Consolas; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-ansi-language: EN-IN; mso-bidi-font-family: Consolas; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">"1. Optional: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-ansi-language: EN-IN; mso-bidi-font-family: Consolas; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">optional</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">);</span><br /><b> Output: </b><br /><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> 1. Optional: Optional.empty</span><b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></b></div>
<br /><br /><span style="font-size: large;"><b>2. isPresent()</b><br /><br />You can also check whether any value present in Optional or not<br /></span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-ansi-language: EN-IN; mso-bidi-font-family: Consolas; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-ansi-language: EN-IN; mso-bidi-font-family: Consolas; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">"2. Optional: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-ansi-language: EN-IN; mso-bidi-font-family: Consolas; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">optional</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.isPresent());</span><br /><b>Output:</b><br /><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> 2. Optional: false<o:p></o:p></span></div>
<span style="font-size: large;"><br /><b>3. Of() method</b><br /><br />We can also use Static Of method to create an Optional Object.<br /></span><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> //Can
create Optional using Static Of method</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> Optional<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">name</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>of</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"WaheedTechblog.com"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"3. Name: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">name</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.toString());<o:p></o:p></span></div>
<b>Output:</b><br /><div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> </span></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">3.
Name: Optional[WaheedTechblog.com]<o:p></o:p></span></div>
<br /><span style="font-size: large;"><b>Note:</b> Make sure you are not passing any null value to Of() method else it would throw a NullPointer Exception.</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;">Optional<String>
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">nullValue</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>of</i>(</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">null</span></b><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"4. Name: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">nullValue</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.toString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">Output:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">Exception in
thread "main" </span><u><span style="color: #0066cc; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">java.lang.NullPointerException</span></u><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> at
java.base/java.util.Objects.requireNonNull(</span><u><span style="color: #0066cc; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">Objects.java:221</span></u><span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">)</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> at
java.base/java.util.Optional.<init>(</span><u><span style="color: #0066cc; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">Optional.java:107</span></u><span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">)</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> at java.base/java.util.Optional.of(</span><u><span style="color: #0066cc; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">Optional.java:120</span></u><span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">)</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="color: red; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"> at
com.waheedtechblog.optional.OptionalExample.main(</span><u><span style="color: #0066cc; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">OptionalExample.java:20</span></u><span style="color: red; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">)</span><b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></b></div>
<br /><span style="font-size: large;"><b>4. OfNullable()</b></span><br /><br /><span style="font-size: large;">If you are not sure about the object you must use OfNullable API.</span><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">//Can accept
NUll value as well</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> Optional<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">isNull</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>ofNullable</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"WaheedTechblog.com"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"5. Name: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">isNull</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.toString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="line-height: 107%;">Output:<span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> </span></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">5. Name: Optional[WaheedTechblog.com]<o:p></o:p></span></div>
<br /><span style="font-size: large;">If we pass a null reference, it does not throw an exception but returns an empty Optional object.</span><br /><br /> <br /><span style="font-size: large;"><b>5. isPresent()</b></span><br /><br /><span style="font-size: large;">We can use isPresent() method to check whether the Optional object is empty or contains some value.</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="background: silver; font-family: Consolas; font-size: 10pt;">Optional</span><span style="font-family: Consolas; font-size: 10pt;"><String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">isNull</span><span style="font-family: Consolas; font-size: 10pt;"> = <span style="background: silver; mso-highlight: silver;">Optional</span>.<i>ofNullable</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"WaheedTechblog.com"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">//check
isNull object contains some value</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">if</span></b><span style="font-family: Consolas; font-size: 10pt;">(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">isNull</span><span style="font-family: Consolas; font-size: 10pt;">.isPresent()) {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"6. Optional object contains some value: "</span><span style="font-family: Consolas; font-size: 10pt;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">isNull</span><span style="font-family: Consolas; font-size: 10pt;">.toString());</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="line-height: 107%;">Output:<span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> </span></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">6. Optional object contains some value:
Optional[WaheedTechblog.com]<b><o:p></o:p></b></span></div>
<br /> <br /><span style="font-size: large;"><b>6. isEmpty()</b></span><br /><br /><span style="font-size: large;">Similarly , we can use isEmpty method to check whether the Optional object is empty or not</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">//Check
whether object is empty or not</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> Optional<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">nullValue</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>ofNullable</i>(</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">null</span></b><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">if</span></b><span style="font-family: Consolas; font-size: 10pt;"> (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">nullValue</span><span style="font-family: Consolas; font-size: 10pt;">.isEmpty()) {</span><span style="font-family: Consolas; font-size: 10pt;">System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10pt;">"7. Is Optional empty? "</span><span style="font-family: Consolas; font-size: 10pt;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10pt;">nullValue</span><span style="font-family: Consolas; font-size: 10pt;">.toString());</span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="line-height: 107%;">Output:<span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">7. Optional object contains
some value: Optional.empty<o:p></o:p></span></div>
<br /> <br /><b><span style="font-size: large;">7. ifPresent()</span></b><br /><span style="font-size: large;">It enables us to run some code if Optional Object is not empty. Most of the time, we normally do something like this in our application.</span><br /><blockquote class="tr_bq">
If(user != null) {<br /> String name = user.getName();<br />}</blockquote>
<span style="font-size: large;">Over here, we are performing some operation based on if condition. This approach is lengthy and there are chances to miss such null checks which can result in a NullPointerException at runtime.</span><br /><br /><span style="font-size: large;">ifPresent() accepts Consumer functional Interface.</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">//Execute
if Optional object exist.</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> Optional<String> </span><u><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">name</span></u><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>of</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"WaheedTechblog.com"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">name</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.ifPresent(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">value</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> -> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"8.
Length of name: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">value</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.length()));</span><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="line-height: 107%;">Output:<span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">8.
Length of name: 18<o:p></o:p></span></div>
<br /><br /><span style="font-size: large;"><b>8. orElse()</b></span><br /><br /><span style="font-size: large;">We can use orElse() method to set some default value incase if Optional object is Empty.</span><br /><br /><span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10pt;">//Set Default
value if Object is empty</span><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">nullString</span><span style="font-family: Consolas; font-size: 10pt;"> = </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">null</span></b><span style="font-family: Consolas; font-size: 10pt;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> String
</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">testOrElse</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>ofNullable</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">nullString</span><span style="font-family: Consolas; font-size: 10pt;">).orElse(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"This is default value"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"9.
Print testorElse value: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">testOrElse</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">);</span><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="line-height: 107%;">Output:<span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">9.
Print testorElse value: This is default value<o:p></o:p></span></div>
<br /><br /><span style="font-size: large;"><b>9. orElseGet()</b></span><br /><br /><span style="font-size: large;">This API is very similar to orElse() method except that instead of taking default value, you can pass Supplier functional interface which returns response based on some operation.</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">//Invoke Functional Interface if Optional Object is empty</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt;">String </span><span style="background: yellow; color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas; mso-highlight: yellow;">testOrElseGet</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>ofNullable</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">nullString</span><span style="font-family: Consolas; font-size: 10pt;">).orElseGet(() -> </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"waheedtechblog"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"10.
Print orElseGet value: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="background: silver; color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas; mso-highlight: silver;">testOrElseGet</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">);</span><b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="line-height: 107%;">Output:<span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoNormal">
<b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"> </span></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">10. Print orElseGet value: waheedtechblog<o:p></o:p></span></div>
<br /><span style="font-size: large;"><b>Note:</b> At the very first glance, it looks like orElse and orElseGet method are very similar and either one of them can be used to get the default value but this is not very true. There is a subtle but very important difference between the two.</span><br /><br /><span style="font-size: large;"><b>Let’s understand this with Example</b></span><div>
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> private</span></b><span style="font-family: Consolas; font-size: 10pt;"> String <span style="background: silver; mso-highlight: silver;">getDbConnection</span>() {</span></div>
<div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"13. Invoking Default fucntion"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">return</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"Create db Connection"</span><span style="font-family: Consolas; font-size: 10pt;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> }</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// Checking the <u>diff</u> between orElse <u>Vs</u> orElseGet</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="background: silver; font-family: Consolas; font-size: 10pt;">String</span><span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">testOrElseDiff</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>ofNullable</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"waheedtechblog"</span><span style="font-family: Consolas; font-size: 10pt;">).orElse(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">optionalExample</span><span style="font-family: Consolas; font-size: 10pt;">.getDbConnection());</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"11. Print testorElse value: "</span><span style="font-family: Consolas; font-size: 10pt;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">testOrElseDiff</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="background: silver; font-family: Consolas; font-size: 10pt;">String</span><span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">testOrElseGetDiff</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>ofNullable</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"waheedtechblog"</span><span style="font-family: Consolas; font-size: 10pt;">).orElseGet(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">optionalExample</span><span style="font-family: Consolas; font-size: 10pt;">::getDbConnection);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt; text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"12.
Print orElseGet value: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">testOrElseGetDiff</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt; text-indent: 36.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="line-height: 107%;">Output:<span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt;">13. Invoking Default fucntion</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt;">11. Print testorElse value: waheedtechblog</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">12.
Print orElseGet value: waheedtechblog<o:p></o:p></span></div>
<br /> <br /><span style="font-size: large;">If you observe the output, you will realize that orElse() method is invoking getDBConnection() when the object is already present whereas orElseGet() method is not invoking the DB call.</span><br /><br /><span style="font-size: large;">So, I would suggest choose orElseGet over orElse as database query or any rest API call can cost to your application performance when there was no need of that.</span><br /><br /><span style="font-size: large;"><b>10. orElseThrow()</b></span><br /><br /><span style="font-size: large;">Instead of calling any default method in case of Optional value not present, it throws an exception.</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">//Throw runtime exception if Optional value is not present</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> String </span><u><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">orElseThrowTest</span></u><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> = Optional.<i>ofNullable</i>(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">nullString</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">).orElseThrow(RuntimeException::</span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">new</span></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Output:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">Exception in thread "main" </span><u><span style="color: #0066cc; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">java.lang.RuntimeException</span></u><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> at
java.base/java.util.Optional.orElseThrow(</span><u><span style="color: #0066cc; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">Optional.java:408</span></u><span style="color: red; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">)</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="color: red; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;"> at com.waheedtechblog.optional.OptionalExample.main(</span><u><span style="color: #0066cc; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">OptionalExample.java:62</span></u><span style="color: red; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">)</span><b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"><o:p></o:p></span></b></div>
<br /><span style="font-size: large;"><b>11. get()</b></span><br /><br /><span style="font-size: large;">Get returns the value of Optional Object if not null or else throws no such element exception.</span><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt;">Optional<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">getTest</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>ofNullable</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"waheedtechblog"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"15. GetTest value: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">getTest</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.get());<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<b><span style="line-height: 107%;">Output:</span></b></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> 15. GetTest value:
waheedtechblog<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"><br /></span></div>
<span style="font-size: large;">Note: get throws NoSuchElementException if Optional object is empty</span><br /><br /> <br /><span style="font-size: large;"><b>12. Filter()</b></span><br /><br /><span style="font-size: large;">The concept of filter is very similar to stream API filter. It takes Predicate as an argument and returns an Optional object.</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// <u>filteration</u>
on Optional</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> Optional<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">username</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>of</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"waheedtechblog"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 72.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">boolean</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">isLengthValid</span><span style="font-family: Consolas; font-size: 10pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">username</span><span style="font-family: Consolas; font-size: 10pt;">.filter(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">str</span><span style="font-family: Consolas; font-size: 10pt;"> -> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">str</span><span style="font-family: Consolas; font-size: 10pt;">.length() > 5).isPresent();</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"16. is Length Valid: "</span><span style="font-family: Consolas; font-size: 10pt;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">isLengthValid</span><span style="font-family: Consolas; font-size: 10pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="line-height: 107%;">Output:</span></b></div>
<div class="MsoNormal" style="text-indent: 36.0pt;">
<b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> </span></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">16. is Length Valid: true</span><b><span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><o:p></o:p></span></b></div>
<br /><span style="font-size: large;"><b>13. map()</b></span><br /><br /><span style="font-size: large;">Using map, we can transform the Optional value.</span><br /><br /><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> // map
to perform operation on Optional</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> Optional<String> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">password</span><span style="font-family: Consolas; font-size: 10pt;"> = Optional.<i>of</i>(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"waheedtechblog"</span><span style="font-family: Consolas; font-size: 10pt;">);</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10pt;">encodedPassword</span><span style="font-family: Consolas; font-size: 10pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10pt;">password</span><span style="font-family: Consolas; font-size: 10pt;">.map(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10pt;">str</span><span style="font-family: Consolas; font-size: 10pt;"> -> Base64.<i>getEncoder</i>().encodeToString(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10pt;">str</span><span style="font-family: Consolas; font-size: 10pt;">.getBytes())).get();</span></div>
<div class="MsoListParagraphCxSpFirst" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 72.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">"17. Encoded Password: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">encodedPassword</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">);<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 72.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; text-indent: 36.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="line-height: 107%;"> Output:</span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0px;">
<span style="font-size: 18.6667px; text-indent: 36pt;"><b> </b></span><span style="font-family: Consolas; font-size: 10pt; text-indent: 36pt;">17. Encoded Password:
d2FoZWVkdGVjaGJsb2c=</span></div>
<br /><br /><span style="font-size: large;">We can also merge filter and map together to get the result. </span><br /><div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; mso-add-space: auto; text-indent: 36.0pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> //
first do validation and then operation on Optional object<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">validatedEncodedPassword</span><span style="font-family: Consolas; font-size: 10pt;"> = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">password</span><span style="font-family: Consolas; font-size: 10pt;">.filter(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">ps</span><span style="font-family: Consolas; font-size: 10pt;"> -> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">ps</span><span style="font-family: Consolas; font-size: 10pt;">.length() <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 108.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: -36.0pt;">
<span style="font-family: Consolas; font-size: 10pt;">> 15)</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> .map(<span style="color: #6a3e3e;">str</span> -> Base64.<i>getEncoder</i>().encodeToString(<span style="color: #6a3e3e;">str</span>.getBytes())).toString();</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 108.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: -36.0pt;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%; text-indent: 72pt;">System.</span><b style="text-indent: 72pt;"><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt; line-height: 107%; text-indent: 72pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10pt; line-height: 107%; text-indent: 72pt;">"18. Validated Encoded Password: "</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%; text-indent: 72pt;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10pt; line-height: 107%; text-indent: 72pt;">validatedEncodedPassword</span><span style="font-family: Consolas; font-size: 10pt; line-height: 107%; text-indent: 72pt;">);</span></div>
<div class="MsoListParagraph" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 72.0pt; margin-right: 0cm; margin-top: 0cm; mso-add-space: auto; text-indent: 72.0pt;">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36.0pt;">
<b><span style="line-height: 107%;">Output:<span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; text-indent: 36.0pt;">
<span style="font-family: Consolas; font-size: 10pt; text-indent: 36pt;">18. Validated Encoded Password: Optional.empty</span></div>
<br /><span style="font-size: large;"><b>Happy Coding…!!!</b></span><br /><br /> <br /><br /> <br /><br /> <br /><br /> </div>
</div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-91860753622053515422019-04-19T16:55:00.002+05:302019-04-19T16:55:47.143+05:30Java 9 - Try with resources Improvement<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoTitle" style="text-align: center;">
Java 9 <span style="mso-spacerun: yes;"> </span>-<span style="mso-spacerun: yes;"> </span>Try with resources Improvement<o:p></o:p></div>
<br /><br />
<br />
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">In this blog, I’ll discuss about try
with resources which was introduced with JDK 7 and what enhancement has been
done in JDK 9.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Try with resources is a great feature
which was introduced in JDK 7 that helps in closing resources automatically
after being used.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Any class can be used as resources if
that class implements AutoClosable Interface.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><b>Advantages</b></span></div>
<div class="MsoNormal">
</div>
<ul style="text-align: left;">
<li><span style="font-size: 14pt; text-indent: -18pt;">As try with resources closes all the resources
file Automatically which prevents memory leaks.</span></li>
<li><span style="font-size: 14pt; text-indent: -18pt;">M</span><span style="font-size: 14pt; line-height: 107%;">ore readable code as you don’t have to write
unnecessary code.</span> </li>
</ul>
<br />
<div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Let’s understand it with an example<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">import</span></b><span style="font-family: Consolas; font-size: 10pt;"> java.io.FileNotFoundException;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">import</span></b><span style="font-family: Consolas; font-size: 10pt;"> java.io.FileOutputStream;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">/**</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> * This class will explain the try with
resources which was introduced with</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> * JDK7.</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> * </span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> * </span><b><span style="color: #7f9fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">@author</span></b><span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> AbdulWaheed18<u>@gmail.com</u></span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> *</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> */</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">public</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">class</span></b><span style="font-family: Consolas; font-size: 10pt;"> ExmapleWithJava7 {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">public</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">static</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">void</span></b><span style="font-family: Consolas; font-size: 10pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">args</span><span style="font-family: Consolas; font-size: 10pt;">) </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">throws</span></b><span style="font-family: Consolas; font-size: 10pt;"> FileNotFoundException {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">try</span></b><span style="font-family: Consolas; font-size: 10pt;"> (FileOutputStream </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">fileStream</span><span style="font-family: Consolas; font-size: 10pt;"> = </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">new</span></b><span style="font-family: Consolas; font-size: 10pt;"> FileOutputStream(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"App.log"</span><span style="font-family: Consolas; font-size: 10pt;">);) {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">logMessage</span><span style="font-family: Consolas; font-size: 10pt;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"[INFO]
DATA NEED TO BE WRITTEN"</span><span style="font-family: Consolas; font-size: 10pt;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">byte</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">logMessageInBytes</span><span style="font-family: Consolas; font-size: 10pt;">[] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">logMessage</span><span style="font-family: Consolas; font-size: 10pt;">.getBytes();</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">fileStream</span><span style="font-family: Consolas; font-size: 10pt;">.write(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">logMessageInBytes</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"Updated log files."</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> } </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">catch</span></b><span style="font-family: Consolas; font-size: 10pt;"> (Exception </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">e</span><span style="font-family: Consolas; font-size: 10pt;">) {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// handle error</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> }</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> }</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">With JDK7, we have to declared all resources
within try block but which is not possible for every resource like DB
connection. To use DB connection, we have to close the resources explicitly in
finally block which was an obvious bug.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">With the JDK 9 enhancement, you can
just pass the reference in try block without declaring within try block.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">import</span></b><span style="font-family: Consolas; font-size: 10pt;"> java.io.FileNotFoundException;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">import</span></b><span style="font-family: Consolas; font-size: 10pt;"> java.io.FileOutputStream;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">/**</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> * This class will explain enhancement of try
with resources block which was</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> * introduced with JDK9 .</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> * </span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> * </span><b><span style="color: #7f9fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">@author</span></b><span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> AbdulWaheed18<u>@gmail.com</u></span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> *</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #3f5fbf; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> */</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">public</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">class</span></b><span style="font-family: Consolas; font-size: 10pt;"> ExmapleUsingJava9 {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">public</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">static</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">void</span></b><span style="font-family: Consolas; font-size: 10pt;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">args</span><span style="font-family: Consolas; font-size: 10pt;">) </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">throws</span></b><span style="font-family: Consolas; font-size: 10pt;"> FileNotFoundException {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> FileOutputStream </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">fileStream</span><span style="font-family: Consolas; font-size: 10pt;"> = </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">new</span></b><span style="font-family: Consolas; font-size: 10pt;"> FileOutputStream(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"App.log"</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">try</span></b><span style="font-family: Consolas; font-size: 10pt;"> (</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">fileStream</span><span style="font-family: Consolas; font-size: 10pt;">) {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> String </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">logMessage</span><span style="font-family: Consolas; font-size: 10pt;"> = </span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"[INFO]
DATA NEED TO BE WRITTEN"</span><span style="font-family: Consolas; font-size: 10pt;">;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">byte</span></b><span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">logMessageInBytes</span><span style="font-family: Consolas; font-size: 10pt;">[] = </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">logMessage</span><span style="font-family: Consolas; font-size: 10pt;">.getBytes();</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">fileStream</span><span style="font-family: Consolas; font-size: 10pt;">.write(</span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">logMessageInBytes</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="font-family: Consolas; font-size: 10pt;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"Updated log files."</span><span style="font-family: Consolas; font-size: 10pt;">);</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> } </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">catch</span></b><span style="font-family: Consolas; font-size: 10pt;"> (Exception </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">e</span><span style="font-family: Consolas; font-size: 10pt;">) {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// handle error</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> }</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"> }</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;">}</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 10pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"><span style="font-size: 13.3333px;">You can download the Source code from <a href="https://github.com/abdulwaheed18/Java9" target="_blank">here</a>.</span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">Happy Coding…!!!<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 10pt; line-height: 107%;">
</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
</div>
<!--[if !supportLists]--><br />
<br /></div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0tag:blogger.com,1999:blog-630363181754150660.post-78471677181393669772019-04-07T17:41:00.000+05:302019-04-07T17:41:08.894+05:30Supplier Functional Interface - JAVA 8<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h1>
Supplier Functional Interface<o:p></o:p></h1>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<code><b><span style="background: white; border: none windowtext 1.0pt; color: #2b2b2b; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-border-alt: none windowtext 0cm; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; padding: 0cm;">Supplier </span></b></code><span style="background: white; color: #2b2b2b; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;">is an in-built
functional interface introduced in Java 8 in the </span><code style="-webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal; hyphens: none; orphans: 2; outline: 0px; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;"><b><span style="border: none windowtext 1.0pt; font-family: "Calibri",sans-serif; line-height: 107%; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-latin; mso-border-alt: none windowtext 0cm; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; padding: 0cm;">java.util.function</span></b></code><span style="-webkit-text-stroke-width: 0px; float: none; font-variant-caps: normal; font-variant-ligatures: normal; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;"> package. Supplier
does not expect any input but returns the output. This interface can be handy
where you want to generate some data like OTP, currentTime or even GUID<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background: white; color: #2b2b2b; font-family: "Arial",sans-serif;">The functional method of Supplier is get(T t).<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-size: 12.0pt; line-height: 107%;">Here is a simple source code of <b style="mso-bidi-font-weight: normal;">java.util.function.Supplier<o:p></o:p></b></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;">@FunctionalInterface<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;">public interface Supplier<T>
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;"> /**<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;"> *
Gets a result.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;"> *
@return a result<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;"> */<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;"> T
get();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;">Where
T get () is an abstract method where T is the return type of the function.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060; font-size: 12.0pt; line-height: 107%; mso-bidi-font-size: 11.0pt;">Example 1:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">import</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> java.util.Date;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">import</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> java.util.function.Supplier;</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">public</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">class</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> SupplierExample {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">public</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">static</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">void</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> main(String[] </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">args</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">) {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// Calling
Supplier Functional Interface without using Lambda Expression</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span>SystemDate </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">date</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">new</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> SystemDate();</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"System Date: "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">date</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.get());</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><span style="color: #3f7f5f; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">// Using
Lambda Expression</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span>Supplier<Date> </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">supplier</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> = () -> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">new</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> Date();</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span>System.</span><b><i><span style="color: #0000c0; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">out</span></i></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.println(</span><span style="color: #2a00ff; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">"Using lambda, System Date: "</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> + </span><span style="color: #6a3e3e; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">supplier</span><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">.get());</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">}</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">class</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> SystemDate </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">implements</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> Supplier<Date> {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span></span><span style="color: #646464; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">@Override</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">public</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> Date get() {</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">return</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> </span><b><span style="color: #7f0055; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">new</span></b><span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"> Date();</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><span style="mso-tab-count: 1;"> </span>}</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">}</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas; font-size: 10.0pt; line-height: 107%; mso-bidi-font-family: Consolas;">Output:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">System
Date: Sun Apr 07 17:37:49 IST 2019</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black; font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;">Using
lambda, System Date: Sun Apr 07 17:37:49 IST 2019</span><span style="font-family: Consolas; font-size: 10.0pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-size: 12.0pt; line-height: 107%;">This interface doesn’t contains any default
or static method<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-size: 12.0pt; line-height: 107%;">That’s it for Supplier Functional Interface,
Will talk about other Predefined Functional Interface in my next blog.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-size: 12.0pt; line-height: 107%;">Happy Coding…!!!<o:p></o:p></span></div>
<br /></div>
Abdul Waheedhttp://www.blogger.com/profile/00600409440522692007noreply@blogger.com0