<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>java | Automation Dojos</title>
	<atom:link href="https://www.automationdojos.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.automationdojos.com/tag/java/</link>
	<description>Applied Automation Ops</description>
	<lastBuildDate>Mon, 20 Feb 2023 13:58:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.automationdojos.com/wp-content/uploads/2021/06/Adjo_X_fav_32.png</url>
	<title>java | Automation Dojos</title>
	<link>https://www.automationdojos.com/tag/java/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How To Create Maven Project in Eclipse With Archetype</title>
		<link>https://www.automationdojos.com/create-maven-project-with-archetype/</link>
					<comments>https://www.automationdojos.com/create-maven-project-with-archetype/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Sat, 10 Apr 2021 21:07:00 +0000</pubDate>
				<category><![CDATA[How-To Java]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[maven-project]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=21183</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/create-maven-project-with-archetype/">How To Create Maven Project in Eclipse With Archetype</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-archetype.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" fetchpriority="high" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-archetype.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-archetype-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-archetype-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-archetype-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-archetype-400x240.png 400w" sizes="(max-width: 575px) 100vw, 575px" /></p>
<p>Maven Basics Maven automates the steps involved in building a software application like adding the JAR files, compiling code, running unit tests, creating the output jar/war file, etc. This makes the code less error-prone. Maven uses an XML configuration file known as the POM file. Developers need to specify information like the JAR files required [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/create-maven-project-with-archetype/">How To Create Maven Project in Eclipse With Archetype</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/create-maven-project-with-archetype/">How To Create Maven Project in Eclipse With Archetype</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<div role="navigation" aria-label="Table of Contents" class="simpletoc blog-post-toc wp-block-simpletoc-toc"><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#maven-basics">Maven Basics</a>

</li>
<li><a href="#eclipse-maven-integration">Eclipse Maven Integration</a>

</li>
<li><a href="#create-maven-project-with-archetype-in-eclipse">Create Maven Project with Archetype in Eclipse</a>


<ul><li>
<a href="#create-new-artefact-of-type-other">Create new artefact of type &#8216;Other&#8217;</a>

</li>
<li><a href="#select-maven-project">Select Maven Project</a>

</li>
<li><a href="#uncheck-create-simple-project">Uncheck &#8216;Create Simple Project&#8217;</a>

</li>
<li><a href="#use-filter-mavenarchetypewebapp">Use filter &#8216;maven-archetype-webapp&#8217;</a>

</li>
<li><a href="#select-mavenarchetypewebapp">Select maven-archetype-webapp.</a>

</li>
<li><a href="#input-group-id-and-artifact-id">Input Group Id and Artifact Id</a>

</li>
<li><a href="#verify-new-maven-project-in-eclipse">Verify New Maven project in Eclipse</a>

</li>
<li><a href="#finish">Finish!</a>
</li>
</ul>
</li></ul></div>

<h2 class="wp-block-heading" id="maven-basics">Maven Basics</h2>


<p class="wp-block-paragraph">Maven automates the steps involved in building a software application like adding the JAR files, compiling code, running unit tests, creating the output jar/war file, etc. This makes the code less error-prone. Maven uses an XML configuration file known as the POM file. Developers need to specify information like the JAR files required by an application, the type of output artifact (jar,war, etc). Maven then uses the instructions in the POM file to build the application.</p>


<h2 class="wp-block-heading" id="eclipse-maven-integration">Eclipse Maven Integration</h2>


<p class="wp-block-paragraph">Most of the recent Eclipse releases already include Maven. So, developers do not need to do anything special to install Maven in Eclipse. &nbsp;However, some earlier versions of Eclipse do not include Maven, so it needs to be installed explicitly from the Eclipse marketplace. Once Maven is set up with Eclipse, it allows you to easily create a Maven project and use all the Maven features like dependency resolution within Eclipse itself.</p>


<h2 class="wp-block-heading" id="create-maven-project-with-archetype-in-eclipse">Create Maven Project with Archetype in Eclipse</h2>


<p class="wp-block-paragraph">Maven archetype provides a template that can be used to create a particular type of Maven project. If a Maven project is created with an archetype selection, Maven creates the POM file accordingly. Some of the common Maven archetypes are as follows:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px">



<ul class="wp-block-list">
<li><i class="sui sui-gear" style="color:#888"></i> <strong>maven-archetype-quickstart</strong> – Can be used to create a basic Maven project</li>



<li><i class="sui sui-gear" style="color:#888"></i> <strong>maven-archetype-j2ee-simple</strong> – Can be used to create a simple j2ee project</li>



<li><i class="sui sui-gear" style="color:#888"></i> <strong>maven-archetype-webapp</strong> – Can be used to create a web application</li>
</ul>



<p class="wp-block-paragraph"></div>



<p class="wp-block-paragraph">In order to create a Maven project with a webapp archetype, the following steps need to be followed:</p>


<h3 class="wp-block-heading" id="create-new-artefact-of-type-other">Create new artefact of type &#8216;Other&#8217;</h3>


<p class="wp-block-paragraph">On Eclipse main menu, navigate to <em>&#8216;File &gt; New&#8217;</em> and select &#8216;Other&#8217;</p>



<figure class="wp-block-image size-large is-resized is-style-default td-img-style-shadow"><img decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-1-690x1024.png" alt="" class="wp-image-21164" width="428" height="631"/></figure>


<h3 class="wp-block-heading" id="select-maven-project">Select <strong>Maven Project</strong></h3>


<p class="wp-block-paragraph">Select the option &#8216;Maven Project&#8217; and click Next.</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2.png" alt="" class="wp-image-21163" width="568" height="411" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2-300x218.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2-150x109.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2-324x235.png 324w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2-200x145.png 200w" sizes="(max-width: 568px) 100vw, 568px" /></figure>


<h3 class="wp-block-heading" id="uncheck-create-simple-project">Uncheck &#8216;<strong>Create Simple Project</strong>&#8216;</h3>


<p class="wp-block-paragraph">Leave the <strong>Create a</strong> <strong>Simple Project (skip archetype selection)</strong> checkbox unchecked. Click <strong>Next</strong></p>



<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-10.png" alt="" class="wp-image-21170" width="597" height="541" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-10-150x137.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-10-200x182.png 200w" sizes="auto, (max-width: 597px) 100vw, 597px" /></figure>


<h3 class="wp-block-heading" id="use-filter-mavenarchetypewebapp">Use filter &#8216;<strong>maven-archetype-webapp</strong>&#8216;</h3>


<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-11-1024x552.png" alt="" class="wp-image-21169" width="701" height="371"/></figure>


<h3 class="wp-block-heading" id="select-mavenarchetypewebapp">Select <strong>maven-archetype-webapp.</strong></h3>


<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-12-1024x553.png" alt="" class="wp-image-21168" width="702" height="373"/></figure>


<h3 class="wp-block-heading" id="input-group-id-and-artifact-id">Input <strong>Group Id</strong> and <strong>Artifact Id</strong></h3>


<p class="wp-block-paragraph">Enter a value for <strong>Group Id</strong> and <strong>Artifact Id</strong>. Change <strong>version</strong> and <strong>package </strong>if required. Click <strong>Finish</strong></p>



<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-13-1024x556.png" alt="" class="wp-image-21167" width="716" height="382"/></figure>


<h3 class="wp-block-heading" id="verify-new-maven-project-in-eclipse">Verify New Maven project in Eclipse</h3>


<p class="wp-block-paragraph">This creates a Maven project in Eclipse with the <strong>Maven directory structure</strong> and <strong>POM file</strong> as follows</p>



<figure class="wp-block-image size-large is-style-default"><img loading="lazy" decoding="async" width="474" height="303" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-14.png" alt="" class="wp-image-21166" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-14.png 474w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-14-300x192.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-14-150x96.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-14-200x128.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-14-400x256.png 400w" sizes="auto, (max-width: 474px) 100vw, 474px" /></figure>


<h3 class="wp-block-heading" id="finish">Finish!</h3>


<p class="wp-block-paragraph">Finish! This POM file can then be modified by adding dependencies and other information as required.</p>


[td_smart_list_end]


<hr class="wp-block-separator has-css-opacity"/>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21183" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21183" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21183" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21183&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21183" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=21183" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=21183', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/create-maven-project-with-archetype/">How To Create Maven Project in Eclipse With Archetype</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/create-maven-project-with-archetype/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Create Maven Project in Eclipse Without Archetype</title>
		<link>https://www.automationdojos.com/create-maven-without-archetype/</link>
					<comments>https://www.automationdojos.com/create-maven-without-archetype/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Sun, 10 Jan 2021 15:03:00 +0000</pubDate>
				<category><![CDATA[How-To Java]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[maven-project]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=21159</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/create-maven-without-archetype/">How To Create Maven Project in Eclipse Without Archetype</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-no-archetype.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-no-archetype.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-no-archetype-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-no-archetype-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-no-archetype-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-maven-no-archetype-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>Maven is a very popular build and dependency management tool. Eclipse is an IDE that helps developers write and run Java code easily. In this article, I will be explaining how you can create a Maven project in Eclipse. Maven Basics Maven automates the steps involved in building a software application like adding the JAR [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/create-maven-without-archetype/">How To Create Maven Project in Eclipse Without Archetype</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/create-maven-without-archetype/">How To Create Maven Project in Eclipse Without Archetype</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<div role="navigation" aria-label="Table of Contents" class="simpletoc blog-post-toc wp-block-simpletoc-toc"><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#maven-basics">Maven Basics</a>

</li>
<li><a href="#eclipse-maven-integration">Eclipse Maven Integration</a>

</li>
<li><a href="#creating-a-simple-maven-project">Creating a Simple Maven Project</a>


<ul><li>
<a href="#create-new-artefact-of-type-other">Create new artefact of type &#8216;Other&#8217;</a>

</li>
<li><a href="#select-maven-project-click-next">Select Maven Project. Click Next</a>

</li>
<li><a href="#select-create-a-simple-project">Select &#8216;Create a Simple Project&#8217;</a>

</li>
<li><a href="#enter-value-for-group-id-amp-artifact-id">Enter value for Group Id &amp; Artifact Id.</a>

</li>
<li><a href="#change-version-and-packaging">Change version and packaging</a>

</li>
<li><a href="#new-maven-project-created">New Maven Project Created</a>

</li>
<li><a href="#view-your-pom-file">View Your POM File</a>

</li>
<li><a href="#finish">Finish!</a>
</li>
</ul>
</li></ul></div>


<p class="wp-block-paragraph">Maven is a very popular build and dependency management tool. Eclipse is an IDE that helps developers write and run Java code easily. In this article, I will be explaining how you can create a Maven project in Eclipse.</p>


<h2 class="wp-block-heading" id="maven-basics">Maven Basics</h2>


<p class="wp-block-paragraph">Maven automates the steps involved in building a software application like adding the JAR files, compiling code, running unit tests, creating the output jar/war file, etc. This makes the code less error-prone. Maven uses an XML configuration file known as the POM file. Developers need to specify information like the JAR files required by an application, the type of output artifact (jar,war, etc). Maven then uses the instructions in the POM file to build the application.</p>


<h2 class="wp-block-heading" id="eclipse-maven-integration">Eclipse Maven Integration</h2>


<p class="wp-block-paragraph">Most of the recent Eclipse releases already include Maven. So, developers do not need to do anything special to install Maven in Eclipse. &nbsp;However, some earlier versions of Eclipse do not include Maven, so it needs to be installed explicitly from the Eclipse marketplace. Once Maven is set up with Eclipse, it allows you to easily create a Maven project and use all the Maven features like dependency resolution within Eclipse itself.</p>


<h2 class="wp-block-heading" id="creating-a-simple-maven-project">Creating a Simple Maven Project</h2>


<p class="wp-block-paragraph">In order to create a simple Maven project in Eclipse, the following steps need to be followed:</p>


<h3 class="wp-block-heading" id="create-new-artefact-of-type-other">Create new artefact of type &#8216;Other&#8217;</h3>


<p class="wp-block-paragraph">From menu File &gt; New select &#8216;Other&#8217;</p>



<figure class="wp-block-image size-large is-resized is-style-default td-img-style-shadow"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-1-690x1024.png" alt="" class="wp-image-21164" width="428" height="631"/></figure>


<h3 class="wp-block-heading" id="select-maven-project-click-next">Select <strong>Maven Project</strong>. Click <strong>Next</strong></h3>


<p class="wp-block-paragraph">On the &#8216;new project&#8217; wizard select &#8216;Maven Project&#8217;</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2.png" alt="" class="wp-image-21163" width="618" height="447" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2-300x218.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2-150x109.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2-324x235.png 324w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-2-200x145.png 200w" sizes="auto, (max-width: 618px) 100vw, 618px" /></figure>


<h3 class="wp-block-heading" id="select-create-a-simple-project">Select &#8216;Create a Simple Project&#8217;</h3>


<p class="wp-block-paragraph">Click the Create a Simple Project (skip archetype selection) checkbox. Click Next</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-3.png" alt="" class="wp-image-21162" width="628" height="578" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-3-300x277.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-3-150x138.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-3-455x420.png 455w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-3-200x185.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-3-400x369.png 400w" sizes="auto, (max-width: 628px) 100vw, 628px" /></figure>


<h3 class="wp-block-heading" id="enter-value-for-group-id-amp-artifact-id">Enter value for <strong>Group Id</strong> &amp; <strong>Artifact Id</strong>.</h3>


<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-4.png" alt="" class="wp-image-21161" width="656" height="598" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-4-300x274.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-4-150x137.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-4-696x636.png 696w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-4-460x420.png 460w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-4-200x183.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-4-400x366.png 400w" sizes="auto, (max-width: 656px) 100vw, 656px" /></figure>


<h3 class="wp-block-heading" id="change-version-and-packaging">Change <strong>version</strong> and <strong>packaging</strong></h3>


<p class="wp-block-paragraph">Change <strong>version</strong> and <strong>packaging</strong> if required (This is an optional step). Click <strong>Finish</strong></p>



<figure class="wp-block-image size-large is-resized is-style-default"><img loading="lazy" decoding="async" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-5.png" alt="" class="wp-image-21160" width="609" height="555" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-5-150x138.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-5-200x183.png 200w" sizes="auto, (max-width: 609px) 100vw, 609px" /></figure>


<h3 class="wp-block-heading" id="new-maven-project-created">New Maven Project Created</h3>


<p class="wp-block-paragraph">This creates a Maven project in Eclipse with the <strong>Maven directory structure</strong> and <strong>POM file</strong> as follows</p>



<figure class="wp-block-image size-large is-style-default"><img loading="lazy" decoding="async" width="294" height="365" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-6.png" alt="" class="wp-image-21158" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-6.png 294w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-6-242x300.png 242w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-6-150x186.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-6-161x200.png 161w" sizes="auto, (max-width: 294px) 100vw, 294px" /></figure>


<h3 class="wp-block-heading" id="view-your-pom-file">View Your POM File</h3>


<p class="wp-block-paragraph">The default POM created has the group id, artifact id, version and packaging specified at the time of creation as follows</p>



<figure class="wp-block-image size-large is-style-default"><img loading="lazy" decoding="async" width="1024" height="190" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7-1024x190.png" alt="" class="wp-image-21157" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7-1024x190.png 1024w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7-300x56.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7-768x143.png 768w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7-150x28.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7-696x129.png 696w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7-200x37.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7-400x74.png 400w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-maven-proj-7.png 1045w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>


<h3 class="wp-block-heading" id="finish">Finish!</h3>


<p class="wp-block-paragraph">This POM file can then be modified by adding dependencies and other information as required.</p>


[td_smart_list_end]


<hr class="wp-block-separator has-css-opacity"/>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21159" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21159" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21159" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21159&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21159" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=21159" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=21159', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/create-maven-without-archetype/">How To Create Maven Project in Eclipse Without Archetype</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/create-maven-without-archetype/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Configuring Maven Compiler Plugin (Java)</title>
		<link>https://www.automationdojos.com/configuring-maven-compiler-plugin-jdk/</link>
					<comments>https://www.automationdojos.com/configuring-maven-compiler-plugin-jdk/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Mon, 10 Aug 2020 10:09:00 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache-maven]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdk]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[maven compiler]]></category>
		<category><![CDATA[maven plugin]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=23452</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/configuring-maven-compiler-plugin-jdk/">Configuring Maven Compiler Plugin (Java)</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2022/03/post-maven-compiler-plugin.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2022/03/post-maven-compiler-plugin.png 575w, https://www.automationdojos.com/wp-content/uploads/2022/03/post-maven-compiler-plugin-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2022/03/post-maven-compiler-plugin-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2022/03/post-maven-compiler-plugin-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2022/03/post-maven-compiler-plugin-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>1. What is Maven Compiler Plugin The ‘Maven Compiler Plugin’ or more commonly known as &#8216;Maven Java Compiler&#8217; is used to compile the source code of your project/application. Internally this plugin uses the standard &#8216;javac&#8217; compiler (JDK) and as of version 3.0 of this plugin the default compiler is javax.tools.JavaCompiler Unlike other Maven plugins, the [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/configuring-maven-compiler-plugin-jdk/">Configuring Maven Compiler Plugin (Java)</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/configuring-maven-compiler-plugin-jdk/">Configuring Maven Compiler Plugin (Java)</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#1-what-is-maven-compiler-plugin">1. What is Maven Compiler Plugin</a>

</li>
<li><a href="#2-default-configuration">2. Default Configuration</a>

</li>
<li><a href="#3-common-compilation-error">3. Common Compilation Error</a>

</li>
<li><a href="#4-custom-configuration-java-8-or-earlier">4. Custom Configuration Java 8 or Earlier</a>


<ul><li>
<a href="#41-configure-using-pom-properties">4.1. Configure using POM Properties</a>

</li>
<li><a href="#42-configure-using-sourcenbspampnbsptarget">4.2. Configure using -source&nbsp;&amp;&nbsp;-target</a>

</li>
<li><a href="#43-configure-using-compilerversion">4.3. Configure using ‘compilerVersion’</a>


<ul><li>
<a href="#431-improvise-use-variable-for-path">4.3.1. Improvise – Use variable for Path</a>

</li>
<li><a href="#432-improvise-pass-args-to-compiler">4.3.2. Improvise – Pass args to compiler</a>


<ul><li>
<a href="#method-1-using-ltconfigurationgt-element">Method 1: Using &lt;configuration&gt; element</a>

</li>
<li><a href="#method-2-using-explicit-ltcompilerargsgt">Method 2: Using explicit &lt;compilerArgs&gt;</a>

</li>
</ul>
</li>
</ul>
</li>
</ul>
<li><a href="#5-custom-configuration-java-9-and-beyond">5. Custom Configuration Java 9 and Beyond</a>


<ul><li>
<a href="#51-configure-using-pom-properties">5.1. Configure using POM Properties</a>

</li>
<li><a href="#52-configure-using-plugin-ltconfigurationgt">5.2. Configure using plugin &lt;configuration&gt;</a>
</li>
</ul>
</li></ul>

<h2 class="wp-block-heading" id="1-what-is-maven-compiler-plugin">1. What is Maven Compiler Plugin</h2>


<p class="wp-block-paragraph">The ‘Maven Compiler Plugin’ or more commonly known as &#8216;Maven Java Compiler&#8217; is used to compile the source code of your project/application. </p>



<p class="wp-block-paragraph">Internally this plugin uses the standard <strong>&#8216;javac&#8217;</strong> compiler (JDK) and as of version 3.0 of this plugin the default compiler is <em>javax.tools.JavaCompiler</em></p>



<p class="wp-block-paragraph">Unlike other Maven plugins, the ‘maven compiler plugin’ is <strong>‘in-built’</strong> and <strong>‘implicit’ </strong>in nature. This plugin has two goals, which are already bound to specific phases of the default lifecycle:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px"><ul><li><i class="sui sui-gear" style="color:#979594"></i> compile: compile main source files</li> <li><i class="sui sui-gear" style="color:#979594"></i> testCompile: compile test source files</li></ul></div>



<p class="wp-block-paragraph">As mentioned earlier, the maven compiler plugin is called <em>implicitly</em> and <em>automatically</em> by the maven lifecycle in the appropriate phase. Hence you don´t necessarily need to define it inside ‘pom.xml’ it shall be downloaded and executed automatically by maven as and when required. However, we can certainly define and configure custom behavior and attributes for this plugin by specifying it in the ‘pom.xml’.</p>



<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>


<h2 class="wp-block-heading" id="2-default-configuration">2. Default Configuration</h2>


<p class="wp-block-paragraph">As per the default behavior, the ‘maven compiler plugin’ compiles source code compatible with <span class="su-label su-label-type-default"><em>Java 5</em></span> (also written as Java 1.5), <strong>irrespective </strong>of the JDK installed on your machine. However, with custom configuration in your ‘pom.xml’ you can override this behavior and specify your own version of compiler and compatibility version.</p>



<div class="notice2">
<p><strong>Note:</strong> The java version used to launch Maven itself (Maven runtime) can be set to a different version than the version used for compiling your source code or project. This can be done using custom configuration in your pom.xml as explained in below examples.</p><p>You can find out java version for &#8216;Maven runtime&#8217; by typing the command <strong><i>&#8216;mvn -v&#8217;</i></strong> or <strong><i>&#8216;mvn -version&#8217;</i></strong></p>
<div class="module-icon"></div>
</div>



<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>


<h2 class="wp-block-heading" id="3-common-compilation-error">3. Common Compilation Error</h2>


<p class="wp-block-paragraph">While starting with Maven projects, it is very common to encounter the below error associated with this plugin. This is nothing but the default behavior as mentioned in the above paragraph and can be rectified by using one of the below mentioned custom configurations for your maven java compiler.</p>



<pre class="wp-block-code"><code>&#091;INFO] -------------------------------------------------------------
&#091;ERROR] COMPILATION ERROR :
&#091;INFO] -------------------------------------------------------------
&#091;ERROR] Source option 5 is no longer supported. Use 6 or later.
&#091;ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
&#091;INFO] 2 errors
&#091;INFO] -------------------------------------------------------------
</code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="856" height="747" src="https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01.png" alt="" class="wp-image-23455" srcset="https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01.png 856w, https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01-300x262.png 300w, https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01-768x670.png 768w, https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01-150x131.png 150w, https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01-696x607.png 696w, https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01-481x420.png 481w, https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01-200x175.png 200w, https://www.automationdojos.com/wp-content/uploads/2020/08/post-maven-compiler-plugin01-400x349.png 400w" sizes="auto, (max-width: 856px) 100vw, 856px" /></figure>



<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>


<h2 class="wp-block-heading" id="4-custom-configuration-java-8-or-earlier">4. Custom Configuration Java 8 or Earlier</h2>


<p class="wp-block-paragraph">If you are using Java 8 or earlier, you can set the Maven Java Compiler version in your POM file using one of the following three methods:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px"><ul><li><i class="sui sui-check" style="color:#41a12c"></i> Using POM Properties</li> <li><i class="sui sui-check" style="color:#41a12c"></i> Using -source and -target values in compiler configuration</li> <li><i class="sui sui-check" style="color:#41a12c"></i> Using compilerVersion in compiler configuration</li></ul></div>



<p class="wp-block-paragraph">Let us start with a standard bare-bone ‘pom.xml’ file and insert our custom configuration for ‘Maven Compiler Plugin’ eventually by three different methods.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project 
	xmlns="http://maven.apache.org/POM/4.0.0" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
		http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>
&lt;/project></pre>



<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>


<h3 class="wp-block-heading" id="41-configure-using-pom-properties">4.1. Configure using POM Properties</h3>


<p class="wp-block-paragraph">In this method rather than tweaking the ‘maven compiler’ configuration or ‘build’ configuration’ directly, you can use the <strong>POM properties</strong> to set the compiler (JDK) versions.</p>



<p class="wp-block-paragraph">This is the most simple but probably least reliable way. However, which option works best for you depends on the setup of your project and specific requirements i.e. depend on a case by case basis.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project 
	xmlns="http://maven.apache.org/POM/4.0.0" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
		http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>
    &lt;properties>
    &lt;maven.compiler.source>1.8&lt;/maven.compiler.source>
    &lt;maven.compiler.target>1.8&lt;/maven.compiler.target>
  &lt;/properties>
&lt;/project></pre>



<p class="wp-block-paragraph">Using the above configuration should give you output classes both <em>compiled and compatible with the specified java (compiler) version</em> which is Java 8 in this case.</p>



<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>


<h3 class="wp-block-heading" id="42-configure-using-sourcenbspampnbsptarget"> 4.2. Configure using -source &amp; -target</h3>


<p class="wp-block-paragraph">Another, preferred way for forcing a specific compiler version is by modifying the default parameter values of ‘-source’ and ‘target’ directly in the plugin settings as below.</p>



<p class="wp-block-paragraph">Here we are setting the JDK/JRE version for both source and target to 1.8</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project 
	xmlns="http://maven.apache.org/POM/4.0.0" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
		http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>

  &lt;build>
    &lt;plugins>
      &lt;plugin>
        &lt;groupId>org.apache.maven.plugins&lt;/groupId>
        &lt;artifactId>maven-compiler-plugin&lt;/artifactId>
        &lt;version>3.8.1&lt;/version>
        &lt;configuration>
          &lt;source>1.8&lt;/source>
          &lt;target>1.8&lt;/target>
        &lt;/configuration>
      &lt;/plugin>
    &lt;/plugins>
  &lt;/build>

&lt;/project></pre>



<div class="attention2"><strong>NOTE:</strong> In some cases, problem with this method is that it does not ‘guarantee’ that the maven compiler would be able to strictly adhere to above settings due to unintended usage of APIs that only exist in JREs which would make your code fail at runtime with a linkage error. For further reference on this read https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html<div class="module-icon"></div></div>



<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>


<h3 class="wp-block-heading" id="43-configure-using-compilerversion"> 4.3. Configure using ‘compilerVersion’</h3>


<p class="wp-block-paragraph">You can use this method to compile your code with a <em>‘very specific’ JDK version, even if it is different than the one used to launch Maven itself</em>. This is probably the most <em>precise </em>of all methods.</p>



<p class="wp-block-paragraph">Here ‘compilerVersion’&nbsp;parameter can be used as part of ‘build configuration’ to specify the version of the compiler that the plugin will use. However, you also need to <strong><em>set&nbsp;fork&nbsp;to&nbsp;true</em></strong>&nbsp;for this to work</p>



<p class="wp-block-paragraph">Using the below ‘POM’ configuration, it is still possible to tell the ‘Maven Compiler Plugin’ the specific JDK to use during compilation. But such configuration will be specific to this plugin, and will not affect others.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project 
	xmlns="http://maven.apache.org/POM/4.0.0" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
		http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>
  
  &lt;build>
    &lt;plugins>
      &lt;plugin>
        &lt;groupId>org.apache.maven.plugins&lt;/groupId>
        &lt;artifactId>maven-compiler-plugin&lt;/artifactId>
        &lt;version>3.8.1&lt;/version>
        &lt;configuration>
          &lt;verbose>true&lt;/verbose>
          &lt;fork>true&lt;/fork>
          &lt;executable>&lt;!-- path-to-javac -->&lt;/executable>
          &lt;compilerVersion>1.3&lt;/compilerVersion>
        &lt;/configuration>
      &lt;/plugin>
    &lt;/plugins>
  &lt;/build>
 
&lt;/project></pre>



<div class="attention2"><strong>NOTE:</strong> Please note that you need to set the ‘fork’ value to ‘true’ for this method to work.  This allows running the compiler in a separate process. If false it uses the built-in compiler, while if true it will use the explicitly mentioned executable.
Default value is: false.<div class="module-icon"></div></div>



<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>


<h4 class="wp-block-heading" id="431-improvise-use-variable-for-path">4.3.1. Improvise – Use variable for Path</h4>


<p class="wp-block-paragraph">In the above ‘pom.xml’ snippet, rather than hardcoding the path to java compiler, you can replace it with a variable. We can do so by using the following property: &lt;executable&gt;${JAVA_1_4_HOME}/bin/javac&lt;/executable&gt;</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project 
	xmlns="http://maven.apache.org/POM/4.0.0" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
		http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>
  
  &lt;build>
    &lt;plugins>
      &lt;plugin>
        &lt;groupId>org.apache.maven.plugins&lt;/groupId>
        &lt;artifactId>maven-compiler-plugin&lt;/artifactId>
        &lt;version>3.8.1&lt;/version>
        &lt;configuration>
          &lt;verbose>true&lt;/verbose>
          &lt;fork>true&lt;/fork>
          &lt;executable>${JAVA_1_8_HOME}/bin/javac&lt;/executable>
          &lt;compilerVersion>1.8&lt;/compilerVersion>
        &lt;/configuration>
      &lt;/plugin>
    &lt;/plugins>
  &lt;/build>
  
&lt;/project></pre>



<p class="wp-block-paragraph">The best part of using the above property is that different users can specify their own values for this property in their ‘settings.xml’ file, keeping your project portable for different users and machine configurations.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;settings>
  [...]
  &lt;profiles>
    [...]
    &lt;profile>
      &lt;id>compiler&lt;/id>
        &lt;properties>
          &lt;JAVA_1_4_HOME>C:\Program Files\Java\j2sdk1.4.2_09&lt;/JAVA_1_4_HOME>
        &lt;/properties>
    &lt;/profile>
  &lt;/profiles>
  [...]
  &lt;activeProfiles>
    &lt;activeProfile>compiler&lt;/activeProfile>
  &lt;/activeProfiles>
&lt;/settings></pre>



<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>


<h4 class="wp-block-heading" id="432-improvise-pass-args-to-compiler">4.3.2. Improvise – Pass args to compiler</h4>


<p class="wp-block-paragraph">If you wish to pass some arguments to the maven java compiler, you can do so in two ways.</p>


<h5 class="wp-block-heading" id="method-1-using-ltconfigurationgt-element">Method 1: Using &lt;configuration&gt; element</h5>


<p class="wp-block-paragraph">You can pass the compiler arguments inside the ‘configuration’ part of the compiler plugin itself. A very common example is to pass min and max memory values as below.</p>



<p class="wp-block-paragraph">Here we are passing the following arguments related to <em>max</em> and <em>min memory</em> to the compiler:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">           &lt;meminitial>128m&lt;/meminitial>
           &lt;maxmem>512m&lt;/maxmem>

&lt;project 
	xmlns="http://maven.apache.org/POM/4.0.0" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
		http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>
  
  &lt;build>
    &lt;plugins>
      &lt;plugin>
        &lt;groupId>org.apache.maven.plugins&lt;/groupId>
        &lt;artifactId>maven-compiler-plugin&lt;/artifactId>
        &lt;version>3.8.1&lt;/version>
        &lt;configuration>
          &lt;verbose>true&lt;/verbose>
          &lt;fork>true&lt;/fork>
          &lt;executable>${JAVA_1_8_HOME}/bin/javac&lt;/executable>
          &lt;compilerVersion>1.3&lt;/compilerVersion>
           &lt;meminitial>128m&lt;/meminitial>
           &lt;maxmem>512m&lt;/maxmem>
        &lt;/configuration>
      &lt;/plugin>
    &lt;/plugins>
  &lt;/build>
  
&lt;/project></pre>



<div class="attention2"><strong>NOTE:</strong> The fork value needs to be set to true in order for these memory settings to work.  Without fork value being true these memory parameters set for compiler will not work.<div class="module-icon"></div></div>



<div style="height:1px" aria-hidden="true" class="wp-block-spacer"></div>


<h5 class="wp-block-heading" id="method-2-using-explicit-ltcompilerargsgt">Method 2: Using explicit &lt;compilerArgs&gt;</h5>


<p class="wp-block-paragraph">You should use <em>&#8216;&lt;compilerArgs&gt;&#8217;</em> element to pass specific compiler arguments that are not handled by the Compiler Plugin itself but are supported by the&nbsp;compilerId&nbsp;selected. For such arguments, use the Compiler Plugin&#8217;s&nbsp;&lt;compilerArgs&gt;&nbsp;parameter.</p>



<p class="wp-block-paragraph">The following example passes compiler arguments to the&nbsp;javac&nbsp;compiler:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project 
	xmlns="http://maven.apache.org/POM/4.0.0" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
		http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>
  
  &lt;build>
    &lt;plugins>
      &lt;plugin>
        &lt;groupId>org.apache.maven.plugins&lt;/groupId>
        &lt;artifactId>maven-compiler-plugin&lt;/artifactId>
        &lt;version>3.8.1&lt;/version>
        &lt;configuration>
          &lt;verbose>true&lt;/verbose>
          &lt;fork>true&lt;/fork>
          &lt;executable>${JAVA_1_8_HOME}/bin/javac&lt;/executable>
          &lt;compilerVersion>1.3&lt;/compilerVersion>
           &lt;meminitial>128m&lt;/meminitial>
           &lt;maxmem>512m&lt;/maxmem>
          &lt;compilerArgs>
            &lt;arg>-verbose&lt;/arg>
            &lt;arg>-Xlint:all,-options,-path&lt;/arg>
           &lt;arg>-Xmaxerrs&lt;/arg>
           &lt;arg>1000&lt;/arg>
         &lt;arg>-J-Duser.language=en_us&lt;/arg>
          &lt;/compilerArgs>
        &lt;/configuration>
      &lt;/plugin>
    &lt;/plugins>
  &lt;/build>
  
&lt;/project></pre>



<div class="attention2"><strong>NOTE:</strong> Please note that you need to set the ‘fork’ value to ‘true’ for this method to work. Without fork value being set to true the <compilerArgs> parameters will not be picked up. Default value is: false.<div class="module-icon"></div></div>


<h2 class="wp-block-heading" id="5-custom-configuration-java-9-and-beyond">5. Custom Configuration Java 9 and Beyond</h2>


<p class="wp-block-paragraph">Starting from JDK 9, we can use a new command-line option i.e. &#8216;-release&#8217; which is accepted by the javac executable and can be used to specify against which Java SE release you want to build the project.</p>



<p class="wp-block-paragraph">This new argument replaces the traditional &#8216;source&#8217; and &#8216;target&#8217; properties used for Java 8 or earlier and will automatically configure the compiler to produce class files compatible with the given platform version which should be Java 9 or above. You can implement this &#8216;-release&#8217; value in the following two ways :</p>


<h3 class="wp-block-heading" id="51-configure-using-pom-properties">5.1. Configure using POM Properties</h3>


<p class="wp-block-paragraph">In this method, you can specify the Java compiler version&nbsp;using the &#8216;maven.compiler.release&#8217; element inside the POM Properties. Here is how the Maven Java compiler release element look inside pom properties:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project 
   xmlns="http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
      http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>
    &lt;properties>
    &lt;maven.compiler.release>11&lt;/maven.compiler.release>
  &lt;/properties>
&lt;/project></pre>


<h3 class="wp-block-heading" id="52-configure-using-plugin-ltconfigurationgt">5.2. Configure using plugin &lt;configuration&gt;</h3>


<p class="wp-block-paragraph">In this method, instead of the&nbsp;<em>source</em>&nbsp;and&nbsp;<em>target</em>&nbsp;properties (as mentioned in section 4.2 above), you need to use the&nbsp;&#8216;-<em>release</em>&#8216;&nbsp;property inside the Maven Java compiler plugin&#8217;s &#8216;&lt;configuration&gt;&#8217; element. Given below is the snippet for such implementation:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project 
   xmlns="http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
      http://maven.apache.org/maven-v4_0_0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.testoxide&lt;/groupId>
  &lt;artifactId>maven-quick-start&lt;/artifactId>
  &lt;version>1.0&lt;/version>
  &lt;build>
    &lt;plugins>
      &lt;plugin>
        &lt;groupId>org.apache.maven.plugins&lt;/groupId>
        &lt;artifactId>maven-compiler-plugin&lt;/artifactId>
        &lt;version>3.8.1&lt;/version>
        &lt;configuration>
          &lt;release>11&lt;/release>
        &lt;/configuration>
      &lt;/plugin>
    &lt;/plugins>
  &lt;/build>
&lt;/project></pre>



<div class="attention2"><strong>NOTE:</strong> <p>The value in the &#8216;-release&#8217; parameter follows the new version naming scheme adopted since Java 9. As such, the release number does not start with 1.x anymore.</p><p>Also note that &#8216;-release&#8217; parameter is available for maven-compiler-plugin starting  3.6 version</p>
<div class="module-icon"></div></div>



<p class="wp-block-paragraph"></p>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D23452" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D23452" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D23452" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D23452&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D23452" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=23452" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=23452', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/configuring-maven-compiler-plugin-jdk/">Configuring Maven Compiler Plugin (Java)</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/configuring-maven-compiler-plugin-jdk/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Create Singleton Class in Java</title>
		<link>https://www.automationdojos.com/how-to-create-singleton-class-in-java/</link>
					<comments>https://www.automationdojos.com/how-to-create-singleton-class-in-java/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Wed, 15 Jul 2020 09:05:00 +0000</pubDate>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[How-To Java]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java-class]]></category>
		<category><![CDATA[java-design-patterns]]></category>
		<category><![CDATA[singleton-class]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=22511</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/how-to-create-singleton-class-in-java/">How To Create Singleton Class in Java</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>Design patterns Overview Design patterns are basically solutions to programming problems that developers normally encounter during software development. Design patterns were first documented by four authors known as the Gang of Four (GoF). Design patterns are broadly classified into creational, structural, and behavioral patterns. Creational patterns aid in object creation, structural patterns help to alter [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/how-to-create-singleton-class-in-java/">How To Create Singleton Class in Java</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/how-to-create-singleton-class-in-java/">How To Create Singleton Class in Java</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/11/java-howto-singleton-1-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#design-patterns-overview">Design patterns Overview</a>

</li>
<li><a href="#introduction-to-singleton-pattern">Introduction to Singleton Pattern</a>

</li>
<li><a href="#singleton-pattern-implementation">Singleton Pattern Implementation</a>


<ul><li>
<a href="#eager-initialization">Eager Initialization</a>

</li>
<li><a href="#lazy-initialization">Lazy Initialization</a>

</li>
<li><a href="#static-block-initialization">Static block Initialization</a>

</li>
</ul>
<li><a href="#advantages-of-singleton">Advantages of Singleton</a>

</li>
<li><a href="#disadvantages-of-singleton">Disadvantages of Singleton</a>

</li>
<li><a href="#conclusion">Conclusion</a>
</li></ul>

<h2 class="wp-block-heading" id="design-patterns-overview">Design patterns Overview</h2>


<p class="wp-block-paragraph">Design patterns are basically solutions to programming problems that developers normally encounter during software development. Design patterns were first documented by four authors known as the <a href="https://en.wikipedia.org/wiki/Design_Patterns" target="_blank" rel="noreferrer noopener">Gang of Four (GoF)</a>. </p>



<p class="wp-block-paragraph">Design patterns are broadly classified into creational, structural, and behavioral patterns. Creational patterns aid in object creation, structural patterns help to alter the structure of an object while behavioral patterns mostly have to do with algorithms.</p>


<h2 class="wp-block-heading" id="introduction-to-singleton-pattern">Introduction to Singleton Pattern</h2>


<p class="wp-block-paragraph">Singleton is a creational design pattern; it helps in creating an object of a class. The Singleton pattern ensures that there is only one instance of a class. It is generally used for a class that consumes a lot of memory or one that uses expensive resources. Singleton ensures that there is only one instance of the class, thus saving on memory and other resources. The singleton pattern is mostly used for database connections, caching, logging, and other programming situations that mandate having a single object of a class.</p>


<h2 class="wp-block-heading" id="singleton-pattern-implementation">Singleton Pattern Implementation</h2>


<p class="wp-block-paragraph">There are three main ways in which the singleton pattern can be implemented. All the approaches make use of a static instance, a private constructor, and a public getter method.</p>


<div class="su-note"  style="border-color:#dcdcdc;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#f6f6f6;border-color:#ffffff;color:#444444;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">


<h3 class="wp-block-heading" id="eager-initialization">Eager Initialization</h3>


<p class="wp-block-paragraph">In this approach, the Singleton instance is created at the time the class is loaded. The following code demonstrates creating a Singleton class using this approach:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class MySingleton {
   private static MySingleton mySingleton = new MySingleton();
   private MySingleton() {
   }
   public static MySingleton getMySingleton() {
      return mySingleton;
   }
}</pre>



<p class="wp-block-paragraph">This code specifies a class called&nbsp;<strong>MySingleton</strong>. It has a private static instance field called&nbsp;<strong>mySingleton</strong>&nbsp;that is initialized at the time of creation. It also has a private constructor. Finally, there is a public getter method called&nbsp;<strong>getMySingleton().</strong>&nbsp;This method returns the&nbsp;<strong>mySingleton</strong> instance.&nbsp;</p>



<p class="wp-block-paragraph">So, in this approach, the singleton instance is created much before it is used. If the singleton is a heavy class using a lot of resources, then this approach is not appropriate.</p>


</div></div>
<div class="su-spacer" style="height:15px"></div>


<div class="su-note"  style="border-color:#d1cec9;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#ebe8e3;border-color:#ffffff;color:#444444;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">


<h3 class="wp-block-heading" id="lazy-initialization">Lazy Initialization</h3>


<p class="wp-block-paragraph">In this approach, the Singleton instance is created when it is first requested. The following code demonstrates this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public class MySingleton {
private static MySingleton mySingleton;
   private MySingleton() {
   }
   public static MySingleton getMySingleton() {
      if (mySingleton == null) {
         mySingleton = new MySingleton();
      }
      return mySingleton;
   }
}</pre>



<p class="wp-block-paragraph">This approach is similar to the eager initialization approach in that it has a private static instance field, a private constructor and a public getter method. The only difference is that the singleton instance is not created at start-up. Instead, the&nbsp;<strong>getMySingleton()</strong>&nbsp;method checks if an instance of the singleton class exists. If so, it just returns it. If an instance does not exist, it creates it via the private constructor.</p>



<p class="wp-block-paragraph">So, in this approach the singleton instance is created when it is first requested. This is the preferred approach for singleton classes that use a lot of resources.</p>


</div></div>
<div class="su-spacer" style="height:15px"></div>


<div class="su-note"  style="border-color:#dcdcdc;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#f6f6f6;border-color:#ffffff;color:#444444;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">


<h3 class="wp-block-heading" id="static-block-initialization">Static block Initialization</h3>


<p class="wp-block-paragraph">In this approach, the singleton instance is created within a static block. The following code demonstrates this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class MySingleton {
   private static MySingleton mySingleton;
   private MySingleton() {
   }
   
   static {
      mySingleton = new MySingleton();
   }
   public static MySingleton getMySingleton() {
      return mySingleton;
   }
   
}</pre>



<p class="wp-block-paragraph">Just like the previous approaches, this code defines a private static instance, a private constructor and a public getter method. In addition, this code also defines a static block. The singleton instance&nbsp;<strong>mySingleton</strong>&nbsp;is created in this static block. Since a static block is executed only once this ensures that there is only one instance of the singleton. Since the static block is executed when the class is loaded, the singleton instance is created at start-up just like it is done in the eager initialization approach.</p>



<p class="wp-block-paragraph">The advantage of this approach over the eager initialization approach is that, exception handling code can be added in the static block. So, if there is an error while creating the singleton instance, an appropriate exception can be thrown.</p>


</div></div>
<div class="su-spacer" style="height:5px"></div>


<h2 class="wp-block-heading" id="advantages-of-singleton">Advantages of Singleton</h2>


<p class="wp-block-paragraph">There are several advantages of using a singleton class. &nbsp;It helps it saving on memory and other resources by ensuring that there is only one instance of the class. It provides global access to the singleton instance. It gives a class control over the instantiation process.</p>


<h2 class="wp-block-heading" id="disadvantages-of-singleton">Disadvantages of Singleton</h2>


<p class="wp-block-paragraph">The Singleton pattern has some disadvantages too. For one, singleton objects are often used as global variables which is against object-oriented principles like encapsulation. Secondly, singletons make unit testing difficult. A class that uses a singleton object cannot be tested by itself.</p>


<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>


<p class="wp-block-paragraph">So, in this article, we understood the basics of the singleton design pattern. We also saw some of the ways in which you can implement the singleton pattern in Java. Finally, we understood some of the advantages and disadvantages of the singleton pattern.</p>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D22511" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D22511" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D22511" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D22511&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D22511" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=22511" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=22511', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/how-to-create-singleton-class-in-java/">How To Create Singleton Class in Java</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/how-to-create-singleton-class-in-java/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Create Basic Hibernate Program</title>
		<link>https://www.automationdojos.com/create-hibernate-program/</link>
					<comments>https://www.automationdojos.com/create-hibernate-program/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Sat, 20 Jun 2020 00:45:00 +0000</pubDate>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ORM]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=21220</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/create-hibernate-program/">Create Basic Hibernate Program</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>Hibernate is an ORM framework that helps in accessing database tables from Java code. It is an object-oriented way of accessing database tables and it eliminates boilerplate code that is required with JDBC. In this article, I will be explaining how you can create a basic Hibernate application that saves a record into a database [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/create-hibernate-program/">Create Basic Hibernate Program</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/create-hibernate-program/">Create Basic Hibernate Program</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-create-Hibernate-program-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#prerequisites">Prerequisites</a>

</li>
<li><a href="#creating-a-database-table">Creating a database table</a>

</li>
<li><a href="#creating-pojo-class">Creating POJO class</a>

</li>
<li><a href="#create-hibernate-configuration-file">Create hibernate configuration file</a>

</li>
<li><a href="#writing-and-executing-code">Writing and executing code</a>
</li></ul>


<p class="wp-block-paragraph">Hibernate is an ORM framework that helps in accessing database tables from Java code. It is an object-oriented way of accessing database tables and it eliminates boilerplate code that is required with JDBC. </p>



<p class="wp-block-paragraph">In this article, I will be explaining how you can create a basic Hibernate application that saves a record into a database table via Hibernate.</p>


<h2 class="wp-block-heading" id="prerequisites">Prerequisites</h2>


<p class="wp-block-paragraph">Before writing code, you need to ensure that you have installed and configured the database that you will be connecting to from your Hibernate code. I will be using a MySQL database. You also need to ensure that you have the database driver JAR files as well as Hibernate JAR files. If you are using a MySQL database and Maven as the dependency management tool, you can add the following dependencies:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">  &lt;dependencies>
  	&lt;dependency>
  		&lt;groupId>org.hibernate&lt;/groupId>
  		&lt;artifactId>hibernate-core&lt;/artifactId>
  		&lt;version>5.3.4.Final&lt;/version>
  	&lt;/dependency>
  	&lt;dependency>
  		&lt;groupId>mysql&lt;/groupId>
  		&lt;artifactId>mysql-connector-java&lt;/artifactId>
  		&lt;version>8.0.12&lt;/version>
  	&lt;/dependency>
  &lt;/dependencies>
</pre>


<h2 class="wp-block-heading" id="creating-a-database-table">Creating a database table</h2>


<p class="wp-block-paragraph">Once the database is configured, you will need to create a database table which you will access via Hibernate. I will be using a table called STUDENT. You can create this table by running the following SQL:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">create table STUDENT (
   id INT NOT NULL auto_increment,
   full_name VARCHAR(50),
   marks     DOUBLE ,
   PRIMARY KEY (id)
);
</pre>



<p class="wp-block-paragraph">So, this is a <strong>Student</strong> table that capture student information. It has columns corresponding to the name of the Student and the marks obtained by the student. It also has an id column which is the primary key column.</p>


<h2 class="wp-block-heading" id="creating-pojo-class">Creating POJO class</h2>


<p class="wp-block-paragraph">Hibernate requires you to create a simple POJO class that has fields corresponding to the columns in the database table. The following code demonstrates a <strong>Student</strong> class corresponding to the <strong>Student</strong> table:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">@Entity
@Table(name = "Student")
public class Student {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	int id;
	
@Column(name="full_name")
String name;
	
	double marks;
}
</pre>



<p class="wp-block-paragraph">The Student class has some Hibernate annotations which tell Hibernate how to map this class to the database table. These are as follows:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px">



<ul class="wp-block-list" id="block-e96704d0-3185-440a-888d-f809d6f6b3fc"><li><i class="sui sui-database" style="color:#888"></i> <strong>@Entity</strong> – This annotation specifies that this is an entity class and that it maps to a database table.</li><li><i class="sui sui-database" style="color:#888"></i> <strong>@Table</strong> – This is an optional annotation that can be specified on the class. It indicates the name of the database table that the entity maps to. If not specified, it defaults to the entity name.</li><li><i class="sui sui-database" style="color:#888"></i> <strong>@Id</strong> – This is a field-level annotation. &nbsp;It indicates that the field that maps to the primary key column in the database.&nbsp;</li><li><i class="sui sui-database" style="color:#888"></i> <strong>@GeneratedValue</strong> &#8211; This annotation is used on the field with the @Id annotation and specifies how the primary key values will be generated. Hibernate supports many primary key generation strategies. Here, the <strong>GenerationType.IDENTITY</strong> is used which means that the primary key column is an auto incremented column in the database</li><li><i class="sui sui-database" style="color:#888"></i> <strong>@Column</strong> &#8211; This is an optional field-level annotation. It is used to specify the name and other details of the column to which the field is mapped.&nbsp; If not specified, it defaults to the field name.</li></ul>



<p class="wp-block-paragraph"></div>


<h2 class="wp-block-heading" id="create-hibernate-configuration-file">Create hibernate configuration file</h2>


<p class="wp-block-paragraph">Hibernate requires you to provide a configuration file that contains all the database related information like the database username, password etc. Hibernate uses this information to connect to the database. &nbsp;</p>



<p class="wp-block-paragraph">The following is a basic Hibernate configuration file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
&lt;hibernate-configuration>
	&lt;session-factory>
&lt;property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect&lt;/property> 
&lt;property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver&lt;/property>
		&lt;property name="hibernate.connection.url">URL&lt;/property>
		&lt;property name="hibernate.connection.username">username&lt;/property>
		&lt;property name="hibernate.connection.password">password&lt;/property>
		&lt;mapping class="demo.Student" />
	&lt;/session-factory>
&lt;/hibernate-configuration>
</pre>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px"><span style="font-size: inherit;"> </span></p>



<ul class="wp-block-list"><li><i class="sui sui-hand-o-right" style="color:#26852f"></i> <strong>Hibernate.dialect</strong> – This specifies the underlying database that hibernate should connect to. Hibernate uses this to generate database specific SQL statements. Since I’m using a MySQL database, I’ve specified <strong>MySQLDialect</strong>.</li><li><i class="sui sui-hand-o-right" style="color:#26852f"></i> <strong>hibernate.connection.driver_class</strong> – This specifies the JDBC driver class to be used. I’ve specified the MySQL JDBC driver.</li><li><i class="sui sui-hand-o-right" style="color:#26852f"></i> <strong>hibernate.connection.url </strong>– This specifies the database connection URL</li><li><i class="sui sui-hand-o-right" style="color:#26852f"></i> <strong>hibernate.connection.username</strong> – This specifies the database connection username</li><li><i class="sui sui-hand-o-right" style="color:#26852f"></i> <strong>hibernate.connection.password</strong> – This specifies the database connection password</li><li><i class="sui sui-hand-o-right" style="color:#26852f"></i> <strong>mapping-class</strong> – This specifies the name of the class that needs to be mapped to the database.</li></ul>



<p class="wp-block-paragraph"></div>



<p class="wp-block-paragraph">In addition, there are other several other properties that can be specified in the configuration file.</p>


<h2 class="wp-block-heading" id="writing-and-executing-code">Writing and executing code</h2>


<p class="wp-block-paragraph">After creating the POJO class and the Hibernate configuration file, the next step is to write the code that connects to the database as shown below:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public class Main {
	public static void main(String args[]) {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction tx = session.beginTransaction();
		Student student = new Student("John Doe",87.5);
		session.save(student);
		tx.commit();
		session.close();
		sessionFactory.close();
	}

} 
</pre>



<p class="wp-block-paragraph">This code creates a new Student object and saves it to the database. Let us take a closer look at the main parts of this code:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px"><ul> <li><i class="sui sui-check" style="color:#0d974b"></i> A <strong>SessionFactory </strong>object is first created. The SessionFactory contains all the data in the hibernate configuration file. It is usually created only once at the start of the application and kept for later use.</li>   <li><i class="sui sui-check" style="color:#0d974b"></i> A <strong>Session </strong>object is then created from the <strong>SessionFactory</strong>. A Session represents a physical connection with the database. The session object is used to actually save data and retrieve data from the database.</li> <li><i class="sui sui-check" style="color:#0d974b"></i> Next a Student <strong>object is created</strong> and the <strong>session.save</strong> method is invoked. This method call translates into an insert query and inserts a record corresponding to a Student into the Student database table</li></ul></div>



<p class="wp-block-paragraph">When this code is executed, a database record will be inserted into the <strong>Student</strong> table.</p>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21220" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21220" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21220" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21220&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21220" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=21220" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=21220', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/create-hibernate-program/">Create Basic Hibernate Program</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/create-hibernate-program/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Introduction to Apache Maven</title>
		<link>https://www.automationdojos.com/intro-to-apache-maven/</link>
					<comments>https://www.automationdojos.com/intro-to-apache-maven/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Tue, 09 Jun 2020 21:26:00 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache-maven]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=21186</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/intro-to-apache-maven/">Introduction to Apache Maven</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>1. What is Maven When you write a software application, there are many steps in it like adding the necessary JAR files, compiling the source code, running unit tests, creating the output jar/war file, etc. This is where Maven comes into play, it automates the build process, dependency management, testing, packaging, and much more. It [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/intro-to-apache-maven/">Introduction to Apache Maven</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/intro-to-apache-maven/">Introduction to Apache Maven</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post-intro-maven-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#1-what-is-maven">1. What is Maven</a>

</li>
<li><a href="#2-how-maven-works">2. How Maven Works</a>

</li>
<li><a href="#3-convention-over-configuration">3. Convention over Configuration</a>

</li>
<li><a href="#4-maven-coordinates">4. Maven Coordinates</a>

</li>
<li><a href="#5-pom-file">5. POM File</a>


<ul><li>
<a href="#51-super-pom">5.1. Super POM</a>

</li>
<li><a href="#52-effective-pom">5.2. Effective POM</a>

</li>
</ul>
<li><a href="#6-maven-directory-structure">6. Maven Directory Structure</a>

</li>
<li><a href="#7-maven-build-life-cycle">7. Maven Build Life Cycle</a>

</li>
<li><a href="#8-dependency-management">8. Dependency Management</a>


<ul><li>
<a href="#81-transitive-dependencies">(8.1) Transitive Dependencies</a>

</li>
<li><a href="#82-dependencies-and-scope">(8.2) Dependencies and Scope</a>

</li>
</ul>
<li><a href="#9-running-maven">9. Running Maven</a>

</li>
<li><a href="#10-conclusion">10. Conclusion</a>
</li></ul>

<h2 class="wp-block-heading" id="1-what-is-maven">1. What is Maven</h2>


<p class="wp-block-paragraph">When you write a software application, there are many steps in it like adding the necessary JAR files, compiling the source code, running unit tests, creating the output jar/war file, etc. </p>



<p class="wp-block-paragraph">This is where Maven comes into play, it automates the build process, dependency management, testing, packaging, and much more. It allows executing all these steps via simple pre-defined Maven commands thereby reducing human intervention and making the code less error-prone.</p>



<p class="wp-block-paragraph">On a high-level Maven caters for following aspects of dev project:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px"><ul><li><i class="sui sui-check" style="color:#40b05b"></i> Build Tool</li> <li><i class="sui sui-check" style="color:#40b05b"></i> Dependency Management</li> <li><i class="sui sui-check" style="color:#40b05b"></i> Artefact Repository System</li> <li><i class="sui sui-check" style="color:#40b05b"></i> Additional features via Plugins</li></ul></div>


<h2 class="wp-block-heading" id="2-how-maven-works">2. How Maven Works</h2>


<p class="wp-block-paragraph">The central concept in a Maven project is the POM file. In the <strong>POM file</strong>, developers need to specify how to configure, build and run an application. In addition, Maven provides <strong>build life cycles</strong> which consist of build <strong>phases</strong> and <strong>goals</strong>. &nbsp;</p>



<p class="wp-block-paragraph">Developers need to specify the phase or goal that needs to be executed. Maven then uses these instructions specified in the POM file to execute the specified phase or goal.</p>


<h2 class="wp-block-heading" id="3-convention-over-configuration">3. Convention over Configuration</h2>


<p class="wp-block-paragraph">Maven is based on the principle of <em>‘Convention over Configuration’</em> that keeps various project aspects and features standardized and systematic across all Maven projects. Thus, you can achieve consistent project aspects with little or even no configuration.<br></p>



<p class="wp-block-paragraph">These so-called ‘Conventions’ are based on best practices and backed up by reasonable defaults. An example of such a ‘convention’ in Maven would be the <strong>project directory structure</strong>. By default, Maven expects to find all main Java source code under <span class="su-label su-label-type-default">&#8220;src/main/java&#8221;</span> folder of your project and always looks at this path. Of course, you can override such defaults by customizing your configuration in POM file.</p>


<h2 class="wp-block-heading" id="4-maven-coordinates">4. Maven Coordinates</h2>


<p class="wp-block-paragraph">Maven coordinates are a set of identifiers that can be used to uniquely identify a project, a dependency, or a plugin in a Maven POM. &nbsp;All Maven project uses the <em>groupId</em>, <em>artifactId</em>, <em>version</em>, and the <em>packaging</em> property to uniquely identify every Maven component.</p>



<p class="wp-block-paragraph">The full Maven coordinates are often written in the following format: </p>



<pre class="wp-block-code"><code>groupId:artifactId:packaging:version</code></pre>



<p class="wp-block-paragraph"></p>


<h2 class="wp-block-heading" id="5-pom-file">5. POM File</h2>


<p class="wp-block-paragraph">The POM stands for <strong>Project Object Model</strong>. It is a declarative style, XML-based configuration file containing all the information required to build a project or even multiple projects. </p>



<p class="wp-block-paragraph">Hence every project has its own POM file which is generally located in the root of the source code directory. In the case of multiple projects, a pom file is placed in the root of the source code directory and lists the individual projects as <em>modules</em>.</p>



<p class="wp-block-paragraph">The following are the main elements in the POM file:</p>



<ul class="wp-block-list"><li><strong>Group Id/Artifact Id/Version (GAV)</strong> – These elements help to uniquely identify a project</li><li><strong>Packaging</strong> – This specifies the type of the output file like jar, war, etc.</li><li><strong>Dependencies</strong> – This specifies the external dependencies or jar files that an application requires. Maven automatically downloads the jar files specified here from a central repository</li><li><strong>Build</strong> – This specifies information like the goal to run by default if one is not explicitly specified, the directory where to place the output artifact, plugin information, etc.</li></ul>



<p class="wp-block-paragraph">Here is an example of a very simple POM file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  &lt;modelVersion>4.0.0&lt;/modelVersion>
  &lt;groupId>com.abc.xyz&lt;/groupId>
  &lt;artifactId>HibernateApp&lt;/artifactId>
  &lt;version>1&lt;/version>
  &lt;dependencies>
  	&lt;dependency>
  		&lt;groupId>org.hibernate&lt;/groupId>
  		&lt;artifactId>hibernate-core&lt;/artifactId>
  		&lt;version>5.3.4.Final&lt;/version>
  	&lt;/dependency>
  	&lt;dependency>
  		&lt;groupId>mysql&lt;/groupId>
  		&lt;artifactId>mysql-connector-java&lt;/artifactId>
  		&lt;version>8.0.12&lt;/version>
  	&lt;/dependency>
  &lt;/dependencies>
&lt;/project>
</pre>



<p class="wp-block-paragraph">The POM file above specifies the <strong>group id</strong> as <strong>com.abc.xyz</strong>, <strong>artifact id</strong> as <strong>HibernateApp</strong> and <strong>version</strong> as <strong>1</strong>. In the dependencies section, it specifies the dependencies for Hibernate and the MySQL JDBC driver.</p>


<h3 class="wp-block-heading" id="51-super-pom">5.1. Super POM</h3>


<p class="wp-block-paragraph">All POMs inherit from a parent or default POM whether explicitly defined or not. In cases where no explicit parent POM is defined, it inherits from the default or base pom of Maven. </p>



<p class="wp-block-paragraph">In relation to POM, Maven has the concept of ‘Super POM’ which is considered as Maven&#8217;s default POM or base POM. This &#8216;Super POM&#8217; defines all <strong>default settings</strong>, which are automatically <strong>inherited </strong>by all Maven projects by ‘Inheritance’. This is one of the strategies by which <em>‘Convention over Configuration’</em> manifests in Maven.</p>



<p class="wp-block-paragraph">Under the inherited Super POM, each individual project implements its own local project POM (also Known as Simplest POM) providing its own unique information specific to that project including any overrides in that project&#8217;s POM file thereby achieving a project-specific and customized project POM.</p>


<h3 class="wp-block-heading" id="52-effective-pom">5.2. Effective POM</h3>


<p class="wp-block-paragraph">Maven always executes against an&nbsp;<em>effective pom</em>. This is an amalgamation or combination of settings from this project’s pom.xml, all parent pom (if declared), a super-pom, user-defined settings, and active profiles settings.</p>



<p class="wp-block-paragraph">This helps developers to specify minimum configuration detail in their Project POM while re-using the inherited default POM. You can see your effective POM by using the following command:</p>



<pre class="wp-block-code"><code>mvn help:effective-pom</code></pre>


<h2 class="wp-block-heading" id="6-maven-directory-structure">6. Maven Directory Structure</h2>


<p class="wp-block-paragraph">Maven defines a standard directory structure and always looks for these directories by default. Although you can certainly override or customize this directory structure via your POM configuration but by default Maven expects developers to follow this directory structure:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px">



<ul class="wp-block-list" id="block-082fae00-546e-49fa-a325-3308faadd9a5"><li><i class="sui sui-folder-open" style="color:#999"></i> <strong>pom.xml</strong> – The pom.xml should be in the root directory of your project</li><li><i class="sui sui-folder-open" style="color:#999"></i> <strong>src/main/java</strong> – Should contain Java source code</li><li><i class="sui sui-folder-open" style="color:#999"></i> <strong>src/main/resources</strong> – Should contain resources like configuration files, etc</li><li><i class="sui sui-folder-open" style="color:#999"></i> <strong>src/test/java</strong> – Should contain source code for unit tests</li><li><i class="sui sui-folder-open" style="color:#999"></i> <strong>src/test/resources</strong> – Should contain resources like configuration files for unit tests</li><li><i class="sui sui-folder-open" style="color:#999"></i> <strong>target</strong> – Maven places the .class files, output artifacts in this directory</li></ul>



<p class="wp-block-paragraph"></div>


<h2 class="wp-block-heading" id="7-maven-build-life-cycle">7. Maven Build Life Cycle</h2>


<p class="wp-block-paragraph">A build life cycle refers to a set of steps that are executed sequentially as part of a Maven build. Maven has 3 built in build lifecycles as follows:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px">



<ul class="wp-block-list" id="block-197c5769-05ec-4897-98c2-f0063003a926"><li><i class="sui sui-recycle" style="color:#2a9334"></i> clean</li><li><i class="sui sui-recycle" style="color:#2a9334"></i> default</li><li><i class="sui sui-recycle" style="color:#2a9334"></i> site</li></ul>



<p class="wp-block-paragraph"></div>



<p class="wp-block-paragraph">Each build lifecycle consists of a number of <strong>phases</strong>.</p>


<div class="su-box su-box-style-default" id="vp_mostviewed" style="border-color:#bfbfbf;border-radius:3px;"><div class="su-box-title" style="background-color:#f2f2f2;color:#6b6b6b;border-top-left-radius:1px;border-top-right-radius:1px">Build Phase</div><div class="su-box-content su-u-clearfix su-u-trim" style="border-bottom-left-radius:1px;border-bottom-right-radius:1px"> </p>
<p>A build phase represents a stage in the build life cycle and is responsible for a specific task. The following are some of the phases associated with the <strong>default</strong> lifecycle:</p>
<ul class="bullet-crank">
<li>validate</li>
<li>compile</li>
<li>test</li>
<li>package</li>
<li>verify</li>
<li>install</li>
<li>deploy</li>
</ul>
<p>These phases are executed sequentially. When you specify a phase that you want to be executed as part of a Maven build, Maven executes all the phases up to the specified phase sequentially. So, for example, if you specify that you want to run the <strong>install</strong> phase, all the phases starting with <strong>validate</strong> and up to <strong>install</strong> will get executed sequentially. Each phase consists of one or more <strong>plugin goals</strong>.</p>
</div></div>


<div class="su-box su-box-style-default" id="vp_mostviewed" style="border-color:#bfbfbf;border-radius:3px;"><div class="su-box-title" style="background-color:#f2f2f2;color:#6b6b6b;border-top-left-radius:1px;border-top-right-radius:1px">Plugin Goal</div><div class="su-box-content su-u-clearfix su-u-trim" style="border-bottom-left-radius:1px;border-bottom-right-radius:1px"> </p>
<p>A plugin goal represents a specific task that contributes to building a project. For example, the <strong>compile</strong> goal is responsible for compiling code.&nbsp; A goal may be associated with zero or more phases. When a phase is executed, it runs all the goals within that phase.</p>
</div></div>


<div class="su-box su-box-style-default" id="vp_mostviewed" style="border-color:#bfbfbf;border-radius:3px;"><div class="su-box-title" style="background-color:#f2f2f2;color:#6b6b6b;border-top-left-radius:1px;border-top-right-radius:1px">Plugin</div><div class="su-box-content su-u-clearfix su-u-trim" style="border-bottom-left-radius:1px;border-bottom-right-radius:1px">
<p>A Maven plugin is a container of goals. So, goals exist within plugins. Maven provides some built-in plugins that contain some goals. Developers can also define their own plugins. Plugins are not associated with phases and can be run independently.</p>
</div></div>


<h2 class="wp-block-heading" id="8-dependency-management">8. Dependency Management</h2>


<p class="wp-block-paragraph">In Maven, you just declare the external dependency in the&nbsp;<strong>dependencies</strong>&nbsp;section of the POM file. &nbsp;These dependencies could be a library, package, or plugin (mostly in the form of ‘.jars’) that is needed for your project. Then, Maven will automatically download these dependencies and any transitive dependencies along with them. Maven will recursively resolve any required dependencies for your project.</p>



<p class="wp-block-paragraph">All dependencies are downloaded from Maven repositories defined. But dependencies downloaded from the internet are stored locally as well in a local Maven repository like a local dependency cache. Hence Maven looks at the local repository first, for any dependencies, before going out to the internet for download.</p>



<p class="wp-block-paragraph">This local Maven repository is a folder called&nbsp;<strong>.m2/repository</strong>&nbsp;in the home directory. When a Maven build is run, it first checks if the jar files corresponding to the dependencies in the POM file are present in the local repository. If so, it uses them. If not, it downloads the JAR files from the&nbsp;Maven Central repository.&nbsp;</p>



<p class="wp-block-paragraph"><strong>Maven Central repository</strong>&nbsp;is a repository of a large number of JAR files that is maintained by the Maven community. Developers can also configure an alternate repository in the POM file. Downloaded JAR files are placed in the local repository.</p>


<h3 class="wp-block-heading" id="81-transitive-dependencies">(8.1) Transitive Dependencies</h3>


<p class="wp-block-paragraph">A transitive dependency is basically the <em>dependency of your dependency</em>, for example, you could be using a java library or package which could be dependent on another package which in turn could be dependent on another one, and so on. Such <strong>indirect dependencies</strong> are called &#8216;Transitive Dependencies&#8217;.</p>



<p class="wp-block-paragraph">One of the best features of Maven is automatically taking care of transitive dependencies which in some cases could prove very painful especially when there is a chain of transitive dependencies for a project.</p>


<h3 class="wp-block-heading" id="82-dependencies-and-scope">(8.2) Dependencies and Scope</h3>


<p class="wp-block-paragraph">Finally, dependencies can be bound to a specific scope, which defines when and where the dependencies are needed in your project. For example, the TestNG, JUint jars are needed for Testing, but they are not needed for deployment to an application server. Hence they will be bound to ‘Test’ phase rather then build or other phases.</p>



<p class="wp-block-paragraph">You can use the following command to print &#8216;dependencies&#8217; for your project:</p>



<pre class="wp-block-code"><code>mvn dependency:tree</code></pre>



<p class="wp-block-paragraph">The above command will first of all download Maven plugin called &#8216;maven-dependency-plugin&#8217; and then print dependencies for your project.</p>


<h2 class="wp-block-heading" id="9-running-maven">9. Running Maven</h2>


<p class="wp-block-paragraph">In order to run Maven, developers need to specify the Maven command (<strong>mvn</strong>). &nbsp;Along with the <strong>mvn</strong> command, the <strong>build phase/goal</strong> can also be specified. </p>



<p class="wp-block-paragraph">First of all, Maven resolves the dependencies specified in the dependencies section. After that, Maven runs the specified goals/phase. If a phase is specified, Maven sequentially executes all the phases before the specified phase. </p>



<p class="wp-block-paragraph">If developers do not specify a phase or goal along with the <strong>mvn</strong> command, the value specified under <strong>build/defaultGoal</strong> will be used. If this value is not specified, an error will occur. Also, the type of output artifact to be produced (specified in the packaging element), determines which goals will be executed as part of a phase.</p>


<h2 class="wp-block-heading" id="10-conclusion">10. Conclusion</h2>


<p class="wp-block-paragraph">So, to summarise, Maven is a dependency management tool that helps to configure, build and run an application. It uses an XML configuration file known as the POM file. It also follows a certain life cycle that consists of phases and goals. It executes the specified phases and goals as part of the build process.</p>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21186" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21186" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21186" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21186&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D21186" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=21186" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=21186', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/intro-to-apache-maven/">Introduction to Apache Maven</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/intro-to-apache-maven/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Getting Started With Hibernate</title>
		<link>https://www.automationdojos.com/getting-started-hibernate/</link>
					<comments>https://www.automationdojos.com/getting-started-hibernate/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Sat, 04 Apr 2020 14:54:00 +0000</pubDate>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ORM]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=20849</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/getting-started-hibernate/">Getting Started With Hibernate</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3.png 575w, https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>Introduction Hibernate is a framework which allows you to access database tables from Java code. Before Hibernate came into existence, JDBC was widely used. JDBC is an API to access a relational database from a java program. JDBC basically allows you to execute SQL statements from Java code, so any SQL statement which you can [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/getting-started-hibernate/">Getting Started With Hibernate</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/getting-started-hibernate/">Getting Started With Hibernate</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3.png 575w, https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2020/04/post_Hibernate3-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#introduction">Introduction</a>


<ul><li>
<a href="#how-jdbc-works">How JDBC works</a>

</li>
<li><a href="#problems-with-jdbc">Problems with JDBC</a>

</li>
<li><a href="#what-is-hibernate">What is Hibernate</a>

</li>
<li><a href="#why-hibernate">Why Hibernate</a>

</li>
<li><a href="#how-hibernate-works">How Hibernate works</a>

</li>
</ul>
<li><a href="#hibernate-integration-with-jpa">Hibernate Integration with JPA</a>

</li>
<li><a href="#conclusion">Conclusion</a>
</li></ul>

<h2 class="wp-block-heading" id="introduction">Introduction</h2>


<p class="wp-block-paragraph">Hibernate is a framework which allows you to access database tables from Java code. Before Hibernate came into existence, JDBC was widely used. JDBC is an API to access a relational database from a java program. JDBC basically allows you to execute SQL statements from Java code, so any SQL statement which you can run on a database directly, you can run it from your Java code via JDBC.</p>


<h3 class="wp-block-heading" id="how-jdbc-works">How JDBC works</h3>


<p class="wp-block-paragraph">JDBC requires writing code for connecting to the database, executing an SQL query and obtaining the results. The following code demonstrates this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Class.forName("com.mysql.jdbc.Driver"); //Register JDBC Driver
Connection conn = DriverManager.getConnection(url, username, password); //Open a //connection
Statement stmt = conn.createStatement(); //create a statement
ResultSet rs = stmt.executeQuery("Select * from person");// Execute a query
Person person = new Person();
while(rs.next()){ //iterate through the resultset
      String name = rs.getString("name"); 
	person.setName(name);
       //more code for other fields
 }
 rs.close();
 stmt.close();
 conn.close();
</pre>



<p class="wp-block-paragraph">This code queries a table called <strong>Person</strong> via JDBC. So, as you can see, you need to write a lot of code in order to query a table. The JDBC code needs you to register the JDBC driver, open a database connection, create a statement, execute the query, iterate through the results, map each field to the fields in an object and finally close the Resultset, Statement and Connection objects.</p>


<h3 class="wp-block-heading" id="problems-with-jdbc">Problems with JDBC</h3>


<p class="wp-block-paragraph">This code written via JDBC is not only bulky and difficult to read, but it has several other disadvantages too. It uses SQL directly in the code. So, if you use database specific SQL syntax, it becomes tedious to migrate to a different database. Secondly, it has a lot of boilerplate code like creating connections/statements and closing them. Also, it is not object oriented and it is hard to map database tables to objects in the code. Finally, it is not extensible. For example, if you want to make a change to a database table like adding or removing a column, the code needs to be modified in order for the changes to work.</p>


<h3 class="wp-block-heading" id="what-is-hibernate">What is Hibernate</h3>


<p class="wp-block-paragraph">Hibernate is an ORM tool.<strong> ORM</strong>&nbsp;is a programming technique that allows you to map Java objects to database tables and vice versa. Hibernate is one such ORM tool available for Java. There are other ORM tools like TopLink, Spring DAO, etc.</p>


<h3 class="wp-block-heading" id="why-hibernate">Why Hibernate</h3>


<p class="wp-block-paragraph">Hibernate or any ORM tool for that matter does away with most of the boilerplate stuff that is required by JDBC. &nbsp;The code that you need to write is more object oriented and directly maps the Java code with database tables.</p>



<p class="wp-block-paragraph">The above code can be rewritten using Hibernate as follows:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Person person = session.load(Person.class, 2);
tx.commit();
session.close();
HibernateUtil.closeSessionFactory();
</pre>



<p class="wp-block-paragraph">So, if you look at this code, it’s much cleaner. There are no SQL statements since your objects are mapped to tables.</p>


<h3 class="wp-block-heading" id="how-hibernate-works">How Hibernate works</h3>


<p class="wp-block-paragraph">In order to use Hibernate in your application you need to do the following:</p>



<p class="wp-block-paragraph"><div class="su-list" style="margin-left:0px">



<ul class="wp-block-list"><li><i class="sui sui-hand-o-right" style="color:#0eab3c"></i> Create a configuration file that has details about the database connection, URL, etc</li><li><i class="sui sui-hand-o-right" style="color:#0eab3c"></i> Create POJO classes corresponding to the database tables. So, each table needs to have a class with fields that correspond to the columns in the table.</li><li><i class="sui sui-hand-o-right" style="color:#0eab3c"></i> Provide mapping information either via an XML file or annotations. This mapping information specifies how each class maps to the corresponding database table</li><li><i class="sui sui-hand-o-right" style="color:#0eab3c"></i> Invoke methods on the Hibernate session interface to perform database operations</li></ul>



<p class="wp-block-paragraph"></div>



<p class="wp-block-paragraph">Hibernate uses the information in the configuration file to establish a database connection. It then uses the mapping information and maps the POJO class to the corresponding database table. When you invoke code to perform database operations, Hibernate automatically converts your code into SQL statements. &nbsp;So, compared to JDBC, Hibernate provides a much cleaner and easy to use approach.</p>


<h2 class="wp-block-heading" id="hibernate-integration-with-jpa">Hibernate Integration with JPA</h2>


<p class="wp-block-paragraph">JPA stands for Java Persistence API. Over time, just like Hibernate several ORM frameworks were developed. Each framework had its proprietary code. So, if developers wanted to switch from one framework to another, it was not possible. To address this issue, Java introduced the JPA specification. JPA was developed as a standard way to access relational tables from Java code. JPA is just a specification, it is not an implementation. So, if the proprietary frameworks implemented the JPA specification, it was possible to switch from one framework to the other.</p>



<p class="wp-block-paragraph">Over time, Hibernate was made JPA compatible, that is, it was made to implement the JPA specification. So, in addition to its own proprietary methods, Hibernate also supports JPA methods. So, if your application code uses the JPA specific methods in Hibernate, then it becomes easy to replace Hibernate with some other JPA implementation.</p>


<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>


<p class="wp-block-paragraph">Hibernate was developed to overcome the shortcomings of the JDBC framework.&nbsp; Compared to JDBC, it provides a more object oriented and cleaner approach to access database tables from Java code.&nbsp; In addition, Hibernate is also a JPA provider and implements the JPA specification.</p>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20849" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20849" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20849" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20849&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20849" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=20849" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=20849', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/getting-started-hibernate/">Getting Started With Hibernate</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/getting-started-hibernate/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Sort List in Java</title>
		<link>https://www.automationdojos.com/sort-list-in-java/</link>
					<comments>https://www.automationdojos.com/sort-list-in-java/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Tue, 10 Mar 2020 13:17:00 +0000</pubDate>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[How-To Java]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java-how-to]]></category>
		<category><![CDATA[java-list]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=20840</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/sort-list-in-java/">How To Sort List in Java</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>Introduction A List is an interface in the Java collection framework. It can be used to store objects. Programmers often encounter scenarios where they need to sort a List. There are several ways you can achieve this. In the next few sections, I will be going over each method in detail. 1. Using Collections.sort The [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/sort-list-in-java/">How To Sort List in Java</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/sort-list-in-java/">How To Sort List in Java</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_sort-list-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#introduction">Introduction</a>

</li>
<li><a href="#1-using-collectionssort">1. Using Collections.sort</a>


<ul><li>
<a href="#collectionssort-without-comparator">Collections.sort without Comparator</a>

</li>
<li><a href="#collectionssort-with-comparator">Collections.sort with Comparator</a>

</li>
</ul>
<li><a href="#2-using-listsort">2. Using List.sort</a>

</li>
<li><a href="#3-using-stream-api">3. Using Stream API</a>

</li>
<li><a href="#4-sorting-a-list-of-objects">4. Sorting a List of Objects</a>

</li>
<li><a href="#conclusion">Conclusion</a>
</li></ul>

<h2 class="wp-block-heading" id="introduction">Introduction</h2>


<p class="wp-block-paragraph">A List is an interface in the Java collection framework. It can be used to store objects. Programmers often encounter scenarios where they need to sort a List. There are several ways you can achieve this. In the next few sections, I will be going over each method in detail.</p>


<h2 class="wp-block-heading" id="1-using-collectionssort">1. Using Collections.sort</h2>


<p class="wp-block-paragraph">The Collection framework has the java.util.Collections class. This has a lot of utility methods that can be used to perform various operations on Collections. One of these is the Collections.sort method. There are two overloaded versions of this method as explained below.</p>



<div class="rt-block">
<h3 class="wp-block-heading" id="collectionssort-without-comparator"><strong>Collections.sort without Comparator</strong></h3>


<p class="wp-block-paragraph">This version of the Collections.sort method accepts as parameter a List object. It sorts the List according to the natural order of the elements in the List. The following code demonstrates this:</p>


<div class="su-spacer" style="height:20px"></div>


<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
public static void usingCollectionsSort() {
List&lt;Integer> input = Arrays.asList(34,12,67,8,91,54,24);
Collections.sort(input);
System.out.print("Sorted List:");
input.forEach(num -> System.out.print(num+" "));
}</pre>


<div class="su-spacer" style="height:20px"></div>


<p class="wp-block-paragraph">Here, the code creates a new List with some Integer values. As you can see this List is not sorted. The code then invokes the Collections.sort method. Since the natural ordering for Integers is ascending order, this sorts the List in ascending order. So, this code prints the following output:</p>



<pre class="wp-block-code"><code>Sorted List:8 12 24 34 54 67 91 </code></pre>


<div class="su-spacer" style="height:20px"></div>

<h3 class="wp-block-heading" id="collectionssort-with-comparator"><strong>Collections.sort with Comparator</strong></h3>


<p class="wp-block-paragraph">There is an overloaded version of the Collections.sort method. In addition to the List to be sorted, this method also accepts as parameter a Comparator. It then sorts the input List as per the specified Comparator. The following code demonstrates this:</p>


<div class="su-spacer" style="height:20px"></div>


<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
public static void usingCollectionsSortWithComparator() {
List&lt;Integer> input = Arrays.asList(34,12,67,8,91,54,24);
Collections.sort(input,(num1,num2) -> num2-num1);
System.out.print("Sorted List:");
input.forEach(num -> System.out.print(num+" "));
}
</pre>


<div class="su-spacer" style="height:20px"></div>


<p class="wp-block-paragraph">As before, this code creates an unsorted List with some values. The Collections.sort method is invoked with the input List and a lambda expression that implements the Comparator interface. Here, the lambda expression returns the difference of subtracting the first number from the second number. So, this is equivalent to sorting the List in descending order. So, this code prints the following output:</p>



<pre class="wp-block-code"><code>Sorted List:91 67 54 34 24 12 8</code></pre>

</div>


<h2 class="wp-block-heading" id="2-using-listsort">2. Using List.sort</h2>


<p class="wp-block-paragraph">Java 8 has added a sort method on the List interface. This can also be used to sort a List. It accepts as parameter a Comparator instance and sorts the List based on the specified Comparator. The following code demonstrates this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public static void usingListSortWithStrings() {
List&lt;String> input = Arrays.asList("Horse","Cat","Elephant","Giraffe");
	input.sort((str1,str2) -> str1.compareTo(str2));
	System.out.print("Sorted List:");
	input.forEach(num -> System.out.print(num+" "));

}
</pre>



<p class="wp-block-paragraph">In this case, the code creates a List of String values. The List.sort method is invoked using a lambda expression that compares the Strings and returns the result of comparison. This is equivalent to sorting the List in alphabetical order. So, this code prints the following output:</p>



<pre class="wp-block-code"><code>Sorted List:Cat Elephant Giraffe Horse</code></pre>



<p class="wp-block-paragraph">List.sort has better performance compared to Collections.sort. This is because Collections.sort sorts the List by dumping its contents in an array. List.sort on the other hands sorts inline.</p>


<h2 class="wp-block-heading" id="3-using-stream-api">3. Using Stream API</h2>


<p class="wp-block-paragraph">The Stream API added by Java 8 can also be used to perform several operations on Collections. The Stream interface has a method called sorted that sorts the element in the Stream as per their natural order.&nbsp; The following code demonstrates this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public static void usingStreamSort() {
	List&lt;Integer> input = Arrays.asList(34,12,67,8,91,54,24);
	Stream&lt;Integer> inputStream = input.stream();
	Stream&lt;Integer> sortedStream = inputStream.sorted();
	List&lt;Integer> output = sortedStream.collect(Collectors.toList());
	System.out.print("Sorted List:");
	output.forEach(num -> System.out.print(num+" "));
}
</pre>



<p class="wp-block-paragraph">Here, first the stream() method is invoked on the input List. This returns a Stream corresponding to the List. Then the sorted() method is invoked on the Stream. This returns a new Stream that is sorted. Finally, the collect() method is invoked which converts the Stream to a List back. So, this code prints the same output as before:</p>



<pre class="wp-block-code"><code>Sorted List:8 12 24 34 54 67 91</code></pre>



<p class="wp-block-paragraph">There is also an overloaded version of the sorted method that accepts as parameter a Comparator instance and sorts the input Stream as per the specified Comparator.</p>


<h2 class="wp-block-heading" id="4-sorting-a-list-of-objects">4. Sorting a List of Objects</h2>


<p class="wp-block-paragraph">Sometimes, you may have a List of objects and you may need to sort it based on some field in the class. You can achieve this by using a Comparator and either the Collections.sort of List.sort method.</p>



<p class="wp-block-paragraph">For example, suppose you have a Student class as follows:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public class Student {
	
	private String name;
	private double marks;
	//constructors, getters and setters
}
</pre>



<p class="wp-block-paragraph">And suppose you have a List of Student objects that need to be sorted based on the marks field. You can do this using the following code:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">List&lt;Student> input = new ArrayList&lt;Student>();
		
input.add(new Student("Bill",76));
input.add(new Student("Jane",94));
input.add(new Student("George",68));
	
input.sort((s1,s2) -> s1.getMarks() - s2.getMarks());
System.out.print("Sorted List:");
input.forEach(s -> System.out.print(s.getName()+" "));
</pre>



<p class="wp-block-paragraph">Here, we have used the List.sort method. The lambda expression passed to the sort method implements a Comparator and compares the marks fields. So, this code prints the following output: Sorted List:George Bill Jane</p>


<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>


<p class="wp-block-paragraph">So, there are several ways in which you can sort a List in Java. You can use the Collections.sort to sort as per the natural order or using a custom Comparator. You can use the List.sort with a custom Comparator as well. You can also use the Stream API to sort a List.</p>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20840" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20840" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20840" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20840&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20840" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=20840" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=20840', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/sort-list-in-java/">How To Sort List in Java</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/sort-list-in-java/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Convert String To Date in Java</title>
		<link>https://www.automationdojos.com/convert-string-to-date/</link>
					<comments>https://www.automationdojos.com/convert-string-to-date/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Tue, 04 Feb 2020 11:58:00 +0000</pubDate>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[How-To Java]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java-how-to]]></category>
		<category><![CDATA[java-strings]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=20831</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/convert-string-to-date/">How To Convert String To Date in Java</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date.png 575w, https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>Introduction There are often scenarios in programming, where you will need to convert a date in String format to an actual Date object. For example, such a scenario may occur when the date is read from an end user via a UI and sent to the back-end code. In this article, we will understand the [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/convert-string-to-date/">How To Convert String To Date in Java</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/convert-string-to-date/">How To Convert String To Date in Java</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date.png 575w, https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2020/02/post_howto_string-date-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#introduction">Introduction</a>

</li>
<li><a href="#java-date-handling">Java Date Handling</a>

</li>
<li><a href="#converting-string-to-javautildate">Converting String to java.util.Date</a>

</li>
<li><a href="#converting-string-to-javautilcalendar">Converting String to java.util.Calendar</a>

</li>
<li><a href="#converting-string-to-javatimelocaldate">Converting String to java.time.LocalDate</a>


<ul><li>
<a href="#localdate-without-formatter">LocalDate without Formatter</a>

</li>
<li><a href="#localdate-with-formatter">LocalDate with formatter</a>

</li>
</ul>
<li><a href="#conclusion">Conclusion</a>
</li></ul>

<h2 class="wp-block-heading" id="introduction">Introduction</h2>


<p class="wp-block-paragraph">There are often scenarios in programming, where you will need to convert a date in String format to an actual Date object. For example, such a scenario may occur when the date is read from an end user via a UI and sent to the back-end code. In this article, we will understand the different ways in which you can represent a date in Java and how you can convert a String date to each of these Date representations.</p>


<h2 class="wp-block-heading" id="java-date-handling">Java Date Handling</h2>


<p class="wp-block-paragraph">Before we dive into the details of how to convert a String to a Date, let us understand how Java handles Dates.  In Java, there are three main classes that can be used to represent a date. These are as follows:</p>


<div class="su-note"  style="border-color:#dcdcdc;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#f6f6f6;border-color:#ffffff;color:#444444;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">



<ul class="wp-block-list"><li>java.util.Date</li><li>java.util.Calendar</li><li>java.time.LocalDate</li></ul>



<p class="wp-block-paragraph"></div></div>



<p class="wp-block-paragraph">The java.util.Date and java.util.Calendar classes were present right from the early versions of Java. However, these classes have several issues. They are not very user friendly and they do not allow performing date time manipulation very easily. To address all these issues, Java 8 introduced the java.time.LocalDate class as part of DateTime API. The LocalDate class allows performing date operations easily.  So, if you have a String object, you can convert it to a java.util.Date, java.util.Calender object or a java.time.LocalDate object based on your requirements.</p>


<h2 class="wp-block-heading" id="converting-string-to-javautildate">Converting String to java.util.Date</h2>


<p class="wp-block-paragraph">Sometimes, you may need to convert a String to a java.util.Date object. For this, you need to use the SimpleDateFormat class. You need to specify the format in which the String date is present and invoke the parse method. The following code demonstrates how this can be done:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void convertToDate() throws ParseException {
	String strDate = "2015-06-12";
	SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
	Date date = dateFormatter.parse(strDate);
	System.out.println(date);
}
</pre>



<p class="wp-block-paragraph">This code creates a SimpleDateFormat instance. Since the input date is in the <strong>yyyy-MM-dd</strong> format, the SimpleDateFormat is created using this format. The parse() method is then invoked with the actual String date. This returns a java.util.Date object corresponding to the String. So, this code prints the following output:</p>



<pre class="wp-block-code"><code>Fri Jun 12 00:00:00 IST 2015</code></pre>



<p class="wp-block-paragraph">You can check out the API documentation for <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a> in order to understand the patterns that need to be specified for various date formats.</p>


<h2 class="wp-block-heading" id="converting-string-to-javautilcalendar">Converting String to java.util.Calendar</h2>


<p class="wp-block-paragraph">As mentioned earlier, the java.util.Calendar class also encapsulates a date. The Calendar class has some more features that the java.util.Date class. It provides the ability to extract the day, month, year and other fields corresponding to the date that the Calendar represents. So, sometimes, you may need to convert a String date to a Calendar instance. For this, you first need to convert the String date to a java.util.Date instance via the SimpleDateFormat class. You can then use this Date to create a Calendar instance. The following code demonstrates this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void convertToCalendar() throws ParseException {
String strDate = "2015-06-12";
	SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
	Date date = dateFormatter.parse(strDate);
	Calendar cal = Calendar.getInstance();
	cal.setTime(date);
	System.out.println(date);
}
</pre>



<p class="wp-block-paragraph">As before, this code uses a SimpleDateFormat and creates a java.util.Date instance from the String date. The Calendar.getInstance() method is invoked which creates a Calendar object corresponding to the current time. The calendar.setTime() method is then invoked with the Date object. This changes the Calendar’s time to the time in the Date object. So, this code prints the following output:</p>



<pre class="wp-block-code"><code>Fri Jun 12 00:00:00 IST 2015</code></pre>


<h2 class="wp-block-heading" id="converting-string-to-javatimelocaldate">Converting String to java.time.LocalDate</h2>


<p class="wp-block-paragraph">As mentioned earlier, in order to overcome the shortcomings of the Date and Calendar classes, Java 8 introduced the LocalDate class as part of the DateTime API. Compared to the java.util.Date and java.util.Calendar classes, the LocalDate class is much simpler to use.  Let us now understand how to convert a String date to a LocalDate instance.</p>



<div class="rt-block">
<h3 class="wp-block-heading" id="localdate-without-formatter">LocalDate without Formatter</h3>


<p class="wp-block-paragraph">The LocalDate class has a parse method. You can use this to convert a String to a LocalDate. The following code demonstrates this:</p>

<div class="su-spacer" style="height:20px"></div>

<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void convertToLocalDate() {
String strDate = "2015-06-12";
	LocalDate date = LocalDate.parse(strDate);
	System.out.println(date);
}
</pre>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">So, this code simply invokes the parse method with the String date object. It prints the following output: 2015-06-12</p>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">The LocalDate.parse() method requires the String date to be in the <strong>yyyy-MM-dd</strong> format. If the String date is in some other format, this method throws an Exception. There is an overloaded version of the parse method that can be used for such scenarios as explained in the next section.</p>

<div class="su-spacer" style="height:20px"></div>
<h3 class="wp-block-heading" id="localdate-with-formatter">LocalDate with formatter</h3>


<p class="wp-block-paragraph">The LocalDate class has an overloaded parse() method. In addition to the String Date, it accepts a DateTimeFormatter instance that specifies the format of the input date. So, this can be used in case the String date is not in the <strong>yyyy-MM-dd</strong> format. The following code demonstrates this:</p>

<div class="su-spacer" style="height:20px"></div>

<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void convertToLocalDateWithDateFormatter() { 
String strDate = "06/12/2015";
	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
	LocalDate date = LocalDate.parse(strDate,formatter);
	System.out.println(date);
}
</pre>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">In this case, the String date is in the <strong>dd/MM/YYYY</strong> format.&nbsp; A DateTimeFormatter instance is created with this pattern. The parse() method is then invoked with the String date and the DateTimeFormatter instance. So, this code prints the following output:</p>



<p class="wp-block-paragraph">2015-06-12</p>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">You can check out the API documentation for <a href="https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html">DateTimeFormatter</a> in order to understand the patterns that need to be specified for various date formats.</p>

</div>


<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>


<p class="wp-block-paragraph">So, in summary, you can use the java.util.Date, java.util.Calendar or the java. time.LocalDate classes to represent a date in Java. You can convert a String date to any of these methods using the methods demonstrated in this article.</p>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20831" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20831" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20831" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20831&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20831" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=20831" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=20831', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/convert-string-to-date/">How To Convert String To Date in Java</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/convert-string-to-date/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Concatenate Strings in Java</title>
		<link>https://www.automationdojos.com/concatenate-strings-in-java/</link>
					<comments>https://www.automationdojos.com/concatenate-strings-in-java/#respond</comments>
		
		<dc:creator><![CDATA[Tushar Sharma]]></dc:creator>
		<pubDate>Sat, 04 Jan 2020 10:00:00 +0000</pubDate>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[How-To Java]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[concatenate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java-how-to]]></category>
		<category><![CDATA[java-strings]]></category>
		<guid isPermaLink="false">https://www.automationdojos.com/?p=20809</guid>

					<description><![CDATA[<p><a href="https://www.automationdojos.com/concatenate-strings-in-java/">How To Concatenate Strings in Java</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>Introduction In Java, a String is a sequence of characters. There are often programming situations where you will need to concatenate Strings. There are several ways in which you can achieve this. In the next few sections, I will be going over each method in detail. Using + Operator The + operator is also known [&#8230;]</p>
<p>The post <a href="https://www.automationdojos.com/concatenate-strings-in-java/">How To Concatenate Strings in Java</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.automationdojos.com/concatenate-strings-in-java/">How To Concatenate Strings in Java</a> | As Published On <a href="https://www.automationdojos.com">Automation Dojos</a></p>
<p><img width="575" height="345" src="https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async" loading="lazy" srcset="https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java.png 575w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java-300x180.png 300w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java-150x90.png 150w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java-200x120.png 200w, https://www.automationdojos.com/wp-content/uploads/2021/10/post_howto_concatenate-java-400x240.png 400w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p><h2 class="simpletoc-title">Table of Contents</h2>
<ul class="simpletoc-list">
<li><a href="#introduction">Introduction</a>

</li>
<li><a href="#using-operator">Using + Operator</a>

</li>
<li><a href="#using-stringconcat">Using String.concat</a>

</li>
<li><a href="#using-stringbufferstringbuilder">Using StringBuffer/StringBuilder</a>


<ul><li>
<a href="#using-stringbuffer-for-strings">Using StringBuffer for Strings</a>

</li>
<li><a href="#using-stringbuffer-for-other-types-of-data">Using StringBuffer for other types of data</a>

</li>
<li><a href="#using-stringbuilder">Using StringBuilder</a>

</li>
</ul>
<li><a href="#using-stringjoin">Using String.join</a>


<ul><li>
<a href="#stringjoin-for-multiple-strings">String.join for multiple Strings</a>

</li>
<li><a href="#stringjoin-for-a-collection">String.join for a Collection</a>

</li>
</ul>
<li><a href="#using-stringjoiner">Using StringJoiner</a>

</li>
<li><a href="#conclusion">Conclusion</a>
</li></ul>

<h2 class="wp-block-heading" id="introduction">Introduction</h2>


<p class="wp-block-paragraph">In Java, a String is a sequence of characters. There are often programming situations where you will need to concatenate Strings. There are several ways in which you can achieve this. In the next few sections, I will be going over each method in detail.</p>


<h2 class="wp-block-heading" id="using-operator">Using + Operator</h2>


<p class="wp-block-paragraph">The + operator is also known as the concatenation operator. It can be used to concatenate Strings. The following code demonstrates this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void usingPlusOperator() {
String string1 = "Hello ";
	String string2 = "World";
	String result = string1+string2;
	System.out.println(result);
}</pre>



<p class="wp-block-paragraph">This code creates two Strings called string1 and string2. It uses the + operator to concatenate them and assign the result to a separate variable. So, this code prints the following output:</p>



<pre class="wp-block-code"><code>Hello World</code></pre>



<p class="wp-block-paragraph">This approach can be used to concatenate more than two values. Not only that, it can be used to concatenate other types of values like primitives as shown below:</p>



<pre class="wp-block-code"><code>String result = “Hello”+” World”+” 2“+” times!”; </code></pre>



<p class="wp-block-paragraph">So, this code prints the following output:</p>



<pre class="wp-block-code"><code>Hello World 2 times!</code></pre>



<p class="wp-block-paragraph">The downside of this approach is that it is not very efficient. Since String is immutable, every time you use the + operator, a new String is created.</p>


<h2 class="wp-block-heading" id="using-stringconcat">Using String.concat</h2>


<p class="wp-block-paragraph">The String class has a method called concat. It accepts as parameter a String value and concatenates it with the current String. The following code demonstrates this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void usingStringConcat() {
	String string1 = "Hello ";
	String string2 = "World";
	String result = string1.concat(string2);
	System.out.println(result);
}
</pre>



<p class="wp-block-paragraph">As before, this code creates string1 and string2.&nbsp; It then invokes the concat() method on string1 and passes string2 as an argument. So, this code also prints the same output as before:</p>



<pre class="wp-block-code"><code>Hello World</code></pre>



<p class="wp-block-paragraph">Performance-wise, this approach is not much better than using the + operator. Also, unlike the + operator, this approach cannot be used for multiple Strings or other types of values.</p>


<h2 class="wp-block-heading" id="using-stringbufferstringbuilder">Using StringBuffer/StringBuilder</h2>


<p class="wp-block-paragraph">In addition to String, Java has the java.lang.StringBuffer and java.lang.StringBuilder classes. These can also be used to concatenate Strings.  The advantage of these classes is that both these classes are mutable, so using them does not result in the creation of new String objects. So StringBuffer and StringBuilder have a better performance as compared to the + operator and concat method.</p>



<div class="rt-block">
<h3 class="wp-block-heading" id="using-stringbuffer-for-strings">Using StringBuffer for Strings</h3>


<p class="wp-block-paragraph">The StringBuffer class has a method called append which can be used to concatenate Strings. It appends the value passed in with the StringBuffer on which it is invoked. The following code demonstrates this:</p>

<div class="su-spacer" style="height:20px"></div>

<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void usingStringBuffer() {
String string1 = "Hello ";
	String string2 = "World";
	StringBuffer result = new StringBuffer();
	result.append(string1);
	result.append(string2);
	System.out.println(result);
}
</pre>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">As before, this code creates string1 and string2.&nbsp; It also creates a StringBuffer called result. It then invokes the append method with both the Strings. So, this code also prints the same output as before: Hello World</p>

<div class="su-spacer" style="height:20px"></div>
<h3 class="wp-block-heading" id="using-stringbuffer-for-other-types-of-data">Using StringBuffer for other types of data</h3>


<p class="wp-block-paragraph">There are several overloaded versions of the append method that accept data of different types like primitive values, character arrays and Strings. These methods can be used to append different types of data as demonstrated below:</p>

<div class="su-spacer" style="height:20px"></div>

<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">StringBuffer result = new StringBuffer();
result.append("Hello").append(" World ").append(2).append(" times!");
</pre>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">So, this code prints the following output: Hello World 2 times!</p>

<div class="su-spacer" style="height:20px"></div>
<h3 class="wp-block-heading" id="using-stringbuilder">Using StringBuilder</h3>


<p class="wp-block-paragraph">The StringBuilder class is very similar to StringBuffer. It also has a method called append which can be used to concatenate Strings. The only difference is that StringBuffer is synchronised while StringBuilder is not. So StringBuilder has a slight performance advantage over StringBuffer.</p>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">The following code demonstrates the StringBuilder.append method:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void usingStringBuilder() {
String string1 = "Hello ";
	String string2 = "World";
	StringBuilder result = new StringBuilder();
	result.append(string1);
	result.append(string2);
	System.out.println(result);
}
</pre>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">So, this code is exactly the same as the StringBuffer code and it prints the following output: Hello World</p>

</div>


<h2 class="wp-block-heading" id="using-stringjoin">Using String.join</h2>


<p class="wp-block-paragraph">Java 8 has added a static join method to the String class. This concatenates Strings using a delimiter. Performance-wise, it is similar to StringBuffer.append, but it has the added advantage that it automatically adds a delimiter.</p>



<div class="rt-block">
<h3 class="wp-block-heading" id="stringjoin-for-multiple-strings">String.join for multiple Strings</h3>


<p class="wp-block-paragraph">&nbsp;The String.join() method accepts as parameter a variable number of Strings that need to be concatenated as well as a delimiter to separate the Strings. The following code demonstrates this:</p>

<div class="su-spacer" style="height:20px"></div>

<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void usingStringJoin() {

String string1 = "red";
	String string2 = "blue";
	String result = String.join(" ", string1,string2);
	System.out.println(result);

}
</pre>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">As before, this code creates string1 and string2.&nbsp; It invokes the join method with these Strings and specifies space (“ “) as a delimiter. So, this code prints the following output: red blue</p>

<div class="su-spacer" style="height:20px"></div>
<h3 class="wp-block-heading" id="stringjoin-for-a-collection">String.join for a Collection</h3>


<p class="wp-block-paragraph">There is also an overloaded version of the String.join method that accepts as parameter an Iterable implementation. Since all Collection classes implement the Iterable interface, this method can be used to concatenate all the elements in a Collection. The following code demonstrates this:</p>

<div class="su-spacer" style="height:20px"></div>

<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void usingStringJoinWithList() {

List&lt;String> colours = Arrays.asList("red","blue","green","white");
	String result = String.join("/", colours);
	System.out.println(result);

}
</pre>

<div class="su-spacer" style="height:20px"></div>

<p class="wp-block-paragraph">This code creates a List of String values and passes this List to the String.join method with a “/” as the delimiter. So, this code prints the following output: red/blue/green/white</p>

</div>


<h2 class="wp-block-heading" id="using-stringjoiner">Using StringJoiner</h2>


<p class="wp-block-paragraph">Java 8 has added a new class called StringJoiner. This concatenates Strings using a delimiter as well as adds a prefix and suffix to the concatenated String. Performance wise, it is similar to StringBuffer.append, but it has the added advantage that it automatically adds a delimiter, prefix and suffix.</p>



<p class="wp-block-paragraph">The following code demonstrates how the StringJoiner class can be used to concatenate Strings:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">private static void usingStringJoiner() {

	StringJoiner strJoiner = new StringJoiner(",","{","}");	strJoiner.add("red");
	strJoiner.add("blue");
	strJoiner.add("green");
	System.out.println(strJoiner);

}
</pre>



<p class="wp-block-paragraph">This code creates a StringJoiner. It specifies that a comma symbol (,) should be used as the delimiter. It also specifies that the “{“should be used as the prefix and “}” should be used as the suffix. It then invokes the add method with some String values. So, this concatenates the specified Strings using the specified delimiter, prefix and suffix. So, this code prints the following output: {red,blue,green}</p>


<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>


<p class="wp-block-paragraph">So, as seen in this article, there are several ways in which you can concatenate Strings in Java. The approach that you need to choose depends on your requirements and performance consideration. If you want to simply concatenate Strings without a delimiter, using a StringBuffer or StringBuilder is a better approach. However, if you want to add delimiters/prefix/suffix, consider going for the String.join or StringJoiner method. &nbsp;</p>
<div class='the_champ_sharing_container the_champ_vertical_sharing the_champ_hide_sharing the_champ_bottom_sharing' style='width:42px;left: -10px;top: 222px;-webkit-box-shadow:none;box-shadow:none;' data-super-socializer-href="https://www.automationdojos.com/tag/java/feed/"><div class="the_champ_sharing_ul"><a aria-label="Facebook" class="the_champ_facebook" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20809" title="Facebook" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#0765FE;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path fill="#484848" d="M28 16c0-6.627-5.373-12-12-12S4 9.373 4 16c0 5.628 3.875 10.35 9.101 11.647v-7.98h-2.474V16H13.1v-1.58c0-4.085 1.849-5.978 5.859-5.978.76 0 2.072.15 2.608.298v3.325c-.283-.03-.775-.045-1.386-.045-1.967 0-2.728.745-2.728 2.683V16h3.92l-.673 3.667h-3.247v8.245C23.395 27.195 28 22.135 28 16Z"></path></svg></span></a><a aria-label="Twitter" class="the_champ_button_twitter" href="https://twitter.com/intent/tweet?via=@testoxide&text=java&url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20809" title="Twitter" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_twitter" style="background-color:#55acee;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-4 -4 39 39"><path d="M28 8.557a9.913 9.913 0 0 1-2.828.775 4.93 4.93 0 0 0 2.166-2.725 9.738 9.738 0 0 1-3.13 1.194 4.92 4.92 0 0 0-3.593-1.55 4.924 4.924 0 0 0-4.794 6.049c-4.09-.21-7.72-2.17-10.15-5.15a4.942 4.942 0 0 0-.665 2.477c0 1.71.87 3.214 2.19 4.1a4.968 4.968 0 0 1-2.23-.616v.06c0 2.39 1.7 4.38 3.952 4.83-.414.115-.85.174-1.297.174-.318 0-.626-.03-.928-.086a4.935 4.935 0 0 0 4.6 3.42 9.893 9.893 0 0 1-6.114 2.107c-.398 0-.79-.023-1.175-.068a13.953 13.953 0 0 0 7.55 2.213c9.056 0 14.01-7.507 14.01-14.013 0-.213-.005-.426-.015-.637.96-.695 1.795-1.56 2.455-2.55z" fill="#484848"></path></svg></span></a><a aria-label="Linkedin" class="the_champ_button_linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20809" title="Linkedin" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_linkedin" style="background-color:#0077b5;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><path d="M6.227 12.61h4.19v13.48h-4.19V12.61zm2.095-6.7a2.43 2.43 0 0 1 0 4.86c-1.344 0-2.428-1.09-2.428-2.43s1.084-2.43 2.428-2.43m4.72 6.7h4.02v1.84h.058c.56-1.058 1.927-2.176 3.965-2.176 4.238 0 5.02 2.792 5.02 6.42v7.395h-4.183v-6.56c0-1.564-.03-3.574-2.178-3.574-2.18 0-2.514 1.7-2.514 3.46v6.668h-4.187V12.61z" fill="#484848"></path></svg></span></a><a aria-label="Pinterest" class="the_champ_button_pinterest" href="https://www.automationdojos.com/tag/java/feed/" onclick="event.preventDefault();javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());" title="Pinterest" rel="noopener" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_pinterest" style="background-color:#cc2329;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-2 -2 35 35"><path fill="#484848" d="M16.539 4.5c-6.277 0-9.442 4.5-9.442 8.253 0 2.272.86 4.293 2.705 5.046.303.125.574.005.662-.33.061-.231.205-.816.27-1.06.088-.331.053-.447-.191-.736-.532-.627-.873-1.439-.873-2.591 0-3.338 2.498-6.327 6.505-6.327 3.548 0 5.497 2.168 5.497 5.062 0 3.81-1.686 7.025-4.188 7.025-1.382 0-2.416-1.142-2.085-2.545.397-1.674 1.166-3.48 1.166-4.689 0-1.081-.581-1.983-1.782-1.983-1.413 0-2.548 1.462-2.548 3.419 0 1.247.421 2.091.421 2.091l-1.699 7.199c-.505 2.137-.076 4.755-.039 5.019.021.158.223.196.314.077.13-.17 1.813-2.247 2.384-4.324.162-.587.929-3.631.929-3.631.46.876 1.801 1.646 3.227 1.646 4.247 0 7.128-3.871 7.128-9.053.003-3.918-3.317-7.568-8.361-7.568z"/></svg></span></a><a aria-label="Reddit" class="the_champ_button_reddit" href="https://reddit.com/submit?url=https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20809&title=java" title="Reddit" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg the_champ_s__default the_champ_s_reddit" style="background-color:#ff5700;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-3.5 -3.5 39 39"><path d="M28.543 15.774a2.953 2.953 0 0 0-2.951-2.949 2.882 2.882 0 0 0-1.9.713 14.075 14.075 0 0 0-6.85-2.044l1.38-4.349 3.768.884a2.452 2.452 0 1 0 .24-1.176l-4.274-1a.6.6 0 0 0-.709.4l-1.659 5.224a14.314 14.314 0 0 0-7.316 2.029 2.908 2.908 0 0 0-1.872-.681 2.942 2.942 0 0 0-1.618 5.4 5.109 5.109 0 0 0-.062.765c0 4.158 5.037 7.541 11.229 7.541s11.22-3.383 11.22-7.541a5.2 5.2 0 0 0-.053-.706 2.963 2.963 0 0 0 1.427-2.51zm-18.008 1.88a1.753 1.753 0 0 1 1.73-1.74 1.73 1.73 0 0 1 1.709 1.74 1.709 1.709 0 0 1-1.709 1.711 1.733 1.733 0 0 1-1.73-1.711zm9.565 4.968a5.573 5.573 0 0 1-4.081 1.272h-.032a5.576 5.576 0 0 1-4.087-1.272.6.6 0 0 1 .844-.854 4.5 4.5 0 0 0 3.238.927h.032a4.5 4.5 0 0 0 3.237-.927.6.6 0 1 1 .844.854zm-.331-3.256a1.726 1.726 0 1 1 1.709-1.712 1.717 1.717 0 0 1-1.712 1.712z" fill="#484848"/></svg></span></a><a aria-label="Whatsapp" class="the_champ_whatsapp" href="https://api.whatsapp.com/send?text=java https%3A%2F%2Fwww.automationdojos.com%2F%3Fp%3D20809" title="Whatsapp" rel="nofollow noopener" target="_blank" style="font-size:24px!important;box-shadow:none;display:inline-block;vertical-align:middle"><span class="the_champ_svg" style="background-color:#55eb4c;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block;opacity:1;float:left;font-size:24px;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box"><svg style="display:block;" focusable="false" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="-6 -5 40 40"><path class="the_champ_svg_stroke the_champ_no_fill" stroke="#484848" stroke-width="2" fill="none" d="M 11.579798566743314 24.396926207859085 A 10 10 0 1 0 6.808479557110079 20.73576436351046"></path><path d="M 7 19 l -1 6 l 6 -1" class="the_champ_no_fill the_champ_svg_stroke" stroke="#484848" stroke-width="2" fill="none"></path><path d="M 10 10 q -1 8 8 11 c 5 -1 0 -6 -1 -3 q -4 -3 -5 -5 c 4 -2 -1 -5 -1 -4" fill="#484848"></path></svg></span></a><a class="the_champ_more" title="More" rel="nofollow noopener" style="font-size:24px!important;border:0;box-shadow:none;display:inline-block!important;font-size:16px;padding:0 4px;vertical-align: middle;display:inline;" href="https://www.automationdojos.com/?p=20809" onclick="event.preventDefault()"><span class="the_champ_svg" style="background-color:#ee8e2d;width:38px;height:38px;border-radius:3px;margin:0;display:inline-block!important;opacity:1;float:left;font-size:32px!important;box-shadow:none;display:inline-block;font-size:16px;padding:0 4px;vertical-align:middle;display:inline;background-repeat:repeat;overflow:hidden;padding:0;cursor:pointer;box-sizing:content-box;" onclick="theChampMoreSharingPopup(this, 'https://www.automationdojos.com/?p=20809', 'java', '' )"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-.3 0 32 32" version="1.1" width="100%" height="100%" style="display:block;" xml:space="preserve"><g><path fill="#484848" d="M18 14V8h-4v6H8v4h6v6h4v-6h6v-4h-6z" fill-rule="evenodd"></path></g></svg></span></a></div></div><p>The post <a href="https://www.automationdojos.com/concatenate-strings-in-java/">How To Concatenate Strings in Java</a> appeared first on <a href="https://www.automationdojos.com">Automation Dojos</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.automationdojos.com/concatenate-strings-in-java/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
