tag:blogger.com,1999:blog-63140545909587636332024-03-19T08:14:24.818+05:30Coding Bot | Program CodesCodingBot || C - C++ - Java - Blogger - Linux - ElasticSearch - CrateDB - Microsoft Graph API - We're Here To HelpPiyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comBlogger49125tag:blogger.com,1999:blog-6314054590958763633.post-87717754786256799432024-03-04T01:43:00.001+05:302024-03-04T01:56:14.085+05:30Exploring Microsoft Graph APIs: A Tech Enthusiast's Dive into Messages and SharePoint<style type="text/css">
#toc_container {
background: #f9f9f9 none repeat scroll 0 0;
border: 1px solid #aaa;
display: table;
font-size: 95%;
margin-bottom: 1em;
padding: 20px;
width: auto;
}
.toc_title {
font-weight: 700;
text-align: center;
}
#toc_container li, #toc_container ul, #toc_container ul li{
list-style: outside none none !important;
}
</style><div><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; color: #0d0d0d; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="font-family: Raleway; font-size: medium;">Hey techies! If you're into tech and always hungry for knowledge, you might have heard about Microsoft Graph APIs. In this series, we're going to break down the intricacies of this powerful tool, shining a light on the Messages and SharePoint APIs. Ready to join the adventure into the heart of Microsoft 365 integration?</span></p><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; color: #0d0d0d; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="font-family: Raleway;"><br /></span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyP1MtBJQo8qjUyyYUXANpLvMt3iQPvkvcc-Z4YB1yRR9K6HK6ulelHPE000IFSSftvgqRAqMSmJ0pDqSu3Q9RARa4gr38ENdliAXxFQYbtNHDlh8EVQrksfBq-WreRIaH1438VeQyCZyS77MEO1lNr1f8KY6cF7MHO70VPoiwW4zG34dyL4Y6EkqUSRg/s1024/Microsoft%20Graph%20API%20series%20-%20CodingBot.jpeg" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Raleway;"><img border="0" data-original-height="1024" data-original-width="1024" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyP1MtBJQo8qjUyyYUXANpLvMt3iQPvkvcc-Z4YB1yRR9K6HK6ulelHPE000IFSSftvgqRAqMSmJ0pDqSu3Q9RARa4gr38ENdliAXxFQYbtNHDlh8EVQrksfBq-WreRIaH1438VeQyCZyS77MEO1lNr1f8KY6cF7MHO70VPoiwW4zG34dyL4Y6EkqUSRg/w400-h400/Microsoft%20Graph%20API%20series%20-%20CodingBot.jpeg" width="400" /></span></a></div><span style="font-family: Raleway;"><br /></span><p></p><h3 style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; margin: 1.25em 0px; text-align: left; white-space-collapse: preserve;"><span style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; font-weight: 600;"><span style="color: #cc0000; font-family: Raleway; font-size: large;">Getting Started: Azure Apps and Permissions Demystified</span></span></h3><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; color: #0d0d0d; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="font-family: Raleway; font-size: medium;">Let's start with the basics. Before we can play around with Microsoft Graph API, we need to create an Azure app. No sweat, it's not as complicated as it might sound! Just swing by the Azure portal, set up an application registration, and bam – you've got a unique identity for your app.</span></p><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; color: #0d0d0d; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="font-family: Raleway; font-size: medium;">Now, onto permissions – think of them as your app's backstage pass. We're going to choose permissions wisely, letting our app access only what it needs. We want our app to be the VIP in the Microsoft Graph party, right?</span></p><h3 style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; margin: 1.25em 0px; text-align: left; white-space-collapse: preserve;"><span style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; font-weight: 600;"><span style="color: #cc0000; font-family: Raleway; font-size: large;">Bearer Tokens: The Hidden Key</span></span></h3><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; color: #0d0d0d; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="font-family: Raleway; font-size: medium;">Alright, with our app registered and permissions sorted, here comes the cool part – bearer authentication tokens. Picture them as the magic keys unlocking the treasure trove of Microsoft Graph resources. And guess what? We're going to show you how to snag these golden tokens.</span></p><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; color: #0d0d0d; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="font-family: Raleway;"><span style="font-size: medium;">We're talking OAuth 2.0 – sounds complex, but we promise it's not rocket science. This authorization code flow is like the golden ticket to Willy Wonka's chocolate factory. We'll guide you through the entire process – from asking for permission politely to swapping codes for access tokens. Once you've got that token, you're practically a Microsoft Graph rockstar</span>!</span></p><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; font-weight: 600;"><span style="color: #cc0000; font-family: Raleway; font-size: large;">Coming Soon: Unveiling Messages and SharePoint APIs!</span></span></p><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; font-weight: 600;"><span></span></span></p><a name='more'></a><span style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; font-weight: 600;"><span style="color: #cc0000; font-family: Raleway; font-size: large;"><br /></span></span><p></p><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; color: #0d0d0d; margin: 1.25em 0px; white-space-collapse: preserve;"><span style="font-family: Raleway; font-size: medium;">Now that we've laid the groundwork, it's time for the real fun. In the next blog posts, we're zooming in on the Messages and SharePoint APIs – the unsung heroes of Microsoft Graph.</span></p><ul style="text-align: left;"><li><span style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; font-weight: 600; white-space-collapse: preserve;"><span style="color: #2b00fe; font-family: Raleway; font-size: large;">Messages API: Inbox Magic</span></span></li></ul><span style="font-family: Raleway;"><span style="background-color: white; color: #0d0d0d; white-space-collapse: preserve;"><span style="font-size: medium;">Ever wondered how to make your app handle emails like a pro? We're spilling the secrets of the Messages API – from sending and receiving emails to managing your inbox with flair. Get ready to level up your email game!</span></span><br /></span><ul style="text-align: left;"><li><span style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; font-weight: 600; white-space-collapse: preserve;"><span style="color: #2b00fe; font-family: Raleway; font-size: large;">SharePoint API: Collaboration Mastery</span></span></li></ul><span style="font-family: Raleway;"><span style="background-color: white; color: #0d0d0d; white-space-collapse: preserve;"><span style="font-size: medium;">SharePoint is like the cool kid in the Microsoft 365 playground. Our blog post is your guide to the SharePoint API, where we'll talk about managing documents, uploading files, and even juggling SharePoint lists. It's like digital acrobatics – minus the circus tent!</span></span><br /></span><ul style="text-align: left;"><li><span style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; font-weight: 600; white-space-collapse: preserve;"><span style="color: #2b00fe; font-family: Raleway; font-size: large;">Advanced Tricks: Elevate Your Game</span></span></li></ul><span style="background-color: white; color: #0d0d0d; white-space-collapse: preserve;"><span style="font-family: Raleway; font-size: medium;">Once you've nailed the basics, we'll take things up a notch. Think real-time collaboration, Microsoft Graph webhooks for event-driven apps, and optimizing performance for handling massive datasets. It's the advanced stuff that'll make you the tech guru in your team!</span></span></div><div><span style="font-family: Raleway; font-size: medium;"><br /></span></div><div><p style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 transparent; --tw-rotate: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-shadow-colored: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-skew-x: 0; --tw-skew-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; background-color: white; border: 0px solid rgb(227, 227, 227); box-sizing: border-box; color: #0d0d0d; margin: 1.25em 0px 0px; white-space-collapse: preserve;"><span style="font-family: Raleway; font-size: medium;">As we dive into this Microsoft Graph API adventure, our mission is clear – to simplify the tech talk and make it a breeze for you. Whether you're a seasoned developer or just dipping your toes into coding waters, we've got your back. Stay tuned for more insights into Messages and SharePoint APIs, and let's uncover the tech wonders together! Cheers to the exciting journey ahead!</span></p></div><div dir="ltr" style="text-align: left;" trbidi="on">
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/=/2019/04/download-youtube-videos-youtube-to-mp3-converter-free.html",
"datePublished":"2019-04-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Download You Tube Videos & You Tube To MP3 Converter FREE",
"sameAs": "https://www.codingbot.net/=/2019/04/download-youtube-videos-youtube-to-mp3-converter-free.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "93",
"bestRating": "100",
"ratingCount": "687"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-59517562056865866462019-02-15T20:20:00.002+05:302024-03-04T01:04:59.676+05:30A Clustering Guide to CrateDB and ElasticSearch<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Hi friends,</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Recently I ran CrateDB in multi-node environment as a trial and in this post I'll share my findings as to what is the basic setup and configuration that is required to have high availability setup in CrateDB. I am pretty sure that similar settings will be useful for ElasticSearch as well.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">I used crateDB version 3.2.2 and Java 8 for this POC.</span><br />
<br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">So there is some bootstrap checks before the server runs successfully. According to the documentation those are some mandatory checks that are mandatory and needed to get the cluster running smoothly in multi-node environment. </span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">The first problem I faced was related to increasing ulimit in Ubuntu, which I have explained in this post - <a href="https://www.codingbot.net/2019/02/increase-open-files-file-descriptors-ulimit-in-ubuntu-cratedb-elasticsearch.html" target="_blank">Increase Open Files/File Descriptors/Ulimit in Ubuntu | CrateDB ElasticSearch</a>.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span><span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Once my CrateDB ran successfully, I began to mess around with basic settings and configurations. Remember, many of the things can be customised, and I'll share a few read-worthy links if you truly want to customise all settings around your cluster, towards the end of this post.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">So here's the final configuration that worked for me:</span><br />
<a name='more'></a>
<script src="https://gist.github.com/chughpiyush/e210e1e63fb03661492099cf2a33d0c5.js"></script>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span><span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Here's the explanation for the non-obvious ones:</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"></span><br />
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;">node.master</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Set this to true to just <b>INDICATE </b>that this node is master eligible. It does not mean that it will be master for sure.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;">node.data</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Set this to true if this node will be storing data. There can be a master node that doesn't store data.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;">network.host</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">This will vary if you want to set the cluster in your organisation locally, or set it up on Azure or GCP or AWS. In my case for POC purpose, I entered my machine's IP address here. More details <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html" rel="nofollow" target="_blank">here</a>.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;">discovery.zen.minimum_master_nodes</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">This tells how many minimum master nodes are needed before the cluster events starts to work. In my case I had it as 2, if you take 1 master node offline that cluster won't work. One of the two is set as master.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;">discovery.zen.ping.unicast.hosts</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">You can specify your master node's IP address alongwith the ports here. If any new node tries to ping any of the existing nodes in the cluster, it may be automatically added to the cluster.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;">gateway.expected_nodes</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">This is the number of nodes that your cluster is expecting. It will start to show warning if the total number of data/master nodes don't match this count.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;">gateway.recover_after_nodes</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">This is the nodes that should be active in order to begin the recovery process. I set it at 3 because I could then check if I take 1 data node offline, does it lead to high availability of data or not.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">I faced some heap space issues as well, and I have documented all of the issues here - </span><span face=""trebuchet ms" , sans-serif" style="font-size: large;"><a href="https://www.codingbot.net/2019/02/increase-open-files-file-descriptors-ulimit-in-ubuntu-cratedb-elasticsearch.html" target="_blank">Increase Open Files/File Descriptors/Ulimit in Ubuntu | CrateDB ElasticSearch</a><span style="color: #444444;">. </span></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">As you know, CrateDB by default maintains shards as (number of data nodes * 2). I created 1 table with 3282 records. The table was divided in 8 shards total as each of my 4 nodes were a data node. Also, the default replication in CrateDB is [0-1]. Much of this information after cluster formation can be found in these tables:</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;"><i>sys.health</i></span><br />
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;"><i>sys.nodes</i></span><br />
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;"><i>sys.shards</i></span><br />
<br />
<br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">So each document out of 3282 total docs was being replicated once in a replica shared, across all 4 nodes. So even if I removed one of the non-master data nodes, data could still be extracted from the replica shards achieving 100% data availability and the system would automatically adjust the number of shards across the remaining nodes. </span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Here's a brief idea about my observation:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiarAV7TF6fxBqC7WUWDA0sQMPOLL5ybfcCpdhNjVLM8pXvHY4lQtmyY1C_GzdHEUF1cIVBDxpU9iJXpixAlLd3RDpSlfi4jvzQ6IC5sTE6lRdMqq0lOHAUUWzahMxfTmA6qrwaEIu3F_c/s1600/Sharding+example+CrateDB+ElasticSearch.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="484" data-original-width="1281" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiarAV7TF6fxBqC7WUWDA0sQMPOLL5ybfcCpdhNjVLM8pXvHY4lQtmyY1C_GzdHEUF1cIVBDxpU9iJXpixAlLd3RDpSlfi4jvzQ6IC5sTE6lRdMqq0lOHAUUWzahMxfTmA6qrwaEIu3F_c/s640/Sharding+example+CrateDB+ElasticSearch.png" width="640" /></a></div>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">If you try to take one of the data nodes offline, then what happens is that the process recognises this change and starts showing some docs in <span style="background-color: #ead1dc;">unreplicated</span> docs section in Admin console, along-with some % loss in data availability. Then the server will try to balance now active shards and replicas and possibly recover from data loss by replicating data on new re-positioned shards and replicas. After a few seconds you can see that the data availability section goes 100% again.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">It is possible to configure the number of replica nodes required, during create table command. More information can be found <a href="https://crate.io/docs/crate/reference/en/latest/sql/statements/create-table.html#number-of-replicas" rel="nofollow" target="_blank">here</a>. </span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Similarly if you want to configure the number of shards, it can be configured via this <a href="https://crate.io/docs/crate/reference/en/latest/general/ddl/sharding.html" rel="nofollow" target="_blank">way</a>.</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">These were a few useful commands to check the cluster status:</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: #ead1dc; color: #444444; font-size: large;"><i>select count(primary), num_docs, primary, node from sys.shards group by primary, node,num_docs limit 100;</i></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><i><br /></i></span>
<i><span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"></span></i><br />
<span face=""trebuchet ms" , sans-serif" style="background-color: #ead1dc; color: #444444; font-size: large;"><i>select count(primary), num_docs, primary, node['name'] from sys.shards group by primary, node['name'],num_docs order by node['name'] limit 100;</i></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">If you're facing this issue when you took one of data nodes offline:</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><br /></span>
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;">Not enough active copies to meet write consistency of [ALL] (have 1, needed 2)</span><br />
<span face=""trebuchet ms" , sans-serif" style="background-color: yellow; color: #444444; font-size: large;"><br /></span>
<br />
<blockquote class="tr_bq">
<span style="background-color: #eeeeee; color: #444444;"><span face=""arial" , "helvetica" , sans-serif" style="font-size: large;"><i>"Have 1 needed 2" means that the document should go to two shards, but only one is available. That tells us that the index you are indexing into has 1 replica, not 0, so for some reason setting replicas to 0 didn't work. Also, the default consistency is QUORUM, not ALL. Using consistency ALL in a single node cluster with an index with default settings would definitely cause this, as default settings are 5 shards and 1 replica, and replicas can not be unassigned on a single node cluster.</i></span></span></blockquote>
<br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;">Some useful links:</span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://crate.io/docs/crate/guide/en/latest/scaling/multi-node-setup.html" rel="nofollow" target="_blank">CrateDB multi-node setup</a></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html" rel="nofollow" target="_blank">Network Settings</a></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://crate.io/docs/crate/reference/en/latest/admin/system-information.html" rel="nofollow" target="_blank">System Information</a></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://crate.io/docs/clients/admin-ui/en/latest/cluster.html" rel="nofollow" target="_blank">Cluster Browser</a></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://crate.io/docs/crate/guide/en/latest/architecture/shared-nothing.html#clustering" rel="nofollow" target="_blank">Clustering</a></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html" rel="nofollow" target="_blank">Local Gateway</a></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://crate.io/docs/crate/reference/en/latest/sql/statements/create-table.html#number-of-replicas" rel="nofollow" target="_blank">Set Replicas</a></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://crate.io/docs/crate/guide/en/latest/performance/sharding.html" rel="nofollow" target="_blank">Sharding</a></span><br />
<span face=""trebuchet ms" , sans-serif" style="color: #444444; font-size: large;"><a href="https://crate.io/docs/crate/reference/en/latest/sql/statements/create-table.html#ref-clustered-clause" rel="nofollow" target="_blank">Clustered Clause</a></span><br />
<br />
<br />
<span face=""trebuchet ms" , sans-serif" style="font-size: large;"><span style="color: #444444;">Let me know via comments below if you face any problem in any of the above steps. Adios till my next post!</span></span></div>
</div>
</div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2019/02/clustering-guide-to-cratedb-and-elasticsearch.html",
"datePublished":"2019-02-15T20:00",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "A Clustering Guide to CrateDB and ElasticSearch",
"sameAs": "https://www.codingbot.net/2019/02/clustering-guide-to-cratedb-and-elasticsearch.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "96",
"bestRating": "100",
"ratingCount": "44"
}
}
}
</script> <div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-83356741988387830572019-02-15T18:15:00.002+05:302024-03-04T01:05:57.208+05:30Increase Open Files/File Descriptors/Ulimit in Ubuntu | CrateDB ElasticSearch<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: "trebuchet ms", sans-serif; font-size: large;">Hi friends,</span><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJQrAL-ZxGrAF1h4nWKRWXPmBPTgX718pEgw7tfUg49kXcpYcSjys14m4QdLui8NxzMjip19uhoc9J5HrSUq9jCLZD9jnXVhyphenhyphenDNFi1VfhbPQgFn1uBgu1cIrzRj6pxxb8Owbeh10MxNmQ/s1600/Increase+Open+Files+File+Descriptors+Ulimit+in+Ubuntu+%257C+CrateDB+ElasticSearch.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="900" data-original-width="1172" height="153" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJQrAL-ZxGrAF1h4nWKRWXPmBPTgX718pEgw7tfUg49kXcpYcSjys14m4QdLui8NxzMjip19uhoc9J5HrSUq9jCLZD9jnXVhyphenhyphenDNFi1VfhbPQgFn1uBgu1cIrzRj6pxxb8Owbeh10MxNmQ/s200/Increase+Open+Files+File+Descriptors+Ulimit+in+Ubuntu+%257C+CrateDB+ElasticSearch.jpg" width="200" /></a><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">This week I faced a rather peculiar issue while trying to setup clustering in CrateDB, which is very much similar to the clustering done in ElasticSearch. As soon as I did the basic configuration which you can find here, starting the process showed the following kinds of exceptions:</span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<br />
<a name='more'></a>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">ERROR: bootstrap checks failed
max file descriptors [16384] for elasticsearch process is too low, increase to at least [65536]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
</pre>
<!-- INFOLINKS_ON -->
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">java.lang.RuntimeException: bootstrap checks failed
initial heap size ... not equal to maximum heap size ...; this can cause resize pauses and prevents mlockall from locking the entire heap
please set [discovery.zen.minimum_master_nodes] to a majority of the number of master eligible nodes in your cluster
at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:132)
</pre>
<!-- INFOLINKS_ON -->
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">[WARN ][o.e.b.BootstrapChecks ] [node-1] max file descriptors [...] for elasticsearch process is too low, increase to at least [65536]
[WARN ][env ] max file descriptors [65535] for elasticsearch process likely too low, consider increasing to at least [65536]
[WARN ][o.e.b.BootstrapChecks ] [node-1] max number of threads [1024] for user [] is too low, increase to at least [2048]
[WARN ][o.e.b.BootstrapChecks ] [node-1] system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
</pre>
<!-- INFOLINKS_ON -->
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">The second one which is related to heap size can be very easily solved by specifying HEAP params in environment variables of your system for CrateDB or ElasticSearch. You need to have the same heap size for -Xmx and -Xms. Something like:</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="background-color: #d9ead3; font-family: "trebuchet ms" , sans-serif; font-size: large;"><i>CRATE_HEAP_SIZE</i>=2g</span><br />
<span style="background-color: #d9ead3; font-family: "trebuchet ms" , sans-serif; font-size: large;"><i>CRATE_JAVA_OPTS</i>=-Xmx2g -Xms2g</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">The other one, max file descriptors, is related to <span style="background-color: #cfe2f3;">ulimit</span> set on your system. </span><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">To see your existing hard and soft limits, use these commands in terminal:</span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ ulimit -Hn</span></div>
<div style="text-align: left;">
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ ulimit -Sn</span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">In my case, hard limit was set to 4096 and soft limit was set to 1024 by default.</span></div>
<div style="text-align: left;">
<blockquote class="tr_bq">
<span style="background-color: #fff2cc;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Also, using this option <b>doesn't</b> work in Ubuntu, atleast not in 18.04:</span><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">$ ulimit -n 70000</span></span></blockquote>
</div>
</div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">In order to solve the remaining issue related to max open files or increase file descriptors, just follow these steps and you will be good to go:</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"></span><br />
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Go to the following file:</span></span></li>
</ul>
<br />
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ sudo vim /etc/security/limits.conf</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"></span><br />
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Add the following lines in the file:</span></span></li>
</ul>
<br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">* soft nofile 80000
* hard nofile 80000
* soft nproc 80000
* hard nproc 80000
root soft nofile 80000
root hard nofile 80000
</pre>
<!-- INFOLINKS_ON -->
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"></span></div>
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Save the changes.</span></span></li>
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Next you need to go to the following file:</span></span></li>
</ul>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ sudo vim /etc/systemd/user.conf</span><br />
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Add this to the file and save changes:</span></span></li>
</ul>
</div>
</div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">DefaultLimitNOFILE=80000</pre>
<!-- INFOLINKS_ON -->
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Do the same in the following file:</span></span></li>
</ul>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ sudo vim /etc/systemd/system.conf</span><br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">DefaultLimitNOFILE=80000</pre>
<!-- INFOLINKS_ON -->
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">These changes take care that the ulimit is increased for GUI based login.</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"></span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">If you're a non-Ubuntu Linux user and following the above steps doesn't help you then maybe you can try the following steps:</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">First check the following values:</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ cat /proc/sys/fs/file-max</span><br />
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ cat /proc/sys/vm/max_map_count</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">If the values are below 65536, then do this:</span><br />
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Edit this file:</span></span></li>
</ul>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ sudo vim /etc/sysctl.conf</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">with the following changes:</span><br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">fs.file-max = 500000
vm.max_map_count=200000</pre>
<!-- INFOLINKS_ON -->
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Next, edit the following files:</span></li>
</ul>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ sudo vim /etc/pam.d/common-session</span><br />
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">$ sudo vim /etc/pam.d/common-session-noninteractive</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Add the following line in both of these files:</span><br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">session required pam_limits.so</pre>
<!-- INFOLINKS_ON -->
<br />
<br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="background-color: #ea9999;">P.S.</span> You will need to reboot the system for the changes to take effect.</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Let me know via comments below if you face any problem in any of the above steps. Adios till my next post!</span>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2019/02/increase-open-files-file-descriptors-ulimit-in-ubuntu-cratedb-elasticsearch.html",
"datePublished":"2019-02-15T20:00",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Increase Open Files/File Descriptors/Ulimit in Ubuntu | CrateDB ElasticSearch",
"sameAs": "https://www.codingbot.net/2019/02/increase-open-files-file-descriptors-ulimit-in-ubuntu-cratedb-elasticsearch.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "94",
"bestRating": "100",
"ratingCount": "175"
}
}
}
</script> <div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-39910218805321180742019-02-14T14:03:00.000+05:302019-04-14T18:17:32.058+05:30Switch Between Multiple Java Versions on Linux<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Hi friends,</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">In my previous blog post -</span><span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"> </span><span style="color: black; font-size: large;"><a href="https://www.codingbot.net/2019/02/install-java-11-and-java-8-on-linux.html" style="background-color: yellow; font-family: "Droid Sans";">Install Java 11 and Java 8 on Linux</a><span style="background-color: white;"><span style="font-family: "droid sans";">, I </span><span style="font-family: "trebuchet ms" , sans-serif;">shared the way to install Java 11/Java 8 on your Linux machine. Now many of the current applications do not support Java 11 yet, so you must need a way to quickly switch between different installations of Java on your Linux machine. Without further ado, let's get started.</span></span></span><br />
<span style="color: black; font-family: "droid sans"; font-size: large;"><span style="background-color: white;"><br /></span></span>
<br />
<h2 style="text-align: left;">
<span style="color: black; font-family: "droid sans"; font-size: large;"><span style="background-color: white;">Way 1:</span></span></h2>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">If you actually followed my way of installing Java 8/ Java 11 on your machine, and did set Java 8 / Java 11 default by using either of these commands:</span></div>
<div>
<span style="background-color: #d0e0e3; font-size: large;"><br /></span></div>
<div>
<span style="background-color: #d0e0e3;"><code class="cpp plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">sudo apt install oracle-java8-set-</code><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">default</code></span></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #d0e0e3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><br /></code></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #d0e0e3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><code class="cpp plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: 400; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">sudo apt install oracle-java11-set-</code><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">default</code></code></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #ea9999; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-size: 14px; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></code></code></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Simply install the other command and it will automatically set that version as default in your system.</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Now if you have both the above packages installed and now you want to set either of them as default, simply purge the one you wish to set as default and reinstall it.</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">So if you want to set Java 8 as default, run these commands in your terminal in order:</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<span style="background-color: #cfe2f3;"><code class="cpp plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">sudo apt purge oracle-java8-set-</code><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">default</code></span></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #cfe2f3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><br /></code></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #cfe2f3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><code class="cpp plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: 400; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">sudo apt install oracle-java8-set-</code><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">default</code></code></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 14px; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><br /></code></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 14px; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><br /></code></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">If you want to set Java 11 as default, run these commands in your terminal in order:</span></div>
<div>
<span style="background-color: #cfe2f3; font-size: large;"><br /></span></div>
<div>
<div>
<span style="background-color: #cfe2f3;"><code class="cpp plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">sudo apt purge oracle-java11-set-</code><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">default</code></span></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #cfe2f3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><br /></code></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #cfe2f3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><code class="cpp plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: 400; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">sudo apt install oracle-java11-set-</code><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">default</code></code><br />
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #cfe2f3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><br /></code></code>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #cfe2f3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><br /></code></code></div>
</div>
<div>
<br /></div>
<h2 style="text-align: left;">
<span style="color: black; font-family: "droid sans"; font-size: large;"><span style="background-color: white;">Way 2:</span></span></h2>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"></span><br />
<a name='more'></a><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Run the following command in terminal:</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<div>
<span style="background-color: #cfe2f3;"><code class="cpp plain" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;">sudo update-alternatives --config java</code></span></div>
<div>
<code class="cpp keyword bold" style="background-attachment: initial !important; background-clip: initial !important; background-color: #cfe2f3; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 14px; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre; width: auto !important;"><br /></code></div>
<div>
<br /></div>
</div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">You can select which version you want to set default and then press enter. </span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">You might need to repeat the same operation for other java programs as well like:</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;">sudo update-alternatives --config java</span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;">sudo update-alternatives --config javac</span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;">sudo update-alternatives --config javaws</span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;">sudo update-alternatives --config javadoc</span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;">sudo update-alternatives --config jar</span><br />
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;"><br /></span>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<h2 style="text-align: left;">
<span style="color: black; font-family: "droid sans"; font-size: large;"><span style="background-color: white;">Way 3:</span></span></h2>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Run the following command in terminal:</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;">sudo update-java-alternatives --list</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">This will show the list of Java installations on your machine. Now based on which version would you want to set as default, run either of the following commands:</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;">sudo update-java-alternatives --set /path/to/java/8</span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;"><br /></span></div>
<div>
<span style="background-color: #cfe2f3; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace; white-space: pre;">sudo update-java-alternatives --set /path/to/java/11</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">That's it. No need to restart the machine for the changes to take effect. However you might need to change the Project Structure in your IDE to reflect the Java version used to compile the code. </span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: large;"><span style="background-color: red;"><b>P.S.</b></span> Verify if changes have taken place by running <i><span style="background-color: #b4a7d6;">echo $JAVA_HOME</span><span style="background-color: white;"> </span></i>command in terminal.</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: large;">If you've set JAVA_HOME variable in your <span style="background-color: #9fc5e8;">/etc/environment</span> file then you'll need to change it to point it to correct Java installation directory. In this case, you'll either need to restart your system to let the changes reflect globally or if you're working in a shell, use <span style="background-color: #d5a6bd;"><i>source /etc/environment</i></span> command to force the shell session to pick up fresh variables from the file.</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: large;"><br /></span>
<br />
<h3 style="text-align: left;">
<span style="background-color: yellow; font-family: "courier new" , "courier" , monospace; font-size: large;">Update</span><span style="background-color: white; font-family: "courier new" , "courier" , monospace; font-size: large;">:</span></h3>
</div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">I recently came across a weird issue that even though my <i>/etc/environment </i>file had Java 8 set as JAVA_HOME variable, doing this <i>echo $JAVA_HOME </i> in terminal still pointed to Java 11 directory. I checked and there were no mentions of JAVA_HOME variable in any of the .<i>bashrc </i>files. To fix this, I edited my <i>~/.bashrc </i>file and added the following variables:</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">export <span style="background-color: #d0e0e3;">JAVA_HOME</span>="/usr/lib/jvm/java-8-oracle"</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">export <span style="background-color: #d0e0e3;">JRE_HOME</span>="/usr/lib/jvm/java-8-oracle/jre"</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">export <span style="background-color: #d0e0e3;">J2SDKDIR</span>="/usr/lib/jvm/java-8-oracle"</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">export <span style="background-color: #d0e0e3;">J2REDIR</span>="/usr/lib/jvm/java-8-oracle/jre"</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">export <span style="background-color: #d0e0e3;">DERBY_HOME</span>="/usr/lib/jvm/java-8-oracle/db"</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Let me know via comments if you face any trouble. Adios till my next post!</span></div>
</div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2019/02/switch-between-multiple-java-versions.html",
"datePublished":"2019-02-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Switch Between Multiple Java Versions on Linux",
"sameAs": "https://www.codingbot.net/2019/02/switch-between-multiple-java-versions.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "89",
"bestRating": "100",
"ratingCount": "45"
}
}
}
</script>
<div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-52962395283424159882019-02-10T21:15:00.001+05:302024-03-02T22:47:38.215+05:30Install Java 11 and Java 8 on Linux<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Hello friends,</span><br />
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">As many of you must be knowing that Oracle officially ended the support for Java 8 in January this year. What this means for you? You get to try your hands on the latest JDK, which is 11.0.2 as of now. I will cover practical daily-code uses of Java 11 in a separate post soon. But till that time, let's discuss how to install Java 11 on your Linux distro. </span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Now since many of your applications might still be using Java 8 and switching to Java 11 on production might not sound the best idea to your manager. This leaves you to find a way to install multiple Java versions on your machine and be able to switch between them in real-time.</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz6oj6aDCbmHEkQ4d54yucfztEmyXvzErTKDGiKBJt3fFwdTxBkqhKvmgWWZxKbHBvhQqLdr3ECLWyDPmV0fppCubfOFEtmENKI4XoRLR8IITGYpRuGMquvsFcYwkFpE6QwFhjJu0G6HU/s1600/Duke_%2528Java_mascot%2529_Java_11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="360" data-original-width="200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz6oj6aDCbmHEkQ4d54yucfztEmyXvzErTKDGiKBJt3fFwdTxBkqhKvmgWWZxKbHBvhQqLdr3ECLWyDPmV0fppCubfOFEtmENKI4XoRLR8IITGYpRuGMquvsFcYwkFpE6QwFhjJu0G6HU/s320/Duke_%2528Java_mascot%2529_Java_11.png" width="177" /></a></div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">In this post I'll share the steps to install Java 8 and Java 11 on your Linux machine and you can find how to switch between these two installations in this post -> How to switch between Java versions on Linux. </span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"></span><br />
<a name='more'></a><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">I won't be sharing the steps to do the same on Windows OS as it is pretty straight forward, just download the official .exe JDK file from Oracle's website and run it. At max you would need to update the JAVA_HOME environment variable.</span></div>
<div>
<br /></div>
<h3 style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Step 1:</span></h3>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Add the following repository:</span></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">sudo add-apt-repository ppa:webupd8team/java
</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Step 2:</span></h3>
<div>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">For Java 8:</span></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">sudo apt-get update
sudo apt install oracle-java8-installer
</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">For Java 11:</span></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">sudo apt update
sudo apt install oracle-java11-installer
</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Step 3:</span></h3>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">During the above process, the installer will ask for your consent to accept the conditions and after you provide it, it'll start downloading the official Java 8/Java 11 tar from Oracle's website. After it's done, you can check the current java version using this command:</span></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">java -version
</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Step 4:</span></h3>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">If you want to make Java 8/Java 11 as your default java version, run the following command:</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">For Java 8:</span></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">sudo apt install oracle-java8-set-default
</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;">For Java 11:</span></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">sudo apt install oracle-java11-set-default
</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">So now you have both the Java versions installed on your machine. You can always check which version is being currently used by java --version command in terminal.</span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">That's all for now, I'll soon share the steps to switch between these two versions. Till then adios!</span></div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2019/02/install-java-11-and-java-8-on-linux.html",
"datePublished":"2019-02-10T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Install Java 11 and Java 8 on Linux",
"sameAs": "https://www.codingbot.net/2019/02/install-java-11-and-java-8-on-linux.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "98",
"bestRating": "100",
"ratingCount": "221"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-37829852027403768642019-01-14T13:49:00.004+05:302024-03-04T00:46:11.543+05:30Log4j SMTP Appender Using System Environment Variables<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Hey friends!</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Earlier last week, I was stuck for a short while in a what should've been an easy task, but took my more than expected working hours to completely solve that: SMTP appender for Log4j.</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">So as we all know, SMTP or Simple Mail Transfer Protocol is used to send emails from your java program, generally when a particular level of exception occurs in your code. Log4j is a well known Java logging utility, but this particular appender wasn't discussed as about much as I expected earlier. </span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoujZOQmn15_YaP22JF0uqp6dmNzPy8-yypaD74O3ZWIMLi1-7CPK-CpVchurhAO2TzSb5EQMhMTXJ6sDwb0x_WVufZ1BEOlbeuRuvHo9i_hZAasugzzv7-QbWbTXBQczpSt6UuLDgwSY/s1600/generatedtext.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="LOG4J SMTP APPENDER" border="0" data-original-height="111" data-original-width="1102" height="64" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoujZOQmn15_YaP22JF0uqp6dmNzPy8-yypaD74O3ZWIMLi1-7CPK-CpVchurhAO2TzSb5EQMhMTXJ6sDwb0x_WVufZ1BEOlbeuRuvHo9i_hZAasugzzv7-QbWbTXBQczpSt6UuLDgwSY/s640/generatedtext.jpg" title="LOG4J SMTP APPENDER" width="640" /></a></div>
<br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Earlier I was using log4j2.yml file for logging but due to some versioning reasons, it wasn't picking up the Log4j keywords properly from the version of Log4j that I added. So eventually I had to shift to using the XML version.</span><br />
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"></span><br />
<a name='more'></a><span style="font-size: large;">So the version that I am using is:</span><br />
<br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp"><dependency>
<groupid>org.apache.logging.log4j</groupid>
<artifactid>log4j-api</artifactid>
<version>2.11.1</version>
</dependency>
<dependency>
<groupid>org.apache.logging.log4j</groupid>
<artifactid>log4j-core</artifactid>
<version>2.11.1</version>
</dependency>
</pre>
<!-- INFOLINKS_OFF -->
<br />
<br />
<span style="font-size: large;">Here's my version of log4j.xml:</span><br />
<!-- INFOLINKS_ON -->
<pre class="brush:cpp"><?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console1" target="SYSTEM_OUT">
<PatternLayout
pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}{FATAL=red, ERROR=red, WARN=cyan, INFO=white, DEBUG=yellow, TRACE=green}"/>
</Console>
<SMTP>
<name>Mail1</name>
<subject>${env:SMTP_SUBJECT}</subject>
<to>${env:SMTP_TO}</to>
<from>${env:SMTP_FROM}</from>
<smtpHost>${env:SMTP_HOST}</smtpHost>
<smtpPort>${env:SMTP_PORT}</smtpPort>
<ignoreExceptions>false</ignoreExceptions>
<smtpUsername>${env:SMTP_USERNAME}</smtpUsername>
<smtpPassword>${env:SMTP_PASSWORD}</smtpPassword>
<smtpProtocol>smtps</smtpProtocol>
<HtmlLayout charset="UTF-8" locationInfo="true" />
<ThresholdFilter level="ERROR"/>
</SMTP>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console1"/>
<AppenderRef ref="Mail1"/>
</Root>
</Loggers>
</Configuration>
</pre>
<!-- INFOLINKS_ON -->
<br />
<span style="font-size: large;">One different feature that you would observe about the code is that I am not hard-coding the login info and other params in my code. Instead I am picking them up from the environment variables. Your dev-ops team would have no complaints now :)</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">I hope you were able to use this code directly without any further hiccups. Needless to say you can always ping me via the comments below if you face any trouble in using this SMTP appender in log4j. Adios till my next post!</span></div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2019/01/log4j-smtp-appender.html",
"datePublished":"2019-01-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Log4j SMTP Appender Using System Environment Variables",
"sameAs": "https://www.codingbot.net/2019/01/log4j-smtp-appender.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "92",
"bestRating": "100",
"ratingCount": "79"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-46322300281441318852019-01-10T16:00:00.001+05:302024-03-02T22:49:16.373+05:30Fixed — ElasticSearch CrateDB Logstash — ClusterBlockException Forbidden Index Read-Only<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">Hey friends,</span><br />
<span style="font-size: large;"><span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">Ever since I started working with ElasticSearch, CrateDB and Logstash, I have faced plenty of issues and exceptions that maybe had a clear reason and fix but were not documented well anywhere. I had to research through tons and tons of documentation and StackOverFlow pages to atleast get some hints as to what might be causing the issue and how to fix it. </span></span><br />
<span style="font-size: large;"><span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">It was then I decided that I will document such problems for easy access and quick solution for others. One such exception that I got multiple times was:</span></span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">09:46:07.741 [main] ERROR
io.crate.shade.org.postgresql.util.PSQLException: ERROR: ClusterBlockException: blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];
at io.crate.shade.org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458)
at io.crate.shade.org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2158)
at io.crate.shade.org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:291)
</pre>
<!-- INFOLINKS_ON -->
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<br />
<div style="text-align: left;">
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">This was due to:</span></div>
<div style="text-align: left;">
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">[WARN ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] high disk watermark [90%] exceeded on [Piz Roseg][/crate/
[WARN ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] high disk watermark [90%] exceeded on [Piz Roseg][/crate/
[WARN ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] rerouting shards: [high disk watermark exceeded on one or more nodes]
[WARN ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] high disk watermark [90%] exceeded on [Piz Roseg][/crate/
[WARN ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] high disk watermark [90%] exceeded on [Piz Roseg][/crate/
[INFO ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] rerouting shards: [high disk watermark exceeded on one or more nodes]
[WARN ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] high disk watermark [90%] exceeded on [Piz Roseg][/crate/
[WARN ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] high disk watermark [90%] exceeded on [Piz Roseg][/crate/
[INFO ][o.e.c.r.a.DiskThresholdMonitor] [Piz Roseg] rerouting shards: [high disk watermark exceeded on one or more nodes]
</pre>
<!-- INFOLINKS_ON -->
<h2 style="text-align: left;">
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: x-large;">The Cause:</span></h2>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">This particular exception is caused by a very simple problem - <span style="background-color: yellow;">Disk Space</span>. You are definitely running out of disk space on the disk where ElasticSearch/Logstash/CrateDB is installed. </span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"></span><br />
<a name='more'></a><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq-z5PI2jHFVNoDIhuQx6JfmalSyJwM4b_7o61sBIqk1yDeu2LPnS3HeUbr_ZAZz76RC4hYYjjScnmBFbjnsp_kskSNEMatPVYtBu22ItpaY8O2_NccgB5qYG5KOEZucoRPaZwwHoJEOg/s1600/High+Disk+Watermark+Crate+ElasticSearch.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="180" data-original-width="1148" height="100" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq-z5PI2jHFVNoDIhuQx6JfmalSyJwM4b_7o61sBIqk1yDeu2LPnS3HeUbr_ZAZz76RC4hYYjjScnmBFbjnsp_kskSNEMatPVYtBu22ItpaY8O2_NccgB5qYG5KOEZucoRPaZwwHoJEOg/s640/High+Disk+Watermark+Crate+ElasticSearch.jpg" width="640" /></a></div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<h2 style="text-align: left;">
<span style="color: #444444; font-size: x-large;">The Solution:</span></h2>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">The solution comes in three parts:</span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">1. Clean up your disk. You need to have atleast 25-30% disk space free.</span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">2. For every index you have, you need to run the following command individually:</span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">PUT /your-index/_settings
{
"index.blocks.read_only_allow_delete": null
}
</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">In case of CrateDB, you need to run the following SQL query for each table:</span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">ALTER TABLE table-name SET ("blocks.read_only_allow_delete" = FALSE);
</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span><span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">3. Now restart ElasticSearch/CrateDB/Logstash. The problem should be gone.</span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div>
<br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">I hope that your problem is solved now, feel free to reach out to me if you face any similar issue. Adios till my next post!</span></div>
</div>
</div>
</div>
</div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2019/01/elasticsearch-cratedb-logstash-clusterblockexception-forbidden-index-read-only.html",
"datePublished":"2019-01-10T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Fixed — ElasticSearch CrateDB Logstash — ClusterBlockException Forbidden Index Read-Only",
"sameAs": "https://www.codingbot.net/2019/01/elasticsearch-cratedb-logstash-clusterblockexception-forbidden-index-read-only.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "96",
"bestRating": "100",
"ratingCount": "821"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-33285883119360682902019-01-09T13:45:00.002+05:302024-03-02T22:49:34.031+05:30Add/Edit Startup Applications in Ubuntu Linux<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="tr_bq" style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">Hey friends,</span><br />
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">I recently switched over to Ubuntu and I must say it feels a better and crunchier experience as compared to my alternate previous OS, the Windows. That said, switching over to Ubuntu brought its own set of problems and Ububtu 18.10 (Bionic Beaver) is not as stable as 17.04 was for me. </span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">So today I am going to share a very easy way to edit the startup applications on your Ubuntu machine. This approach should work for previous versions as well.</span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">Now just like Windows, there are some startup applications in Linux which can be added/deleted as per your own convenience. Without further ado, let me show you how:</span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<blockquote>
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">The most easy way is to first press <span style="background-color: yellow; color: #444444;">Alt + F2</span><span style="color: #444444;"> keys together.</span></span></li>
</ul>
</blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqf9KFD6c1eGYQpTszAb-6LE81YBykQrzNjhSdTUi7qaJvzro88_9yG6BR9UgYl8hH348aDOcWW6IY6zT7OWd2eMVRj0zzXwWsifzN8OdRTaORTu6IN2cHpAddo5aor8kB4Yga27ixGSA/s1600/Enter+a+Command+Ubuntu+Linux+Alt+F2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="148" data-original-width="353" height="134" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqf9KFD6c1eGYQpTszAb-6LE81YBykQrzNjhSdTUi7qaJvzro88_9yG6BR9UgYl8hH348aDOcWW6IY6zT7OWd2eMVRj0zzXwWsifzN8OdRTaORTu6IN2cHpAddo5aor8kB4Yga27ixGSA/s320/Enter+a+Command+Ubuntu+Linux+Alt+F2.jpg" width="320" /></a></div>
<br />
<blockquote>
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Then write <span style="color: #333333;"><span style="background-color: yellow;">gnome-session-properties</span><span style="background-color: white;"> and press Enter. You will be presented with the following screen.</span></span></span></li>
</ul>
</blockquote>
<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "trebuchet ms" , sans-serif;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZFy4ZUZxNRJziJLTeWQKAL9-T-MnDTrcmcSj2eiusf99U68xrEn_USESoGjdZaRqY7UHABpvnRTgqweBmAIBKnzZxodYt-Ynotk4s2NzUCtLtAvvl7KNt1I5HpnXtmQXbdZVvigwMgFs/s1600/Ubuntu+Startup+Application+Preferences.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="602" data-original-width="673" height="357" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZFy4ZUZxNRJziJLTeWQKAL9-T-MnDTrcmcSj2eiusf99U68xrEn_USESoGjdZaRqY7UHABpvnRTgqweBmAIBKnzZxodYt-Ynotk4s2NzUCtLtAvvl7KNt1I5HpnXtmQXbdZVvigwMgFs/s400/Ubuntu+Startup+Application+Preferences.jpg" width="400" /></a></span></div>
<br />
<blockquote>
<ul style="text-align: left;">
<li><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Now here you can add, edit or delete the startup applications as per your own convenience.</span></li>
</ul>
</blockquote>
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif;">So now you know</span> <span style="font-family: "trebuchet ms" , sans-serif;">how to edit your startup applications in Ubuntu Linux. Please feel free to comment if you face any problem, or in any other linux distro and I'll try my best to help you out.</span></span><br />
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2019/01/addedit-startup-applications-in-ubuntu.html",
"datePublished":"2019-01-09T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Add/Edit Startup Applications in Ubuntu Linux",
"sameAs": "https://www.codingbot.net/2019/01/addedit-startup-applications-in-ubuntu.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "85",
"bestRating": "100",
"ratingCount": "34"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-47342904539455120122017-03-26T23:52:00.001+05:302019-04-14T18:48:25.330+05:30How To Disable Copy Paste And Mouse Right Click Using JavaScript, CSS, jQuery, Swift<div dir="ltr" style="text-align: left;" trbidi="on">
<style type="text/css">
#toc_container {
background: #f9f9f9 none repeat scroll 0 0;
border: 1px solid #aaa;
display: table;
font-size: 95%;
margin-bottom: 1em;
padding: 20px;
width: auto;
}
.toc_title {
font-weight: 700;
text-align: center;
}
#toc_container li, #toc_container ul, #toc_container ul li{
list-style: outside none none !important;
}
</style>
<br />
<div id="toc_container">
<div class="toc_title">
Contents</div>
<ul class="toc_list">
<li><a href="#Disable_Right_Mouse_Click_Using_jQuery">1. Disable Right Mouse Click Using jQuery</a></li>
<li><a href="#Disable_Cut_Copy_Paste_Using_jQuery">2. Disable Cut, Copy, Paste Using jQuery</a></li>
<li><a href="#Disable_Right_Mouse_Click_Cut_Copy_Paste_Using_jQuery">3. Disable Right Mouse Click Cut, Copy, Paste Using jQuery</a></li>
<li><a href="#Disable_Copy_Paste_Using_JavaScript">4. Disable Copy Paste Using JavaScript</a></li>
<li><a href="#Disable_Copy_Paste_Using_CSS">5. Disable Copy Paste Using CSS + Enable Copy Paste For Some Content</a></li>
<li><a href="#Disable_Copy_Paste_For_Whole_Page_Using_CSS">6. Disable Copy Paste For Whole Page Using CSS</a></li>
<li><a href="#Swift_3">7. Swift 3</a></li>
</ul>
</div>
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #444444; font-family: inherit; font-size: large;">Unique content is a must for any budding website. Search engines rank your website not just on the basis of backlinks or social media shares, but most importantly how unique your content is and how helpful it is for the audience, which in turn is determined by the visits to a particular post.</span><br />
<span style="color: #444444; font-family: inherit; font-size: large;"><br /></span>
<span style="color: #444444; font-family: inherit; font-size: large;">However, not all of us think this way, there are and always will be a subset that just knows how to copy paste content. And the worst case will be when their posts show up higher in the search engine rankings than the original post. I can truly understand how frustrating this can be, especially if bloggers such as me and you devote a lot of time building such websites from the scratch and a small section simply copy pastes that content onto their own website.</span><br />
<span style="color: #444444; font-family: inherit; font-size: large;"><br /></span>
<span style="color: #444444; font-family: inherit; font-size: large;">So that's why today I decided to share 4 methods that can be used by you to block such Ctrl A + Ctrl V attempts on your website.</span><br />
<span style="color: #444444; font-family: inherit; font-size: large;"><br /></span>
<span style="color: #444444; font-family: inherit; font-size: large;">One method is by using JavaScript which disables copy-paste for your whole website and the other one uses CSS, which can also be used to enable copy-paste for some part of your posts.</span><br />
<span style="color: #444444; font-family: inherit; font-size: large;"><br /></span>
<span style="color: #444444; font-family: inherit; font-size: large;">Another one is by disabling mouse right click and disabling copy paste using jQuery.</span><br />
<a name='more'></a><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUVfqnhLf7DrvQs15id_NNvRkz0fVQRDfCywPzolBkMEWatuYar48G0VDtIrkg-42B9OlQlaoTmjVaRengWKEdPzfd3ZRKFsmfKPBj_UyC4svYRFJl6aEejg_puHg8610kr_MKW3t5sFY/s1600/logo67666466.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="How To Disable Copy Paste Using JavaScript, CSS, JQuery" border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUVfqnhLf7DrvQs15id_NNvRkz0fVQRDfCywPzolBkMEWatuYar48G0VDtIrkg-42B9OlQlaoTmjVaRengWKEdPzfd3ZRKFsmfKPBj_UyC4svYRFJl6aEejg_puHg8610kr_MKW3t5sFY/s320/logo67666466.png" title="How To Disable Copy Paste Using JavaScript, CSS, JQuery" width="293" /></a></div>
<span style="color: #444444; font-family: inherit; font-size: large;"><br /></span>
<span style="color: #444444; font-family: inherit; font-size: large;"><span id="goog_2034268559"></span><span id="goog_2034268560"></span><br /></span><span style="color: #444444; font-size: large;">You must know that these methods are not full proof, any experienced person can either disable the JavaScript or remove the CSS, but our purpose is to block the majority of those people, you cannot block all of them in any case. So without further ado, let me show you how to disable copy paste on your website using JavaScript and/or CSS and/or jQuery.</span><br />
<span style="color: #444444; font-size: large;"><br /></span>
<span style="color: #444444; font-size: large;">I'll limit these instructions to Blogger users, because I believe WordPress plugins already exists for such purpose. However, you can easily edit your *.css of header or template to use these in your website. If you have any specific questions, please feel free to ask them via comment section at the bottom of this post.</span><br />
<span style="color: #444444; font-size: large;"><br /></span>
<br />
<h3 id="Disable_Right_Mouse_Click_Using_jQuery" style="text-align: left;">
<u>Disable Right Mouse Click Using jQuery:</u></h3>
</div>
</div>
<!-- INFOLINKS_OFF -->
<br />
<pre class="brush:cpp"><script type="text/javascript">
$(document).ready(function () {
//Disable full page
$("body").on("contextmenu",function(e){
return false;
});
//Disable part of page
$("#id").on("contextmenu",function(e){
return false;
});
});
</script>
</pre>
<!-- INFOLINKS_ON -->
<br />
<h3 id = "Disable_Cut_Copy_Paste_Using_jQuery" style="text-align: left;">
<u>Disable Cut, Copy, Paste Using jQuery:</u></h3>
<!-- INFOLINKS_OFF -->
<br />
<pre class="brush:cpp"><script type="text/javascript">
$(document).ready(function () {
//Disable full page
$('body').bind('cut copy paste', function (e) {
e.preventDefault();
});
//Disable part of page
$('#id').bind('cut copy paste', function (e) {
e.preventDefault();
});
});
</script>
</pre>
<!-- INFOLINKS_ON -->
<br />
<div>
<h3 id = "Disable_Right_Mouse_Click_Cut_Copy_Paste_Using_jQuery">
<u>Disable Right Mouse Click & Cut, Copy, Paste Using jQuery:</u></h3>
</div>
<!-- INFOLINKS_OFF -->
<br />
<pre class="brush:cpp"><script type="text/javascript">
$(document).ready(function () {
//Disable cut copy paste
$('body').bind('cut copy paste', function (e) {
e.preventDefault();
});
//Disable mouse right click
$("body").on("contextmenu",function(e){
return false;
});
});
</script>
</pre>
<!-- INFOLINKS_ON -->
<br />
<div>
<blockquote>
<span style="background-color: yellow; font-weight: normal;"><span style="font-family: inherit; font-size: large;">For the above 3 codes, the #id is used to disable copy paste on a particular section of a page. Add this only if you want to disable a particular section, otherwise just add the 1st part of the code that has $("body") that'll disable copy paste for the whole page.</span></span></blockquote>
<h3 id="Disable_Copy_Paste_Using_JavaScript">
<u>Disable Copy Paste Using JavaScript:</u></h3>
</div>
<!-- INFOLINKS_OFF -->
<br />
<pre class="brush:cpp" style="text-align: left;"><!--Disable Copy Paste www.codingbot.net-->
<script language='JavaScript1.2'>
function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function (&quot;return false&quot;)
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script><span style="font-size: large;">
</span></pre>
<!-- INFOLINKS_ON -->
<br />
<div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span style="font-size: large;"><br /></span></span></div>
<div style="text-align: left;">
<blockquote class="tr_bq">
<span style="background-color: yellow;"><span style="font-size: large;">If you're on Blogger, you need to add the above code after the </span><span style="font-size: large;"><head></span><span style="font-size: large;"> in you theme's template.</span></span></blockquote>
<span style="background-color: yellow;"><span style="font-size: large;"><br /></span></span></div>
<h3 id="Disable_Copy_Paste_Using_CSS">
<u>Disable Copy Paste Using CSS + Enable Copy Paste For Some Content:</u></h3>
</div>
<!-- INFOLINKS_OFF -->
<br />
<pre class="brush:cpp">/*----- Disable Text Selection with CSS Code ------*/
.post blockquote {
-webkit-user-select: text !important;
-moz-user-select: text !important;
-ms-user-select: text !important;
user-select: text !important;
}
body {
-webkit-user-select: none !important;
-moz-user-select: -moz-none !important;
-ms-user-select: none !important;
user-select: none !important;
}
</pre>
<!-- INFOLINKS_ON -->
<span style="background-color: #3d85c6;"><br /></span>
<br />
<blockquote class="tr_bq">
<span style="background-color: yellow;"><span style="font-size: large;">If your'e on Blogger, the above CSS code needs to be added before </span><span style="font-size: large;">]]></b:skin></span><span style="font-size: large;"> in your theme's template.</span></span></blockquote>
<br />
<span style="background-color: white; font-size: large;"><br /></span>
<span style="background-color: white; font-size: large;">The .post blockquote is used to enable copy paste on specific content of your page. For example, you may be sharing some program code with your users. So this might be useful in your case.</span><br />
<span style="background-color: white; font-size: large;"><br /></span>
<span style="background-color: white; font-size: large;">Also, the above code will work for your template only if it's using .post blockquote CSS class.</span><br />
<span style="background-color: white; font-size: large;"><br /></span>
<span style="background-color: white;"><span style="font-size: large;">If it's using .post-body blockquote then you need to replace </span><span style="font-size: large;">.post blockquote with </span><span style="font-size: large;">.post-body blockquote in the above code.</span></span><br />
<span style="background-color: white;"><span style="font-size: large;"><br /></span></span>
<br />
<h3 id="Disable_Copy_Paste_For_Whole_Page_Using_CSS">
<u>Disable Copy Paste For Whole Page Using CSS:</u></h3>
<!-- INFOLINKS_OFF -->
<br />
<pre class="brush:cpp">/*----- Disable Text Selection with CSS Code-------*/
body {
-webkit-user-select: none !important;
-moz-user-select: -moz-none !important;
-ms-user-select: none !important;
user-select: none !important;
}
</pre>
<!-- INFOLINKS_ON -->
<br />
<h4 id="Swift_3" style="text-align: left;">
<span style="font-family: inherit; font-size: large;">Swift 3:</span></h4>
<!-- INFOLINKS_OFF -->
<br />
<pre class="brush:cpp">open override func target(forAction action: Selector, withSender sender: Any?) -> Any? {
guard isReadonly else {
return super.target(forAction: action, withSender: sender)
}
if #available(iOS 10, *) {
if action == #selector(UIResponderStandardEditActions.paste(_:)) {
return nil
}
} else {
if action == #selector(paste(_:)) {
return nil
}
}
return super.target(forAction: action, withSender: sender)
}
</pre>
<!-- INFOLINKS_ON -->
<span style="font-family: inherit; font-size: large;"><br /></span>
<span style="font-family: inherit; font-size: large;">The benefit of using CSS over JavaScript here is that it's lightweight as compared to JS. Also, JS is relatively easier to block for amateur people than CSS. No offence intended there :)</span><br />
<span style="font-family: inherit; font-size: large;"><br /></span>
<span style="font-family: inherit; font-size: large;">Let us know if you need any help regarding any of these codes. I'll be back soon with some more blogger tips and tricks. Till then, adios!</span><br />
<div itemscope="" itemtype="http://schema.org/Review" style="visibility: hidden;">
<div itemprop="itemReviewed" itemscope="" itemtype="http://schema.org/Product">
<span itemprop="name">How To Disable Copy Paste And Mouse Right Click Using JavaScript, CSS, jQuery</span>
</div>
<span itemprop="reviewRating" itemscope="" itemtype="http://schema.org/Rating">
<span itemprop="ratingValue">4.5</span>
</span>
<span itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<span itemprop="name">Piyush Chugh</span>
</span>
</div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2017/03/disable-copy-paste-mouse-right-click-using-javascript-jquery-css.html",
"datePublished":"2017-03-26T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "How To Disable Copy Paste And Mouse Right Click Using JavaScript, CSS, jQuery, Swift",
"sameAs": "https://www.codingbot.net/2017/03/disable-copy-paste-mouse-right-click-using-javascript-jquery-css.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "96",
"bestRating": "100",
"ratingCount": "404"
}
}
}
</script></div>
</div>
<div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-16793429651863873422017-03-15T23:11:00.001+05:302024-03-04T00:45:28.126+05:30How To Submit Website To Google,Bing,Baidu,Yandex,DuckDuckGo<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit; font-size: large;">Hello avid bloggers!<br />Today I'll share with you all how you can share your websites, blogs, RSS Feeds with all the major search engines. </span><br />
<span style="font-family: inherit; font-size: large;"><br /></span>
<span style="font-family: inherit; font-size: large;">So there you are, working so hard on setting up your website or blog, you've worked on SEO, keyword density, good content, but much to your amazement, the Big Bosses aren't still indexing your website. </span><br />
<span style="font-family: inherit; font-size: large;"><br /></span>
<span style="font-family: inherit; font-size: large;">Don't feel defeated yet, I have a way by which you can ping your website to these search engines.</span><br />
<span style="font-size: large;"><b><span style="color: red; font-family: "trebuchet ms" , sans-serif;">BOOKMARK THIS PAGE RIGHT NOW</span></b><span style="font-family: inherit;">, if you want to save your time. </span></span><br />
<span style="font-family: inherit; font-size: large;"><br /></span>
<span style="font-family: inherit; font-size: large;">If your website or blog has a sitemap, then you can ping its URL to these search engines. This is one of the basic ways to let these engines know that your website has some updated content. </span><br />
<span style="font-family: inherit; font-size: large;"><br /></span>
<span style="font-family: inherit; font-size: large;">Now even if you ping these, there's no guarantee till when their crawler will scan your website and index it, but it's still letting them know that you're ready with some awesome changes to your website or blog.</span><br />
<span style="font-family: inherit; font-size: large;"><br /></span>
<span style="font-family: inherit; font-size: large;">Search engines such as Google, Baidu (popular in China), Bing or Yandex (popular in Russia) might not automatically crawl your website, so this is one of the best ways to 'ping' them about your website's sitemap.</span><br />
<span style="font-family: inherit; font-size: large;"><br /></span>
<span style="font-family: inherit; font-size: large;">You just need to replace my sitemap with your website's or blog's sitemap and that's it. It will be pinged to these search engines automatically.</span><br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsuzzlZo5mYgAVDcKwt7fNyW81FI9jQqrG5yuCxeJbZoUk2h27zxMSrtfVNKMCsH3orVFc39Z94fkXP-lpEjrC2feJL4LJILu6l1b7iYxIxlWcVKcEbm9GceOlxgKHUwW7Vnfm6zTGt2o/s1600/Submit+Website+to+Google%252C+Bing%252C+Yandex%252C+Baidu.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="How To Submit Website To Bing, Google, Baidu, Yandex, DuckDuckGo" border="0" height="326" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsuzzlZo5mYgAVDcKwt7fNyW81FI9jQqrG5yuCxeJbZoUk2h27zxMSrtfVNKMCsH3orVFc39Z94fkXP-lpEjrC2feJL4LJILu6l1b7iYxIxlWcVKcEbm9GceOlxgKHUwW7Vnfm6zTGt2o/s640/Submit+Website+to+Google%252C+Bing%252C+Yandex%252C+Baidu.png" title="How To Submit Website To Bing, Google, Baidu, Yandex, DuckDuckGo" width="640" /></a></div>
<br />
<br />
<h3 style="text-align: left;">
<!-- INFOLINKS_OFF -->
<span style="font-size: large;">Submit Website Sitemap To Google:</span></h3>
</div>
<pre class="brush:cpp">http://www.google.com/webmasters/tools/ping?sitemap=https://www.codingbot.net/sitemap.xml
</pre>
<h3 style="text-align: left;">
<span style="font-size: large;">Submit Sitemap To Bing:</span></h3>
<pre class="brush:cpp">http://www.bing.com/webmaster/ping.aspx?siteMap=https://www.codingbot.net/sitemap.xml
</pre>
<h3 style="text-align: left;">
<span style="font-size: large;">Submit Website To Bing:</span></h3>
<pre class="brush:cpp">http://www.bing.com/toolbox/submit-site-url
</pre>
<h3 style="text-align: left;">
<span style="font-size: large;">Submit Website Sitemap To Yandex:</span></h3>
<pre class="brush:cpp">http://blogs.yandex.ru/pings/?status=success&url=https://www.codingbot.net/sitemap.xml
</pre>
<h3 style="text-align: left;">
<span style="font-size: large;">Submit Blog's Sitemap To Baidu:</span></h3>
<pre class="brush:cpp">http://ping.baidu.com/ping.html
</pre>
<h3 style="text-align: left;">
<span style="font-size: large;">Submit Website Sitemap To Baidu:</span></h3>
<pre class="brush:cpp">http://zhanzhang.baidu.com/linksubmit/index
</pre>
<!-- INFOLINKS_ON -->
<br />
<br />
<blockquote class="tr_bq" style="text-align: left;">
<span style="background-color: yellow; font-family: "trebuchet ms" , sans-serif; font-size: large;"><i>Update 2018: As of 2017, Baidu does not allow foreign nationals to have a webmaster's account :(</i></span></blockquote>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">DuckDuckGo doesn't have a dedicated webmaster tools like Google has, but it claims to scan the pages indexed by these search engines itself, so you can do little in this area. </span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: inherit; font-size: xx-small;"><br /></span>
</span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">If your website or blog is indexed in the above search engines, then surely you can hope that DuckDuckGo will also index it soon.</span></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Make sure that you comment below if this post helped you. I'll keep on sharing more such Blogger tips and posts with you, because what's a better way to learn something new than teaching it yourself?</span></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<span style="font-family: "trebuchet ms" , sans-serif;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Adios till then :)</span></span><br />
<br />
<br />
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><span style="font-family: inherit; font-size: x-small;"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><span style="color: #444444; font-size: large;"><br /></span></span></div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2017/03/submit-website-to-bing-google-baidu-yandex-duckduckgo.html",
"datePublished":"2017-03-15T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "How To Submit Website To Google,Bing,Baidu,Yandex,DuckDuckGo",
"sameAs": "https://www.codingbot.net/2017/03/submit-website-to-bing-google-baidu-yandex-duckduckgo.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "94",
"bestRating": "100",
"ratingCount": "2401"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-38401182794108967712017-03-11T16:48:00.004+05:302024-03-04T00:45:17.236+05:30Customize Scrollbar In Blogger<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">Hi there! I welcome you to yet another Blogger tutorial by Coding Bot. In our last tutorial, we discussed how can you customize the text highlighting color from the default blue to something different of your choice. This website has a different color as you can also check yourself by selecting anything on this page ;)</span><br />
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">So today I will share how can you customize the scrollbar of your website. Most of the websites come with a default scrollbar, that is kind of gloomy and boring. Kind of like this one:</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG4tl_S_JJ79FiobQiEfiHxTqRFggsrUz0amjrqO9pmN91Kvq92q_433oYDVU_xUUghrS35apzMc2aUtJnqum4q4G4y-TItnoW4_nh0LjDwJ6Pe_TkLfed6JsmbP71m49R8P_f1pWZmWw/s1600/Default+Scroll+Bar.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Customize Scrollbar In Blogger" border="0" height="297" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG4tl_S_JJ79FiobQiEfiHxTqRFggsrUz0amjrqO9pmN91Kvq92q_433oYDVU_xUUghrS35apzMc2aUtJnqum4q4G4y-TItnoW4_nh0LjDwJ6Pe_TkLfed6JsmbP71m49R8P_f1pWZmWw/s640/Default+Scroll+Bar.png" title="Customize Scrollbar In Blogger" width="640" /></a></div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">So why not change this gloomy scrollbar to something more creative and good looking for your website. </span><br />
<a name='more'></a><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><b><u>How To Customize Scrollbar In Blogger:</u></b></span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><b><u><br /></u></b></span>
<br />
<ol style="text-align: left;">
<li><span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">Login to blogger</span></li>
<li><span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">In the left nav, click on Theme -> Edit HTML</span></li>
<li><span style="font-size: large;"><span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">Search </span><span style="background-color: white;"><span style="font-weight: bold;"><span style="color: red; font-family: "courier new" , "courier" , monospace;">]]></b:skin></span><span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"> </span></span></span><span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">and paste the following lines of code just before it.</span></span></li>
</ol>
</div>
<div>
<br />
<br /></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/*--------- Scrollbar Customization by CODINGBOT.NET--------- */
::-webkit-scrollbar {
width:9px;
height:9px;
}
::-webkit-scrollbar-track {
background:#FFF; /*------Background color of scrollbar track ------*/
-webkit-box-shadow:inset 1px 1px 2px #E0E0E0;
border:1px solid #D8D8D8;
}
::-webkit-scrollbar-thumb {
background:#c0392b; /*------Thumb color ------*/
-webkit-box-shadow:inset 1px 1px 2px rgba(155,155,155,0.4);
}
::-webkit-scrollbar-thumb:hover {
-webkit-box-shadow:inset 1px 1px 10px rgba(0,0,0,0.4); /*------Shadow on hover------*/
}
::-webkit-scrollbar-thumb:active {
background:#333; /*------Thumb color when it is active------*/
-webkit-box-shadow:inset 1px 1px 2px rgba(0,0,0,0.4);
}
</pre>
<!-- INFOLINKS_ON -->
<span style="font-size: large;"><br /></span>
<br />
<div>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">The comments are pretty much self explanatory. To change the scrollbar's height or width, you can adjust it in the first part of the CSS. Similarly the background color can be changed, the thumb color, similarly other parts may be customized according to your own needs.</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><b><br /></b></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">Make sure that you comment below if this post helped you. I'll keep on sharing more such Blogger tips and posts with you, because what's a better way to learn something new than teaching it yourself?</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif; font-size: large;">Adios till then :)</span></div>
</div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2017/03/customize-scrollbar-in-blogger.htmll",
"datePublished":"2017-03-11T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Customize Scrollbar In Blogger",
"sameAs": "https://www.codingbot.net/2017/03/customize-scrollbar-in-blogger.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "88",
"bestRating": "100",
"ratingCount": "47"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-21240407267490565342017-03-10T02:38:00.002+05:302024-03-04T00:45:07.899+05:30Difference Between Hashmap and Hashtable Java<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; border: 0px; clear: both; color: #242729; margin-bottom: 1em; padding: 0px;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">There are several notable differences between Hashmap and Hashtable in Java, such as:</span></div>
<div style="background-color: white; border: 0px; clear: both; color: #242729; margin-bottom: 1em; padding: 0px;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div style="background-color: white; border: 0px; clear: both; color: #242729; margin-bottom: 1em; padding: 0px;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">1. Hashmap has one sub-type -> LinkedHashMap. It is used if you want insertion order by default, in which case you can easily swap a Hashmap for a LinkedHashMap, which wouldn't be possible in case of a Hashtable.</span></div>
<div style="background-color: white; border: 0px; clear: both; color: #242729; margin-bottom: 1em; padding: 0px;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">2. Hashmap allows a single NULL key and any number of NULL values, whereas Hashtable does not allow NULL KEYS OR VALUES.</span><br />
<a name='more'></a></div>
<div style="background-color: white; border: 0px; clear: both; color: #242729; margin-bottom: 1em; padding: 0px;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">3. Hashmap is not synchronized, where Hashtable is. This makes Hashtable better for threaded applications as synchronized objects usually perform better than unsynchronized ones</span></div>
<div style="background-color: white; border: 0px; clear: both; color: #242729; margin-bottom: 1em; padding: 0px;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
<div style="background-color: white; border: 0px; clear: both; color: #242729; margin-bottom: 1em; padding: 0px;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">However, there're a few more differences between these two, and have been summarized below:</span></div>
<div style="background-color: white; border: 0px; clear: both; color: #242729; margin-bottom: 1em; padding: 0px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj15eykmf9UZA7prmiht-wf-AeFFzn_XP1-252Yk3qGbN4G0LpNQh6P6DtYMvy-ItA_lfhQX1F64qUDn07Ihq0ud3W6Brrbs0FTI5o2YtXNWSepPq3xreKXUiYDukPJhI_OKKRQ8uT1vas/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Difference Between Hashmap and Hashtable Java | Coding Bot" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj15eykmf9UZA7prmiht-wf-AeFFzn_XP1-252Yk3qGbN4G0LpNQh6P6DtYMvy-ItA_lfhQX1F64qUDn07Ihq0ud3W6Brrbs0FTI5o2YtXNWSepPq3xreKXUiYDukPJhI_OKKRQ8uT1vas/s1600/Capture.PNG" title="Difference Between Hashmap and Hashtable Java | Coding Bot" /></a></div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span></div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2017/03/difference-between-hashmap-and-hashtable-java.html",
"datePublished":"2017-03-10T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Difference Between Hashmap and Hashtable Java",
"sameAs": "https://www.codingbot.net/2017/03/difference-between-hashmap-and-hashtable-java.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "99",
"bestRating": "100",
"ratingCount": "115"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-58042081285259048612017-01-02T23:43:00.002+05:302024-03-04T00:44:57.677+05:30Armstrong Number C Code<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Armstrong number is a number that is equal to the sum of the digits raised to the power of the number of digits. So for example:</span><br />
<span style="font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif;">371 = 3^3 + 7^3 + 1^3 = 27 + 343 + 1 = 371</span></span><br />
<span style="font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif;">There are other such numbers as well: 150, 370, 407, 8208, 1741725, etc.</span></span><br />
<span style="font-size: large;"><span style="font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif;">According to <a href="https://en.wikipedia.org/wiki/Narcissistic_number" rel="nofollow" target="_blank">Wikipedia</a>: <span style="background-color: white;"> </span>Narcissistic Number or Armstrong Number </span><span style="background-color: white; font-family: "trebuchet ms" , sans-serif;">is a number that is the sum of its own digits each raised to the power of the number of digits. This definition depends on the base </span><i style="background-color: white; font-family: "Trebuchet MS", sans-serif;">b</i><span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"> of the number system used, e.g., </span><i style="background-color: white; font-family: "Trebuchet MS", sans-serif;">b</i><span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"> = 10 for the </span><span style="font-family: "trebuchet ms" , sans-serif;">decimal system</span><span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"> or </span><i style="background-color: white; font-family: "Trebuchet MS", sans-serif;">b</i><span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"> = 2 for the </span><span style="font-family: "trebuchet ms" , sans-serif;">binary system</span><span style="background-color: white; font-family: "trebuchet ms" , sans-serif;">.</span></span><br />
<a name='more'></a><br />
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<br />
<h4 style="text-align: left;">
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"><b><span style="font-size: large;"><u>C Code to check Armstrong Number:</u></span></b></span></h4>
</div>
</div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include <stdio.h>
#include <conio.h>
int power(int, int);
void main()
{
int n, sum = 0, temp, remainder, digits = 0;
printf("Input an integer\n");
scanf("%d", &n);
temp = n;
// Count number of digits
while (temp != 0) {
digits++;
temp = temp/10;
}
temp = n;
while (temp != 0) {
remainder = temp%10;
sum = sum + power(remainder, digits);
temp = temp/10;
}
if (n == sum)
printf("%d is an Armstrong number.\n", n);
else
printf("%d is not an Armstrong number.\n", n);
}
int power(int n, int r) {
int c, p = 1;
for (c = 1; c <= r; c++)
p = p*n;
return p;
}
</pre>
<!-- INFOLINKS_ON -->
<br />
<h4 style="text-align: left;">
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"><b><span style="font-size: large;"><u>Output:</u></span></b></span></h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia731CgB5YcTKk77DBBX8ejhtZGFQA73f035ljy9pNUZn0kWg6f9q0TJ88rpDETn6vOtRxI3AahW4jyiehG1w1Dxmpui9JlTercoOfMXyZ4PqySCLLJOGFgQf54EEJiU9lUqrZ097xyTA/s1600/Armstrong+Number+C+Code.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Armstrong Number C Code" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia731CgB5YcTKk77DBBX8ejhtZGFQA73f035ljy9pNUZn0kWg6f9q0TJ88rpDETn6vOtRxI3AahW4jyiehG1w1Dxmpui9JlTercoOfMXyZ4PqySCLLJOGFgQf54EEJiU9lUqrZ097xyTA/s1600/Armstrong+Number+C+Code.png" title="Armstrong Number C Code" /></a></div>
<div>
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"><b><span style="font-size: large;"><u><br /></u></span></b></span></div>
<div>
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif;"><b><span style="font-size: large;"><u>Please share if this post helped you :)</u></span></b></span></div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2017/01/armstrong-number-c-code.html",
"datePublished":"2017-01-02T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Armstrong Number C Code",
"sameAs": "https://www.codingbot.net/2017/01/armstrong-number-c-code.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "95",
"bestRating": "100",
"ratingCount": "499"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-83859177239030612292017-01-02T01:57:00.003+05:302024-03-04T00:44:38.666+05:30Quick Sort Algorithm And C++ Code<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<center style="background-color: white; color: #444444; font-family: "droid sans"; text-align: left;">
<center style="color: black; font-family: "Times New Roman"; text-align: left;">
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">Quicksort, or partition-exchange sort, is a sorting algorithm that, on average, makes O(n log n) comparisons to sort n items. It was developed by <b>Tony Hoare</b>. Quicksort is faster in practice than other O(n log n) algorithms such as Bubble sort or Insertion Sort. Quicksort can be implemented with an in-place partitioning algorithm, so the entire sort can be done with only O(log n) additional space.</span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">Quicksort is a comparison sort and is not a stable sort.</span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">Its complexity is as follows:</span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">Best Case - <b>O(n log n)</b></span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">Worst Case - <b>O(n^2) </b></span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">Average Case - <b>O(n log n)</b></span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">Quicksort is a divide and conquer algorithm. Quicksort first divides a large list into two smaller sub-lists: the low elements and the high elements. <a name='more'></a>Quicksort can then recursively sort the sub-lists.</span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">The steps are:</span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">1. Pick an element, called a pivot, from the list.</span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">2. Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.</span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">3. Recursively sort the sub-list of lesser elements and the sub-list of greater elements.</span></center>
<center style="text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;">The base case of the recursion are lists of size zero or one, which never need to be sorted.</span></center>
<center style="font-size: medium; text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></center>
<center style="font-size: medium; text-align: left;">
<h3 style="text-align: left;">
<u style="font-size: medium;"><i><span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;">Algorithm/Pseudo-code For Quicksort:</span></i></u></h3>
</center>
</center>
<div style="color: black; font-family: "Times New Roman"; font-size: medium; text-align: center;">
<br /></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp" style="color: black; font-size: 14px;">/* Double-Click To Select Code */
function quicksort('array')
if length('array') ≤ 1
return 'array' // an array of zero or one elements is already sorted
select and remove a pivot value 'pivot' from 'array'
create empty lists 'less' and 'greater'
for each 'x' in 'array'
if 'x' ≤ 'pivot' then append 'x' to 'less'
else append 'x' to 'greater'
return concatenate(quicksort('less'), 'pivot', quicksort('greater'))
// two recursive calls</pre>
<!-- INFOLINKS_ON -->
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<br /></div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="font-family: "Times New Roman"; font-size: 14px; margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><br />
<br />
<div style="text-align: left;">
</div>
<h3>
<b><i><u><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Here is an Image depicting Quick Sort:</span></u></i></b></h3>
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0duIEAQrTEBbMqMxErUre3sqfq1ywk1PPJC6nXuu8S2KbtoGnzOsjIcb5EEhuf-fqrcXh5NcjTI8zPIOel4cd3LFKZqmnO8FomIBClnjvvd7awW7LtEgiXScgpgx6Ju71lOMzOR7IBwk/s1600/Quick+Sort2.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img alt="Quick Sort" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0duIEAQrTEBbMqMxErUre3sqfq1ywk1PPJC6nXuu8S2KbtoGnzOsjIcb5EEhuf-fqrcXh5NcjTI8zPIOel4cd3LFKZqmnO8FomIBClnjvvd7awW7LtEgiXScgpgx6Ju71lOMzOR7IBwk/s1600/Quick+Sort2.png" title="Quick Sort Algorithm And C Code" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 12.8px;"><span style="background-color: white; font-family: sans-serif; font-size: small; line-height: 15.8333px; text-align: left;">In-place partition in action on a small list. The boxed element is the pivot element, blue elements are less or equal, and red elements are larger.</span></td></tr>
</tbody></table>
</center>
<center style="background-color: white; color: #444444; font-family: "Droid Sans"; font-size: 14px; text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></center>
<center style="background-color: white; color: #444444; text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><b>If you want to see the C Code for Quick Sort, you can refer to my post <a href="https://www.codingbot.net/2013/01/quick-sort-algorithm-and-c-code.html" target="_blank">here</a>.</b></span></center>
<center style="background-color: white; color: #444444; font-size: 14px; text-align: left;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></center>
<center style="background-color: white; text-align: left;">
<h3 style="color: black; font-size: 14px;">
<i style="line-height: 22px;"><u><b><span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;">C++ Program For Quick Sort:</span></b></u></i></h3>
<div>
<br /></div>
</center>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include<iostream.h>
#include<conio.h>
using namespace std;
int part(int low,int high,int *a)
{
//Function for partitioning array
int i,h=high,l=low,p,t; //p==pivot
p=a[low];
while(low<high)
{
while(a[l]<p)
{
l++;
}
while(a[h]>p)
{
h--;
}
if(l<h)
{
t=a[l];
a[l]=a[h];
a[h]=t;
}
else
{
t=p;
p=a[l];
a[l]=t;
break;
}
}
return h;
}
void quick(int l,int h,int *a)
{
int index,i;
if(l<h)
{
index=part(l,h,a);
quick(l,index-1,a);
quick(index+1,h,a);
}
}
void main()
{
int a[100],n,l,h,i;
cout<<"Enter number of elements:";
cin>>n;
cout<<"Enter the elements (Use Space As A Separator):";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\nInitial Array:\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
h=n-1;
l=0;
quick(l,h,a);
cout<<"\nAfter Sorting:\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
getch();
}
</pre>
<!-- INFOLINKS_ON -->
</div>
<br />
<h3 style="background-color: white; margin: 0px; position: relative;">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;"><b><u><i>Output of Program:</i></u></b></span></h3>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;"><b><u><i><br /></i></u></b></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizF4NdiFvyY-rgC9c5ubGMdj1X6I5hV4Eh1PrFg3sZ9-vw-buIr-SN0aVydLKIHNzMKHwAln_OItj65UOHNDdnOSlCxAyYgrGseX84fPQnIAvKx7XtWm5MnyngJ5Wfz7oKQ3A_O4c6g-Q/s1600/Quick+Sort+Algorithm+And+C%252B%252B+Code.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Quick Sort Algorithm And C++ Code" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizF4NdiFvyY-rgC9c5ubGMdj1X6I5hV4Eh1PrFg3sZ9-vw-buIr-SN0aVydLKIHNzMKHwAln_OItj65UOHNDdnOSlCxAyYgrGseX84fPQnIAvKx7XtWm5MnyngJ5Wfz7oKQ3A_O4c6g-Q/s1600/Quick+Sort+Algorithm+And+C%252B%252B+Code.png" title="Quick Sort Algorithm And C++ Code" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;"></span><br />
<div style="font-family: "Times New Roman"; font-size: medium;">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;"><b style="font-family: 'Courier New', Courier, monospace; font-size: x-large; line-height: 22px;">Please Comment If You Liked This Post !! </b></span></div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;">
</span>
<div style="font-family: "Times New Roman"; font-size: medium;">
<!-- INFOLINKS_OFF -->
<span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;"><span style="font-family: "trebuchet ms" , sans-serif; font-size: x-small;"><span style="background-color: white; line-height: 19.1875px;"><br /></span></span><span style="font-size: xx-small;"><span style="font-family: "trebuchet ms" , sans-serif;"><span style="background-color: white; line-height: 19.1875px;">This article uses material from the Wikipedia article </span></span><a href="https://en.wikipedia.org/wiki/Quicksort" rel="nofollow" style="background-color: #f9f9f9; font-family: "trebuchet ms", sans-serif; line-height: 15.8167px;" target="_blank">Quick Sort</a><span style="background-color: white; font-family: "trebuchet ms" , sans-serif; line-height: 19.1875px;"> </span><span style="background-color: white; font-family: "trebuchet ms" , sans-serif; line-height: 19.1875px;">which is released under the </span><span style="background-color: white; font-family: "trebuchet ms" , sans-serif; line-height: 19.1875px;"><a href="https://creativecommons.org/licenses/by-sa/3.0/" rel="nofollow" target="_blank">Creative Commons Attribution-Share-Alike License 3.0</a></span></span></span></div>
<span style="font-family: "georgia" , "times new roman" , serif; font-size: x-large;">
</span></div>
</div>
<!-- INFOLINKS_ON -->
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2017/01/quick-sort-algorithm-and-c-code.html",
"datePublished":"2017-01-02T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Quick Sort Algorithm And C++ Code",
"sameAs": "https://www.codingbot.net/2017/01/quick-sort-algorithm-and-c-code.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "99",
"bestRating": "100",
"ratingCount": "582"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-81987945609579682482016-12-27T02:41:00.003+05:302024-03-04T00:44:17.677+05:30Find Number Of Occurrences Of a Character In a String C Program<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; margin: 0px; position: relative; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif; font-size: large; font-weight: normal;">This program will find out the number of occurrences of each character in a string. So for example, if we have a string "I AM" then here the frequency of occurrence of each of 'I','A','M' will be 1. The program will print the same. This code can be easily modified to account for uppercase characters separately. </span><br />
<a name='more'></a></div>
<h4 style="background-color: white; margin: 0px; position: relative; text-align: left;">
<span class="mw-headline"><i><u><span style="font-family: "trebuchet ms" , sans-serif; font-size: x-large;"><span style="font-family: "droid sans";"><span style="line-height: 22px;"><br /></span></span></span></u></i></span></h4>
<h4 style="background-color: white; margin: 0px; position: relative; text-align: left;">
<span class="mw-headline"><i><u><span style="font-family: "trebuchet ms" , sans-serif; font-size: x-large;"><span style="font-family: "droid sans";"><span style="line-height: 22px;">Here is the C Code to </span></span><span style="font-family: "droid sans";"><span style="line-height: 22px;">find the number of occurrences of a character in a string<span style="font-family: "droid sans";">:</span></span></span></span></u></i></span></h4>
<div>
<span class="mw-headline"><i><u><span style="font-family: "trebuchet ms" , sans-serif; font-size: x-large;"><span style="font-family: "droid sans";"><span style="line-height: 22px;"><span style="font-family: "droid sans";"><br /></span></span></span></span></u></i></span></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char string[100];
int c = 0, count[26] = {0};
printf("Enter a string\n");
gets(string);
while (string[c] != '\0')
{
if (string[c] >= 'a' && string[c] <= 'z')
count[string[c]-'a']++;
c++;
}
for (c = 0; c < 26; c++)
{
if (count[c] != 0)
printf("%c occurs %d times in the entered string.\n",c+'a',count[c]);
}
}
</pre>
<!-- INFOLINKS_ON -->
<br />
<h4 style="text-align: left;">
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif; font-size: x-large; font-style: italic; font-weight: bold; text-decoration: underline;">Output:</span></h4>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWeh9l2ZoLSU2QLc7BL6aWEHo0FuDVNfP4dkcfM0xmNjmJ8CiDINRvFmdAZj0VpU0sOLS-dzMCtf6KtslTM29uzzIY_fHgFESLI26D5HtTrGu5SICGC4xFZXDlkj8pW2O6phkR1KWvhEI/s1600/Find+Number+Of+Occurrences+Of+a+Character+In+a+String+C+Program.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Find Number Of Occurrences Of a Character In a String C Program" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWeh9l2ZoLSU2QLc7BL6aWEHo0FuDVNfP4dkcfM0xmNjmJ8CiDINRvFmdAZj0VpU0sOLS-dzMCtf6KtslTM29uzzIY_fHgFESLI26D5HtTrGu5SICGC4xFZXDlkj8pW2O6phkR1KWvhEI/s1600/Find+Number+Of+Occurrences+Of+a+Character+In+a+String+C+Program.png" title="Find Number Of Occurrences Of a Character In a String C Program" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br /></div>
<div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-53226178720627427432016-12-27T02:18:00.002+05:302024-03-04T00:44:06.247+05:30C Code to transpose a matrix<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">Transposing a matrix means interchanging the rows and column elements of a matrix. For example, if we have a matrix:</span><span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"></span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">1 2 3</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">4 5 6</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">7 8 9</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">Then its transpose will be:</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">1 4 7</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">2 5 8</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;">3 6 9</span><br />
<span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"></span><br />
<a name='more'></a><span style="color: #444444; font-family: "trebuchet ms" , sans-serif;"><br /></span>
<br />
<h4 style="background-color: white; margin: 0px; position: relative; text-align: left;">
<span class="mw-headline"><i><u><span style="font-family: "trebuchet ms" , sans-serif; font-size: x-large;"><span style="font-family: "droid sans";"><span style="line-height: 22px;">Here is the C Code to </span></span><span style="font-family: "droid sans";"><span style="line-height: 22px;">find transpose of a matrix<span style="font-family: "droid sans";">:</span></span></span></span></u></i></span></h4>
<div>
<span class="mw-headline"><i><u><span style="font-family: "trebuchet ms" , sans-serif; font-size: x-large;"><span style="font-family: "droid sans";"><span style="line-height: 22px;"><span style="font-family: "droid sans";"><br /></span></span></span></span></u></i></span></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include<stdio.h>
#include<conio.h>
void main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of matrix\n");
for (c = 0; c < m; c++)
for(d = 0; d < n; d++)
scanf("%d",&matrix[c][d]);
for (c = 0; c < m; c++)
for( d = 0 ; d < n ; d++ )
transpose[d][c] = matrix[c][d];
printf("Transpose of entered matrix :-\n");
for (c = 0; c < n; c++) {
for (d = 0; d < m; d++)
printf("%d\t",transpose[c][d]);
printf("\n");
}
}
</pre>
<!-- INFOLINKS_ON -->
</div>
</div>
<h4 style="background-color: white; margin: 0px; position: relative; text-align: left;">
<br /><span style="font-family: "droid sans"; font-size: x-large;"><i><u>Output:</u></i></span></h4>
<div>
<span class="mw-headline"><i><u><span style="font-family: "trebuchet ms" , sans-serif; font-size: x-large;"><span style="font-family: "droid sans";"><span style="line-height: 22px;"><span style="font-family: "droid sans";"><br /></span></span></span></span></u></i></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHvpckHmpyXVTAG7GmDHARvzIF-MAvuGUyHyzwV0mBeSTGfG4qgzYO9dGZQEb3nYJicHXrKUE4ntj1gQ-G-1UTg3vnnCaCoVGjZh2kPW6sad2P9wKBVcASLENClhrmFgCEG0pSFKYWOrU/s1600/C+Code+to+transpose+a+matrix.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="C Code to transpose a matrix" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHvpckHmpyXVTAG7GmDHARvzIF-MAvuGUyHyzwV0mBeSTGfG4qgzYO9dGZQEb3nYJicHXrKUE4ntj1gQ-G-1UTg3vnnCaCoVGjZh2kPW6sad2P9wKBVcASLENClhrmFgCEG0pSFKYWOrU/s1600/C+Code+to+transpose+a+matrix.png" title="C Code to transpose a matrix" /></a></div>
<br /></div>
<div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-47060688660339636042016-12-25T02:42:00.003+05:302024-03-04T00:43:54.726+05:30Add Two Matrix C Code<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "trebuchet ms" , sans-serif;">This program will first ask user to enter the number of rows and columns for the two matrices. Remember, they have to be the same for both of the matrices. Then the program will ask the user to enter the elements of the first matrix and then the elements of the second matrix in the fashion:</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif;">First Matrix :-</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;">2 3</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;">4 5</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;">Second matrix :-</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;">3 4</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;">5 6</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;">then output of the program will be :-</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;">5 7</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;">9 11</span><br />
<a name='more'></a><br />
<br />
<h3 style="background-color: white; margin: 0px; position: relative;">
<span class="mw-headline"><i><u><span style="font-family: "trebuchet ms" , sans-serif; font-size: x-large;"><span style="font-family: "droid sans";"><span style="line-height: 22px;">Here is the C Code to </span></span><span style="font-family: "droid sans";"><span style="line-height: 22px;">Add Two Matrix<span style="font-family: "droid sans";">:</span></span></span></span></u></i></span></h3>
<br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include <stdio.h>
#include <conio.h>
void main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);
printf("Enter the elements of second matrix\n");
for (c = 0; c < m; c++)
for (d = 0 ; d < n; d++)
scanf("%d", &second[c][d]);
printf("Sum of entered matrices:-\n");
for (c = 0; c < m; c++) {
for (d = 0 ; d < n; d++) {
sum[c][d] = first[c][d] + second[c][d];
printf("%d\t", sum[c][d]);
}
printf("\n");
}
}
</pre>
<!-- INFOLINKS_ON -->
<br />
<br />
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif; font-size: x-large; font-style: italic; font-weight: bold; text-decoration: underline;">Output:</span><br />
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif; font-size: x-large; font-style: italic; font-weight: bold; text-decoration: underline;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLwCwgTtRmdyy6gbPIRID8ir4qPMwSJ-d8qTRwqCagZsfsWrI5rRS1PZTWX3Ums7XNxCAOFtZvFdFpszzF9p8Q46_vBJPfgbhQZeq_lNXJJKTCFAPrr72kmIQzaPSxMmmJr90fOo9DJe8/s1600/Add+Two+Matrix+C+Code.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Add Two Matrix C Code" border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLwCwgTtRmdyy6gbPIRID8ir4qPMwSJ-d8qTRwqCagZsfsWrI5rRS1PZTWX3Ums7XNxCAOFtZvFdFpszzF9p8Q46_vBJPfgbhQZeq_lNXJJKTCFAPrr72kmIQzaPSxMmmJr90fOo9DJe8/s640/Add+Two+Matrix+C+Code.png" title="Add Two Matrix C Code" width="640" /></a></div>
<span style="background-color: white; font-family: "trebuchet ms" , sans-serif; font-size: x-large; font-style: italic; font-weight: bold; text-decoration: underline;"><br /></span></div>
<div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-2073802037985910102014-10-24T16:53:00.002+05:302024-03-04T00:43:30.869+05:30How to get invited for Inbox by Gmail<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="tr_bq" dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif;">Google has just started sending out invites for its new email system; an alternative to Gmail. Its called Inbox. Nope, its not public yet. Instead Google decided to use the "invite only" approach for the time being. Here's a sneak peak:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
</div>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<center>
<iframe allowfullscreen="" frameborder="0" height="360" src="https://www.youtube-nocookie.com/embed/bzNTjpUMOp4" width="640"></iframe></center>
</div>
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Inbox is different from Gmail, designed to focus on what really matters; as reported on this <a href="https://gmailblog.blogspot.in/2014/10/an-inbox-that-works-for-you.html" rel="nofollow" target="_blank">Official Google Post</a>:</span><br />
<blockquote style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="line-height: 20.7999992370605px;">Email started simply as a way to send digital notes around the office. But fast-forward 30 years and with just the phone in your pocket, you can use email to contact virtually anyone in the world…from your best friend to the owner of that bagel shop you discovered last week. </span></span><span style="font-family: Arial, Helvetica, sans-serif;"><br style="line-height: 20.7999992370605px;" /></span><span style="font-family: Arial, Helvetica, sans-serif;"><span style="line-height: 20.7999992370605px;">With this evolution comes new challenges: we get more email now than ever, important information is buried inside messages, and our most important tasks can slip through the cracks—especially when we’re working on our phones. For many of us, dealing with email has become a daily chore that distracts from what we really need to do—rather than helping us get those things done.</span></span></blockquote>
<div style="text-align: center;">
<span style="font-family: Arial, Helvetica, sans-serif;"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoBb1FU-pzpg2QrDmB2M8ENYyVI3uiNMS8k9z5T-aTHZHL_gaSFgWHST9lqGKoIBCWqhTIIli5yujcRH7aZCbnE8okfZPZSuudR1b9Bo-2TKDP4d1m2thU9St68pjh-9RKgpq4eKTyzC4/s400/bigtopblog_fullres.gif" height="236" width="400" /> </span></div>
<div style="text-align: center;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Google has begun to roll out a second wave of invites, following yesterday's first batch. You can even invite your friends. While not everyone who registered, got an invite, be sure to check out your inbox in case you receive it. Inbox can be said as an intelligent version of Gmail. It offers an intelligent system to sort out information and bundle things into groups, so you can easily figure out what's worth reading anyway. Besides this, it offers the ability to act as a personal assistant with reminders, create to-do lists and snooze items.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Assist functionality will even help you make better reminders, for example, if you write a reminder to call the grocery store, Inbox will supply the store's phone number and tell you if it's open or not. Assist works for your email also. If you make reservation for a restaurant online, it adds a map to your confirmation email. Book a train online and Inbox provides a link to check-in.</span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMVEAAOXUaj1k2MZofbgfCCTVheRGd1e1POW1e6IX-ZX1HD_EysYAnhqz5ZsT4bJvRGs0452FhQK6fTb3PV6d6GCyyQzB2wsmRIjXviQglSCYSCmj8W9UJLl54C1CChIS8O42aR-B1ye0/s1600/Inbox+by+Gmail+-+www.codingbot.net.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Inbox by Gmail" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMVEAAOXUaj1k2MZofbgfCCTVheRGd1e1POW1e6IX-ZX1HD_EysYAnhqz5ZsT4bJvRGs0452FhQK6fTb3PV6d6GCyyQzB2wsmRIjXviQglSCYSCmj8W9UJLl54C1CChIS8O42aR-B1ye0/s1600/Inbox+by+Gmail+-+www.codingbot.net.png" height="393" title="Inbox by Gmail" width="640" /></a></div>
<b><u><span style="font-family: Arial, Helvetica, sans-serif;">HOW TO GET AN INVITE:</span></u></b></div>
<div style="text-align: left;">
<b><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">It's as simple as sending a mail. Just send an email to <a href="mailto:inbox@google.com">inbox@google.com</a> to request your invitation.</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<b><u><span style="font-family: Arial, Helvetica, sans-serif;">DOWNLOAD:</span></u></b></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;">Cannot wait for your invite? Well, I have a solution for you. Download this apk file which is signed by Google and it updates your existing app.</span></div>
<div style="text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><span class="fontblue"><span style="background: white; color: #c0504d; line-height: 115%;"><b>File name:</b></span></span><span class="fontblue"><span style="background: white; color: #16acc2; line-height: 115%;"> </span></span><span style="background: white; color: #333333; line-height: 115%;">com.google.android.apps.inbox-1.0_(78094151)-5608113-minAPI16.apk</span><span style="color: #333333; line-height: 115%;"><br style="box-sizing: border-box;" />
</span><span class="fontblue"><span style="background: white; color: #c0504d; line-height: 115%;"><span style="box-sizing: border-box;"><b>Version:</b></span></span><span class="fontblue"><span style="background: white; color: #16acc2; line-height: 115%;"> </span></span></span><span style="background: white; color: #333333; line-height: 115%;">1.0 (78094151) (5608113)</span><span style="color: #333333; line-height: 115%;"><br style="box-sizing: border-box;" /></span><span class="fontblue"><b><span style="background: white; color: #c0504d; line-height: 115%;"><span style="box-sizing: border-box;">File size:</span></span><span class="fontblue"><span style="background: white; color: #16acc2; line-height: 115%;"> </span></span></b></span><span style="background: white; color: #333333; line-height: 115%;">36.05 MB (37,804,961 bytes)</span><span style="color: #333333; line-height: 115%;"><br style="box-sizing: border-box;" />
</span><span class="fontblue"><span style="background: white; color: #c0504d; line-height: 115%;"><span style="box-sizing: border-box;"><b>Minimum Android version:</b></span></span><span class="fontblue"><span style="background: white; color: #16acc2; line-height: 115%;"> </span></span></span><span style="background: white; color: #333333; line-height: 115%;">Android 4.1+ (Jelly Bean, API
16)</span><span style="color: #333333; line-height: 115%;"><br style="box-sizing: border-box;" />
</span><span class="fontblue"><b><span style="background: white; color: #c0504d; line-height: 115%;"><span style="box-sizing: border-box;">MD5:</span></span><span class="fontblue"><span style="background: white; color: #16acc2; line-height: 115%;"> </span></span></b></span><span style="background: white; color: #333333; line-height: 115%;">9059c483fc3e22218877b4b9be948f83</span><span style="color: #333333; line-height: 115%;"><br style="box-sizing: border-box;" />
</span><span class="fontblue"><span style="background: white; color: #c0504d; line-height: 115%;"><span style="box-sizing: border-box;"><b>SHA1</b>:</span></span><span class="fontblue"><span style="background: white; color: #16acc2; line-height: 115%;"> </span></span></span><span style="background: white; color: #333333; line-height: 115%;">accc1fa6a577e80f2c855a7311c50fa5b02f79a8</span></span></div>
<div class="MsoNormal">
<span style="background: white; color: #333333; line-height: 115%;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="background: white; color: #333333; line-height: 115%;"><a href="https://q.gs/7jPx0" rel="nofollow" target="_blank"><span style="font-family: Arial, Helvetica, sans-serif;"><b>DOWNLOAD LINK</b></span></a></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">(You'll need an invite to use this ;)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Arial, Helvetica, sans-serif;">Did you receive an invite? Share your experience with us. I shall get back to you once I'll receive my invite.</span></div>
</div>
<div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-89329213335400767782014-06-08T00:05:00.000+05:302019-04-14T18:58:47.521+05:30Make Codes Postable - HTML Friendly<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
Make Codes Postable - HTML Friendly</h3>
<span style="font-family: inherit; font-size: large;">So you're one of the developers who is tired of making is code HTML Friendly, changing '<' to '&lt;' and </span><span style="font-family: inherit; font-size: large;">using '&amp;' in place of '&'. Making changes in a long code can be very much time consuming especially if you don't have time for this and want to this in fraction of a second.</span><br />
<span style="font-family: inherit;"><span style="font-size: large;"><br /></span>
<span style="font-size: large;">Well if you're reading this, you've come to the right place and we're gonna do it for you - for FREE!! The following section will be very much useful for Web Developers. Basically what we do is, we make appropriate modifications in the code, replace x with y, a with b etc. All you have to do is paste your code in the following box and click on 'Make Friendly' button. You're modified code will appear in the same box. Now your code is ready copying and using it.</span></span><br />
<br />
<br />
<br />
<div style="text-align: center;">
<span style="color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-large;"><i><u>Make Codes Postable - HTML Friendly</u></i></span></div>
</div>
<script type="text/javascript">
function codingbot(){
var re=/[(<>"'&]/g
for (zebra=0; zebra<arguments.length; zebra++)
arguments[zebra].value=arguments[zebra].value.replace(re, function(m){return rep(m)})
}
function rep(match){
if (match=="<")
return "<"
else if (match==">")
return ">"
else if (match=="'")
return "'"
else if (match=="\"")
return """
else if (match=="(")
return "("
else if (match=="&")
return "&"
else if (match==")")
return ")"
}
</script><br />
<form>
<textarea name="dat" style="height: 298px; margin: 0px; width: 99%;"></textarea><br />
<br />
<center>
<input class="button small orange" onclick="codingbot(this.form.dat)" onmouseout="this.className='button small blue'" onmouseover="this.className='button small green'" type="button" value="Make Friendly" /> <input class="button small orange" onmouseout="this.className='button small gray'" onmouseover="this.className='button small green'" type="reset" value="Clear Everything" /></center>
</form>
</div>
<br />
<br /></div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2014/06/make-codes-postable-html-friendly.html",
"datePublished":"2014-06-08T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Make Codes Postable - HTML Friendly",
"sameAs": "https://www.codingbot.net/2014/06/make-codes-postable-html-friendly.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "91",
"bestRating": "100",
"ratingCount": "4209"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Unknownnoreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-68364829089741321522014-06-06T22:02:00.001+05:302024-03-04T00:43:01.950+05:30[SOLVED] Joomla -This email address is being protected from spambots. You need JavaScript enabled to view it.<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;">This is one of the most common errors in Joomla. <b>This email address is being protected from spambots. You need JavaScript enabled to view it. </b>This usually occurs when you've included an email address in a Joomla article and you want to protect it from Email harvesting spambots. </span><br />
<span style="font-size: large;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">You would've most probably used a built-in feature of joomla, i.e. enabled <b><span style="color: #674ea7;">Content - Email Cloaking plugin</span>, </b>which basically does nothing but 'cloaks' the email address. It basically gives access to the email ID only to legitimate users who'll read and click on the message "<b><i><span style="color: #e06666;">This email address is being protected from spambots. You need JavaScript enabled to view it.</span></i></b>" so that it'll show the email in a separate window.</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKElzMoMVRfhbEQbZWbyd0pQc33azawHBysxNQVvo7ghtn4ip9a-ITcIQVQ_UuySCKZCvDj3aBhDf8rjvsr24sDgLIwyABbV2Qql35woEHzebXkbvw6NB4abGUt-U69tWKsuCg4-Hy8l8/s1600/%5BSOLVED%5D+Joomla+-This+email+address+is+being+protected+from+spambots%5Bwww.codingbot.net%5D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="[SOLVED] Joomla -This email address is being protected from spambots. You need JavaScript enabled to view it." border="2" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKElzMoMVRfhbEQbZWbyd0pQc33azawHBysxNQVvo7ghtn4ip9a-ITcIQVQ_UuySCKZCvDj3aBhDf8rjvsr24sDgLIwyABbV2Qql35woEHzebXkbvw6NB4abGUt-U69tWKsuCg4-Hy8l8/s1600/%5BSOLVED%5D+Joomla+-This+email+address+is+being+protected+from+spambots%5Bwww.codingbot.net%5D.jpg" height="315" title="[SOLVED] Joomla -This email address is being protected from spambots. You need JavaScript enabled to view it." width="640" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;">After enabling the plugin, this error would be visible onto every page where you have displayed some email ID. However no need to panic. The solution is as simple as a click:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<h2 style="text-align: left;">
<span style="color: red; font-family: Trebuchet MS, sans-serif;">How to disable the email cloaking plug-in:</span></h2>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;">1. Login into Admin Panel -> Extentions -> Plugin Manager</span></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;">2. In the <i>filter</i> field, search for "Content - Email Cloaking". </span><br />
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;">3. Under <i>Status, </i>tick on the 'green tick' to disable the plugin.</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVCHcPhGwcFsNxx8-27Ll9cPPuKHWjBZ2n4dDRDzwL_aiCAGikeW3EgTU3nuPLysasl69V-dpFKDPbn6ZxSb6tPZjrXstVmAXl_5FYIrtD3IKbK6ThmOHEom3R1_jvgIK0mjtyAFJSxr4/s1600/%5BSOLVED%5D+Joomla+-This+email+address+is+being+protected+from+spambots1%5Bwww.codingbot.net%5D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="[SOLVED] Joomla -This email address is being protected from spambots. You need JavaScript enabled to view it." border="2" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVCHcPhGwcFsNxx8-27Ll9cPPuKHWjBZ2n4dDRDzwL_aiCAGikeW3EgTU3nuPLysasl69V-dpFKDPbn6ZxSb6tPZjrXstVmAXl_5FYIrtD3IKbK6ThmOHEom3R1_jvgIK0mjtyAFJSxr4/s1600/%5BSOLVED%5D+Joomla+-This+email+address+is+being+protected+from+spambots1%5Bwww.codingbot.net%5D.jpg" height="388" title="[SOLVED] Joomla -This email address is being protected from spambots. You need JavaScript enabled to view it." width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;">4. Verify from below that you've successfully disabled the plugin.</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://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhAmiXXI2AMsWxxS_9HHcQFwrqbyRoCW_beG-F9UbLWlIvCqq8NWGwHB_2obhf-nMN6HtsoUZAJRhqNcEtHDEIMd5BW9IMpcMp2Vv80U_W9D0HCbBvMUfGhntu9zGfKgu7ChO3jey5dC0/s1600/%5BSOLVED%5D+Joomla+-This+email+address+is+being+protected+from+spambots2%5Bwww.codingbot.net%5D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="[SOLVED] Joomla -This email address is being protected from spambots. You need JavaScript enabled to view it." border="2" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhAmiXXI2AMsWxxS_9HHcQFwrqbyRoCW_beG-F9UbLWlIvCqq8NWGwHB_2obhf-nMN6HtsoUZAJRhqNcEtHDEIMd5BW9IMpcMp2Vv80U_W9D0HCbBvMUfGhntu9zGfKgu7ChO3jey5dC0/s1600/%5BSOLVED%5D+Joomla+-This+email+address+is+being+protected+from+spambots2%5Bwww.codingbot.net%5D.jpg" height="390" title="[SOLVED] Joomla -This email address is being protected from spambots. You need JavaScript enabled to view it." width="640" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="font-size: large;">Please Comment If You Liked The Post.</span></span></div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2014/06/solved-joomla-this-email-address-is.html",
"datePublished":"2019-04-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "[SOLVED] Joomla -This email address is being protected from spambots. You need JavaScript enabled to view it.",
"sameAs": "https://www.codingbot.net/2014/06/solved-joomla-this-email-address-is.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "92",
"bestRating": "100",
"ratingCount": "1235"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-3713738143554795242013-11-19T13:51:00.001+05:302024-03-04T00:42:33.440+05:30Calculate Roots Of a Quadratic Equation Using C Program<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Trebuchet MS, sans-serif;">Hi everyone</span><br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;">In this post, we're going how to write a C program to calculate the roots of a quadratic equation. As we know that a quadratic equation is of a form like:</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div style="text-align: center;">
<span style="background-color: white; color: #444444; line-height: 16px;"><span style="font-family: Trebuchet MS, sans-serif;"> <b><span style="font-size: large;">ax^2+bx+c=0</span></b></span></span></div>
<div style="text-align: left;">
<span style="background-color: white; color: #444444; line-height: 16px;"><span style="font-family: Trebuchet MS, sans-serif;"><b><span style="font-size: large;"><br /></span></b></span></span></div>
<div style="text-align: left;">
<span style="background-color: white; color: #444444; line-height: 16px;"><span style="font-family: Trebuchet MS, sans-serif;">So we won't go into much details. Also you guys must be knowing to calculate the roots of a quadratic equation directly, having formula:</span></span></div>
<div style="text-align: left;">
<span style="background-color: white; color: #444444; line-height: 16px;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span></span></div>
<div style="text-align: center;">
<span style="font-size: large;"><span style="font-family: Trebuchet MS, sans-serif;"><span style="line-height: 16px;"><span style="color: #444444;">Roots = </span><span style="color: red;">( -b + (b^2 - 4ac) ) / 2a </span><span style="color: #444444;">& </span></span></span><span style="color: blue;"><span style="font-family: 'Trebuchet MS', sans-serif; line-height: 16px;">( -b -</span><span style="font-family: 'Trebuchet MS', sans-serif; line-height: 16px;"> (b^2 - 4ac) ) / 2a</span></span></span></div>
<div style="text-align: center;">
<span style="font-size: large;"><span style="color: blue;"><span style="font-family: 'Trebuchet MS', sans-serif; line-height: 16px;"><br /></span></span></span></div>
<div style="text-align: left;">
<span style="font-family: 'Trebuchet MS', sans-serif; line-height: 16px;">So we are just going to use the same formula in our C code. So Let's begin...</span></div>
<div style="text-align: left;">
<span style="font-family: 'Trebuchet MS', sans-serif; line-height: 16px;"><br /></span></div>
<div style="text-align: left;">
<h2 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><i><u>C Program To Calculate Roots Of a Quadratic Equation:</u></i></span></h2>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,root1,root2,x,real,im;
clrscr();
printf("-> Quadratic Equation Form: ax2+bx+c");
printf("\n\nEnter the value of a: ");
scanf("%f",&a);
printf("\nEnter the value of b: ");
scanf("%f",&b);
printf("\nEnter the value of c: ");
scanf("%f",&c);
x = (b*b)-(4*a*c);
if(x>0)
{
root1 = (-b+sqrt(x))/(2*a);
root2 = (-b-sqrt(x))/(2*a); //ROOTS ARE UNIQUE
printf("\nThe roots of the equation are: %.2f and %.2f",root1,root2);
}
else if(x==0)
{
root1 = -b/(2*a);
root2 = root1; //ROOTS ARE SAME
printf("\nThe roots of the equation are: %.2f and %.2f",root1,root2);
}
else
{
real = -b/(2*a);
im = sqrt(-x)/(2*a); // ROOTS ARE COMPLEX
printf("\nThe roots of the equation are: %.2f+j%.2f and %.2f-j%.2f",real,im,real,im);
}
getch();
}</pre>
<!-- INFOLINKS_ON -->
<div>
<span style="font-family: Georgia, 'Times New Roman', serif; font-size: large;"><br /></span>
<br />
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;">Program Explanation:</span></u></i></h2>
<span style="font-family: Georgia, 'Times New Roman', serif; font-size: large;">The program is self explanatory in itself. First we take the coefficients of the quadratic equation as input from the user. Then on the basis of its determinant,i.e, </span><u style="font-family: Georgia, 'Times New Roman', serif; font-size: x-large;">b^2 - 4*a*c</u><span style="font-family: Georgia, 'Times New Roman', serif; font-size: large;">, if its greater than 0 or equal to 0 or less than 0. In each of the case, we can get different types of roots, Unique, Equal or Complex respectively. Using the formula as I described in the beginning of this post, we calculate roots, with an exception in case of complex roots, whereby, we have to find real and imaginary parts of the roots individually, using the formula:</span><br />
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="font-weight: normal;">Real Part = </span><b><u>-b/(2*a)</u></b></span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Imaginary<span style="font-weight: normal;"> Part = </span><b><u>sqrt(-x)/(2*a)</u></b><span style="font-weight: normal;"> -> Since determinant is negative here, we make it positive by multiplying an extra '-'.</span></span></div>
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><br /></span></u></i></h2>
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;">Program Output:</span></u></i></h2>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbWp8JvninootttfpxtmqXgM9J_83-k2SrsKBb6ckGsaNzWnqRIs-zjfeawf_KVZVttddGwE_esQbVLtySAtgSqeokL4G5W7XlrXAGIzBV0WBNHvP17J6OeXDeAkp7AHGgRpA2Kj-VW80/s1600/C+Program+To+Calculate+Roots+Of+a+Quadratic+Equation-CODINGBOT.net.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="C Program To Calculate Roots Of a Quadratic Equation" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbWp8JvninootttfpxtmqXgM9J_83-k2SrsKBb6ckGsaNzWnqRIs-zjfeawf_KVZVttddGwE_esQbVLtySAtgSqeokL4G5W7XlrXAGIzBV0WBNHvP17J6OeXDeAkp7AHGgRpA2Kj-VW80/s640/C+Program+To+Calculate+Roots+Of+a+Quadratic+Equation-CODINGBOT.net.jpg" height="384" title="C Program To Calculate Roots Of a Quadratic Equation" width="640" /></a></div>
<div>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><br /></span></u></i></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace; font-size: large; font-weight: bold;">Please Comment If You Liked The Post.</span></div>
</div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2013/11/calculate-roots-of-quadratic-equation.html",
"datePublished":"2019-04-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Download You Tube Videos & You Tube To MP3 Converter FREE",
"sameAs": "https://www.codingbot.net/2013/11/calculate-roots-of-quadratic-equation.htmll",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "89",
"bestRating": "100",
"ratingCount": "1148"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-60743205840671340262013-08-06T00:25:00.001+05:302024-03-04T00:42:21.435+05:30C Code To Concatenate Two Strings<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Trebuchet MS, sans-serif;">Hello guys,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">In this post, I'll explain the C Code To Concatenate Two Strings. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br />
As we all know that, the process of appending one string to the end of another string is called concatenation. If s1 and s2 are two strings and when s2 is appended to the end of s1, s1 and s2 are said to be concatenated. The string s1 then contains the original string plus the string contained in s2. Similar to copying and comparing, appending s2 to s1 should be done on a character by character basis. C provides strcat() built-in function to concatenate two strings.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br />
The prototype of strcat() is as follows:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"> <b>strcat(s1,s2);</b></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<h2 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><i><u>C Program To Concate</u></i><i><u>nate Two Strings:</u></i></span></h2>
</div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str1[20]="abc", str2[20]="def", str3[20]="ghi";
int i,j;
clrscr();
printf("str1 = %s | str2 = %s \n",str1,str2);
/* Concatenation of str1 and str2 without using strcat() begins */
for(i=0 ; str1[i]!='\0' ; i++);
for(j=0 ; str2[j]!='\0' ; j++)
{
str1[i+j] = str2[j];
}
str1[i+j]='\0';
printf("\nAfter concatenation str1 = %s \n",str1);
/* Concatenation of str1 and str2 without using strcat() begins */
strcat(str1,str3);
printf("\nstr1 = '%s' \n",str1);
strcat(str1,"jkl");
printf("\nstr1 = '%s' \n",str1);
printf("\n\n *WWW.CODINGBOT.NET*");
getch();
}</pre>
<!-- INFOLINKS_ON -->
<br />
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;">Program Explanation:</span></u></i></h2>
<h2>
<div>
<div style="font-weight: normal;">
<span style="font-family: Trebuchet MS, sans-serif; font-size: small;">Str1, str2 and str3 are declared to be arrays of char type and all are initialized strings. The integer variables i and j are to traverse the strings. String in str2 is appended to the end of the string in str1 by following segment of the program:</span></div>
<div style="font-weight: normal;">
<span style="font-family: Trebuchet MS, sans-serif; font-size: small;"><br /></span></div>
<blockquote class="tr_bq">
<span style="font-family: Trebuchet MS, sans-serif; font-size: small;">for(i=0 ; str1[i]!='\0' ; i++);<br />for(j=0 ; str2[j]!='\0' ; j++)<br />{<br />str1[i+j] = str2[j];<br />}<br />str1[i+j] = '\0';</span></blockquote>
<span style="font-family: Trebuchet MS, sans-serif; font-size: small;"><span style="font-weight: normal;">The first for loop is to simply scan through the string str1. When the loop completes, the variable i points to the position of null character '\0' in str1. The second loop is to scan through the second string str2 till end of it is reached. When j takes 0, the first character in str2 is assigned to the position of null character in str1. So, the null character is str1 is overwritten by the first character in str2. Subsequently, the remaining characters in str2 are appended to str1 and lastly, the null character '\0' is assigned to the last position of str1. The string in str1, "abcdef" is then displayed.</span></span><br />
<span style="font-weight: normal;"><span style="font-family: Trebuchet MS, sans-serif; font-size: small;"><br /></span></span>
<span style="font-weight: normal;"><span style="font-family: Trebuchet MS, sans-serif; font-size: small;">Then two calls are mode to strcat(). In the final call, strcat(str1,str3), str3 is appended to str1. Since str3 had "ghi", sstr1 now becomes "abcdefghi" and is displayed. On the second call, strcat(str,"jkl"), the string constant "jkl" is appended to str1. The new string "abcdefghijkl" in str1 is again displayed.</span></span></div>
</h2>
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;">Program Output:</span></u></i></h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsbGMfAYWSZNpDwVhP9QOaw1muDyNizy7XBkhqQHANUuitbKwZxtHKRB4Hi6LRkMO4A27oxj4Wc-oSjJpszHhNHaj92fvOxHwQ-9rTyZdGkGVA1oHnW4gXRCWXxACNYVC0_JED0lSXl3k/s1600/C+Code+To+Concatenate+Two+Strings.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="C Code To Concatenate Two Strings" border="0" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsbGMfAYWSZNpDwVhP9QOaw1muDyNizy7XBkhqQHANUuitbKwZxtHKRB4Hi6LRkMO4A27oxj4Wc-oSjJpszHhNHaj92fvOxHwQ-9rTyZdGkGVA1oHnW4gXRCWXxACNYVC0_JED0lSXl3k/s640/C+Code+To+Concatenate+Two+Strings.jpg" title="C Code To Concatenate Two Strings" width="640" /></a></div>
<div>
<i style="font-size: 24px; font-weight: bold;"><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"></span></u></i><br />
<div class="separator" style="clear: both; margin: 0px; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; margin: 0px; text-align: left;">
<b style="font-family: 'Courier New', Courier, monospace; font-size: medium; font-style: normal;"><span style="font-size: large;"><u>Please Comment If You Liked The Post</u>.</span></b></div>
</div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2013/08/c-code-to-concatenate-two-strings.html",
"datePublished":"2019-04-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "C Code To Concatenate Two Strings",
"sameAs": "https://www.codingbot.net/2013/08/c-code-to-concatenate-two-strings.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "95",
"bestRating": "100",
"ratingCount": "409"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-27899366995915144352013-08-04T02:10:00.001+05:302024-03-04T00:42:05.248+05:30C Code To Find The Length Of a String<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Trebuchet MS, sans-serif;">Hello guys,</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">In this post, I'll explain the C Code how to find the length of a string, by 2 methods, first by using strlen() function and second by normal programming.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Length of a string is defined to be the number of characters in it excluding the null character '\0'. To find the length of a string, we need to scan through the string, count the number of characters till the null character is reached. C provides a built-in function namely, strlen() to find the length of a string. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<h2 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><i><u>C Program To Find The Length Of a String:</u></i></span></h2>
<br /></div>
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str[100];
int i,length;
clrscr();
printf("Enter a String: ");
gets(str);
/* Finding the length of str without using strlen() begins */
length=0;
for(i=0 ; str[i]!='\0' ; i++)
length++;
printf("\nLength of '%s' = %d\n",str,length);
/* Finding the length of str using strlen() begins */
length = strlen(str);
printf("Length of '%s' using strlen = %d \n",str,length);
printf("\n\n *WWW.CODINGBOT.NET*");
getch();
}</pre>
<!-- INFOLINKS_ON -->
<br />
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;">Program Explanation:</span></u></i></h2>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">str is declared to be an array of char type and of size 100. Length and i are declared to be variables of int type. str is to collect the input string. Variable length is to collect the length of the string in str. The variable i is to scan through the string accessing each character.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">A string is read into str through the keyboard The following segment finds the length of str without strlen():</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"> <b> length = 0;</b></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><b> for(i=0 ; str[i] != '\0' ; i++)</b></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><b> </b></span><span style="font-family: 'Trebuchet MS', sans-serif;"><b> length++;</b></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><b><br /></b></span>
<span style="font-family: Trebuchet MS, sans-serif;">Length is initialized to 0 before scanning through the string begins. When the loop is entered, scanning through the string begins. During the course of scanning, if the character is not fund to be null character '\0', length is incremented by one. The loop is exited when the null character is reached. So, when the loop completes, length collects the length of str.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">The length of str is found out using strlen() built-in function also.</span></div>
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;">Program Output:</span></u></i></h2>
<h2>
<br /><i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHojvREasg0RnfH5SDaH6R5xKVYFFQdw9BBERagpjKjuRnhrCqki6qkZyKHicQeraDL62QDfpAN6Tfuu4BgRWZSp23rfE-__85WSGePPLgO3mWIzY6dEH7kggAefPCMIYS2R6wbZ5DLJQ/s1600/C+Code+To+Find+The+Length+Of+a+String.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="C Code To Find The Length Of a String" border="0" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHojvREasg0RnfH5SDaH6R5xKVYFFQdw9BBERagpjKjuRnhrCqki6qkZyKHicQeraDL62QDfpAN6Tfuu4BgRWZSp23rfE-__85WSGePPLgO3mWIzY6dEH7kggAefPCMIYS2R6wbZ5DLJQ/s640/C+Code+To+Find+The+Length+Of+a+String.jpg" title="C Code To Find The Length Of a String" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b style="font-family: 'Courier New', Courier, monospace; font-size: medium; font-style: normal;"><span style="font-size: large;">Please Comment If You Liked The Post.</span></b></div>
</span></u></i></h2>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2013/08/c-code-to-find-length-of-string.html",
"datePublished":"2019-04-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "C Code To Find The Length Of a String",
"sameAs": "https://www.codingbot.net/2013/08/c-code-to-find-length-of-string.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "94",
"bestRating": "100",
"ratingCount": "6324"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-88577666123687956722013-07-24T19:20:00.001+05:302024-03-04T00:41:49.492+05:30C Program To Find The Number Of Occurrences Of a Character In a String<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: 'Trebuchet MS', sans-serif; font-size: large;">Hello Guys,</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif; font-size: large;">In this post, I'll explain how to find the number of occurrences of a character in a string, program for which is really very simple.</span><br />
<span style="font-size: large;"><span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></span>
<span style="font-size: large;"><span style="font-family: 'Trebuchet MS', sans-serif;"><u>A string is C is defined to be sequence of characters terminated by the special character '\0'. The special character '\0' is called the Null Character and it is to indicate the end of a string.</u></span></span><br />
<span style="font-size: large;"><span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></span>
<span style="font-size: large;"><span style="font-family: 'Trebuchet MS', sans-serif;">Let us straight away understand the following program.</span></span><br />
<span style="font-size: large;"><span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="color: red;">str</span> is declared to be a string variable of size 100. This length can be varied according to user. I have taken it to be 100 so that a sentence can be easily accommodated. Its work is to collect a string(input) from the user. </span></span><br />
<span style="font-size: large;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><span style="color: blue;">ch</span> is declared to be a variable of char type and it is to collect a character(input), the number of occurrences of which in </span><span style="color: red; font-family: 'Trebuchet MS', sans-serif;">str</span><span style="font-family: Trebuchet MS, sans-serif;"> is to be found out. <span style="color: #274e13;">i</span> and <span style="color: magenta;">count</span> are declared to be variable of int type. the variable </span><span style="color: #274e13; font-family: 'Trebuchet MS', sans-serif;">i</span><span style="font-family: Trebuchet MS, sans-serif;"> is used to traverse the characters in </span><span style="color: red; font-family: 'Trebuchet MS', sans-serif;">str</span><span style="font-family: Trebuchet MS, sans-serif;"> and </span><span style="color: magenta; font-family: 'Trebuchet MS', sans-serif;">count</span><span style="font-family: Trebuchet MS, sans-serif;"> is to collect the number of occurrences of </span><span style="color: blue; font-family: 'Trebuchet MS', sans-serif;">ch</span><span style="font-family: Trebuchet MS, sans-serif;"> in </span><span style="color: red; font-family: 'Trebuchet MS', sans-serif;">str</span><span style="font-family: Trebuchet MS, sans-serif;">(output).</span></span><br />
<span style="font-size: large;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">After a string is accepted into </span><span style="color: red; font-family: 'Trebuchet MS', sans-serif;">str</span><span style="font-family: 'Trebuchet MS', sans-serif;">, a for loop is set up to traverse each character of the string. Within the body of the loop, each character of the string is checked against </span><span style="color: blue; font-family: 'Trebuchet MS', sans-serif;">ch</span><span style="font-family: 'Trebuchet MS', sans-serif;"> for equality.</span></span><br />
<span style="font-size: large;"><span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">In case of a match, the variable </span><span style="color: magenta; font-family: 'Trebuchet MS', sans-serif;">count</span><span style="font-family: Trebuchet MS, sans-serif;"> is incremented. When this loop exits, the variable </span><span style="color: magenta; font-family: 'Trebuchet MS', sans-serif;">count</span><span style="font-family: Trebuchet MS, sans-serif;"> will have the number of occurrences of the given character in the given string.</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><i><u>C Program To Find The Number Of Occurrences Of a Character In a String:</u></i></span></h2>
<br />
<br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include<stdio.h>
#include<conio.h>
void main()
{
char str[100], ch;
int i, count;
clrscr();
printf("Enter a String: ");
gets(str);
fflush(stdin);
printf("\nEnter a Character: ");
scanf("%c",&ch);
/* Finding the no. of occurrences of character 'ch' in 'str' begins */
count=0;
for(i=0 ; str[i]!='\0' ; i++)
if(str[i]==ch)
count++;
/* Find the no. of occurrences of 'ch' in 'str' ends */
printf("\nNo. of occurrences of '%c' in '%s' is %d",ch,str,count);
getch();
}</pre>
<!-- INFOLINKS_ON -->
<div>
<br />
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;">Program Output:</span></u></i></h2>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4P90OwTt0VjZZ5hPkQZ9NbYtDxr2c3q3ytlyVz06vCFB5AMcTEtr33aptchn41egzRwup6qyo6pwFK5L0xViM0p_mYG3lkqvkiJtuVk8beLCmrngh-IMPTwqM0IGcJNwMkDJNOYH8bVI/s1600/C+Program+To+Find+The+Number+Of+Occurences+Of+a+Character+In+a+String.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="C Program To Find The Number Of Occurrences Of a Character In a String" border="0" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4P90OwTt0VjZZ5hPkQZ9NbYtDxr2c3q3ytlyVz06vCFB5AMcTEtr33aptchn41egzRwup6qyo6pwFK5L0xViM0p_mYG3lkqvkiJtuVk8beLCmrngh-IMPTwqM0IGcJNwMkDJNOYH8bVI/s640/C+Program+To+Find+The+Number+Of+Occurences+Of+a+Character+In+a+String.jpg" title="C Program To Find The Number Of Occurrences Of a Character In a String" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<div>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><br /></span></u></i></div>
<b style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: large;">Please Comment If You Liked The Post.</span></b></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2013/07/c-program-to-find-number-of-occurrences.html",
"datePublished":"2019-04-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "C Program To Find The Number Of Occurrences Of a Character In a String",
"sameAs": "https://www.codingbot.net/2013/07/c-program-to-find-number-of-occurrences.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "93",
"bestRating": "100",
"ratingCount": "10033"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.comtag:blogger.com,1999:blog-6314054590958763633.post-1686707962308309522013-07-18T17:50:00.001+05:302024-03-04T00:41:37.496+05:30Find Factorial Of a Number Using Recursion C Program<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Trebuchet MS, sans-serif;">Hello Guys,</span><br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;">In this post I'll explain what is Recursion and how it can be used to calculate the factorial of a number in C.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Suppose f1(), f2() and f3() are three functions. The function f1() can call f1(), in turn, f2() can call f3(). Likewise, nesting of the function calls can be to any level depending on the requirement. There is one more possibility with regard to functions, which needs to be mentioned. That is, a function f() calling itself. <b><u>The phenomenon of a function calling itself is called Recursion. The function involved in the process is referred to as a recursive function.</u></b></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><b><u><br /></u></b></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">When a recursive function is employed to solve any problem, care needs to be taken to see to it that the function does not call itself again at some point of time by which the solution of the problem has been arrived at. This is accomplished with the help of a terminating condition.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">The program is quite simple. Function Fact() is defined with an argument of int type and is made to return a Value of int type. The purpose of this function is to find the factorial of an integer number passed as an argument to it and return the result. It works as follows:</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">If the value of n is 1, the function returns 1. Of n>1 then, as long as n>1, fact(0 is called recursively by passing one less than the previous number. Once argument to fact() becomes 1, the function call is replaced by 1. The value of the resultant expression constructed is assigned to the variable f and is then returned to the main(). </span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<h2 style="text-align: left;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><i><u>Find Factorial Of a Number Using Recursion C Program:</u></i></span></h2>
<br />
<br />
<!-- INFOLINKS_OFF -->
<pre class="brush:cpp">/* Double-Click To Select Code */
#include<stdio.h>
#include<conio.h>
int fact(int number);
int main(void)
{
int number;
int f;
clrscr();
printf("\nEnter The Number: ");
scanf("%d",&number);
f = fact(number);
printf("\nFactorial of %d = %d",number,f);
getch();
return 0;
}
int fact(int number)
{
int f;
if(number==0)
return(1);
else
f = number * fact(number-1); // Recursion
return f;
}</pre>
<!-- INFOLINKS_ON -->
<br />
<br />
<h2>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;">Program Output:</span></u></i></h2>
<div>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><br /></span></u></i></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0NTeSw0ENUzctr9U07wYWHCgfMxPjP7xeIAXMGlfTqQLArUjSZANjV3etFxdkrdtWiDu7bRTy4t8Euosi72uXAG9yZFvECZPPtkzxNhN5qvkWvvisD3kZTFNzhwQA8XR9kFW7QlPEwk0/s1600/Find+Factorial+Of+a+Number+Using+Recursion+C+Program.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Find Factorial Of a Number Using Recursion C Program" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0NTeSw0ENUzctr9U07wYWHCgfMxPjP7xeIAXMGlfTqQLArUjSZANjV3etFxdkrdtWiDu7bRTy4t8Euosi72uXAG9yZFvECZPPtkzxNhN5qvkWvvisD3kZTFNzhwQA8XR9kFW7QlPEwk0/s1600/Find+Factorial+Of+a+Number+Using+Recursion+C+Program.jpg" title="Find Factorial Of a Number Using Recursion C Program" /></a></div>
<div>
<i><u><span style="font-family: Georgia, Times New Roman, serif; font-size: x-large;"><br /></span></u></i></div>
<div>
<b style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: large;">Please Comment If You Liked The Post.</span></b></div>
</div>
</div>
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Review",
"author": {
"@type":"Person",
"name":"Piyush Chugh"
},
"url": "https://www.codingbot.net/2013/07/find-factorial-of-number-using.html",
"datePublished":"2019-04-14T20:00",
"dateModified":"2019-04-14T20:00",
"mainEntityOfPage":"https://www.codingbot.net/",
"publisher": {
"@type":"Organization",
"name":"Coding Bot | Program Codes",
"sameAs":"https://www.codingbot.net/"
},
"description":"Coding Bot | Program Codes",
"inLanguage":"en",
"itemReviewed": {
"@type":"Product",
"name": "Find Factorial Of a Number Using Recursion C Program",
"sameAs": "https://www.codingbot.net/2013/07/find-factorial-of-number-using.html",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "94",
"bestRating": "100",
"ratingCount": "1238"
}
}
}
</script><div class="blogger-post-footer"><center><a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'><img alt='Creative Commons Licence' src='http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png' style='border-width:0'/></a><br/><span property='dct:title' xmlns:dct='http://purl.org/dc/terms/'>Coding Bot</span> is licensed under a <a href='http://creativecommons.org/licenses/by-nc-nd/3.0/deed.en_GB' rel='license'>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License</a>.</center></div>Piyush Chughhttp://www.blogger.com/profile/07662183822778236134noreply@blogger.com