<?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>Tips &amp; tricks &#8211; CodePills.com</title>
	<atom:link href="https://codepills.com/category/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Sat, 23 Mar 2024 08:42:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>How to figure out if a character in a string is a number</title>
		<link>https://codepills.com/how-to-figure-out-if-a-character-in-a-string-is-a-number/</link>
					<comments>https://codepills.com/how-to-figure-out-if-a-character-in-a-string-is-a-number/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Tue, 03 May 2022 13:49:33 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[char]]></category>
		<category><![CDATA[Character]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[String]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1301</guid>

					<description><![CDATA[This article is about multiple ways to pull a character from a string and check if it is a number. <a href="https://codepills.com/how-to-figure-out-if-a-character-in-a-string-is-a-number/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article will show how to figure out if a character in a string is a number. You might be wondering how to do it. There are multiple ways to determine if an individual or series of characters in the string classify as a number. So let&#8217;s look at various approaches for determining if the character is a number.</p>
<p><span id="more-1301"></span></p>
<h2>Using <em>Character</em> class</h2>
<p>First option is to select a character from string with help of <em>charAt()</em> method and the character position; and use <em>Character</em> class static method <em>isDigit()</em> to return <em>boolean</em> value.</p>
<pre><code class="language-java">String movie = "101 dalmatians";
System.out.println(movie);
boolean result = Character.isDigit(movie.charAt(0));
System.out.println("Is first letter number? Answer: " + result)</code></pre>
<p>The output will be:</p>
<pre><code class="language-bash">101 dalmatians
Is first letter number? true</code></pre>
<p>If we want to check if several characters are numbers, we can place the <em>isDigit()</em> method call inside the loop.</p>
<pre><code class="language-java">String movie = "101 dalmatians";
for (int i = 0; i <= movie.length() - 1; i++) {
    System.out.println(movie.charAt(i) + " -> " + Character.isDigit(movie.charAt(i)));
}</code></pre>
<p>The output of the above code will be:</p>
<pre><code class="language-bash">1 -> true
0 -> true
1 -> true
  -> false
d -> false
a -> false
l -> false
m -> false
a -> false
t -> false
i -> false
a -> false
n -> false
s -> false</code></pre>
<h2>Using Unicode check</h2>
<p>Using <em>Character</em> class static method <em>isDigit()</em> can be used on any Unicode character, not just 0-9 number range. You can use create number check at any <b>Unicode</b> character.</p>
<p>Here is an example of checking a number through a check of Unicode characters:</p>
<pre><code class="language-java">String movie = "101 dalmatians";
System.out.println(movie);
boolean char c = word.charAt(0);
boolean isDigit = (c >= '0' && c <= '9');
System.out.println(isDigit)</code></pre>
<pre><code class="language-bash">101 dalmatians
true</code></pre>
<h2>Using Regex</h2>
<p>Alternative way to using <em>Character</em> class static method <em>isDigit()</em> is to use solution based on <i>regex</i> output. However, this will require string to be instance of <em>String</em> class as we can conduct regex pattern search only on <em>String</em>.</p>
<p>Let us show you first regex pattern for searching digit in substring of length 1 on the instance <em>String</em> class named <em>word</em>:</p>
<pre><code class="language-java">word.substring(0, 1).matches("\\d")</code></pre>
<p>The alternative and equivalent version uses the regex search pattern with the search of digit range.</p>
<pre><code class="language-java">word.substring(0, 1).matches("[0-9]")</code></pre>
<p>The regex solution should be discouraged as it is an over-engineered solution. While there might be a minor performance hit, we can argue it would not affect simple coding solutions. But be aware that regex brings complexity. A solution implementing regular expression should be used with caution and with a fair amount of tests.</p>
<p><b>Note:</b> Regular expressions are very strong, but expensive tool. It is valid to use regular expressions for character check if, e.g. the first character is a digit. But performance-wise, it is also like shooting birds with cannon.</p>
<h2>Using casting</h2>
<p>The last way to check if the character in a string is a number is to use Java casting feature. We will cast string values into one of the numerical object classes. However, this is the worst way how to do it. If you find a code using casting, you should refactor it immediately.</p>
<pre><code class="language-java">public boolean isNumber(String word) {
    boolean isNumber = true;
    try {
        Integer.valueOf(word.substring(0,1));
    } catch (Exception e) {
        isNumber = false;
    }
    return isNumber;
}</code></pre>
<p>There is a lot that can go wrong with the method above. If the entering argument word is an empty string, casting will throw <em>NumberFormatException</em> and catch it. If the first character is not a digit, e.g. letter or special symbol, casting will also throw <em>NumberFormatException</em> and catch it. But if the first character is a digit, it will return true.</p>
<p>You can place any numerical object class to the code such as <em>Integer</em>, <em>Double</em>, <em>Float</em> or <em>Long</em>. But please do not! Using casting with <em>valueOf()</em> method is wrong for two reason:</p>
<ul>
<li>In general, we want to avoid throwing <em>Exceptions</em>, checked or unchecked, as they slow the program and have tremendous performance hit.</li>
<li>Second reason, we can see above at least 3 different ways which provide shorter, more effective and readable way for solving the same problem.</li>
</ul>
<h2>Conclusion</h2>
<p>In the article, we have demonstrated four different ways to find out if the single character or characters from a string is a number or not. The solutions ranged from best to worst, from easiest to most cumbersome. Use as much as possible the first option which use <em>Character</em> class static method <em>isDigit()</em> for determining if the character is a string. Using <em>isDigit()</em> method is, without instantiation of any variables, the most effective and readable solution.</p>
<p>I hope you learned something new and had fun. Thanks for the reading. And if you have any tricks or know a better way <u>how to find out if the character is a string</u>, let us know in the comments below. We would like to hear your ideas.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-figure-out-if-a-character-in-a-string-is-a-number/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Developer Notes 001</title>
		<link>https://codepills.com/developer-notes-001/</link>
					<comments>https://codepills.com/developer-notes-001/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Sun, 01 May 2022 13:34:28 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[interpunct]]></category>
		<category><![CDATA[Jackson]]></category>
		<category><![CDATA[Java 8]]></category>
		<category><![CDATA[Lombok]]></category>
		<category><![CDATA[NUMBER]]></category>
		<category><![CDATA[Oracle DB]]></category>
		<category><![CDATA[Postman]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[Switch]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1298</guid>

					<description><![CDATA[The list of a few developer notes collected during the software development which were not enough for a self-standing article. <a href="https://codepills.com/developer-notes-001/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article selects a few developer notes collected during the software development, which were unfortunately not enough for a self-standing article.</p>
<p><span id="more-1298"></span></p>
<p>Developer notes will be an irregular series of articles where I will briefly go through some of my notes to make notes for posterity. The notes themself can be pretty long, yet their length is not enough for writing a meaningful article.</p>
<p>Let&#8217;s take a look at a list of content:</p>
<ul>
<li><a href="#oracle_error" title="Oracle Error: Value Larger Than Specified Precision Allowed For This Column">Oracle Error: Value Larger Than Specified Precision Allowed For This Column</a></li>
<li><a href="#switch_on_string_with_enum_name_in_java_8" title="Switch on String in Java">Switch on String with Enum Name in Java 8</a></li>
<li><a href="#lomboks_serialization_error_for_jackson" title="Lombok's serialization error for Jackson">Lombok&#8217;s serialization error for Jackson</a></li>
<li><a href="#interpunct" title="Interpunct">Interpunct</a></li>
<li><a href="#how_to_do_curl_in_postman" title="How To Do CURL in Postman">How To Do <em>curl</em> in Postman</a></li>
</ul>
<h2 id="oracle_error">Oracle Error: Value Larger Than Specified Precision Allowed For This Column</h2>
<p>I was getting errors on inserting data into the Oracle database &#8220;ORA-01438: value larger than specified precision allowed for this column.&#8221;</p>
<p>The reason why I was getting an error was a too big number. When I looked over UI to database column definition, I saw something like this NUMBER(15,2).</p>
<p>Official Oracle documentation, as for <a href="https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-75209AF6-476D-4C44-A5DC-5FA70D701B78" title="Number datatype" target="_blank" rel="nofollow noopener">Oracle database v21</a>, depicts <code>NUMBER</code> datatype defined as <code>NUMBER (precision,scale)</code>.</p>
<p><code>NUMBER</code> datatype notation can be rather rewritten to <i>NUMBER (size,precision)</i>) where the first number depicts the total size of the digits in a number, and the second means the decimal point scale.</p>
<p>In other words, for example, for <code>NUMBER(2,2)</code>, we can place the column number consisting of 2 digits, both of which will be decimals. i.e. 0.15, 0.45 etc. But if we would like to have a bigger number in the column, we need to upgrade the size of the column reserved for the whole number &#8211; <code>NUMBER(5,2)</code> will get us five digits, of which 2 are decimals. i.e 125.40, 18.00.</p>
<h2 id="switch_on_string_with_enum_name_in_java_8">Switch on String with Enum Name in Java 8</h2>
<p>Here is an example of how to use <em>Enum</em> values as strings in a <code>switch</code> case. You can only use the strings which are known at compile time. The compiler cannot determine the result of expression. However, in Java <em>Enum</em> case <code>VALUE1, VALUE2</code> are static.</p>
<pre><code class="language-java">String name = ...
switch(CustomEnum.valueOf(name)) {
   case VALUE1:
        ...
        break;
   case VALUE2:
        ...
        break;
    ...
}</code></pre>
<h2 id="lomboks_serialization_error_for_jackson">Lombok&#8217;s serialization error for Jackson</h2>
<p>When I created a new aggregated DTO class on my REST output, I got the following error:</p>
<pre><code class="language-bash">Type definition error: [simple type, class CUSTOM_DTO_CLASS_NAME]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class CUSTOM_DTO_CLASS_NAME and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: CUSTOM_DTO_CLASS_NAME[\"aggregation-class-property\"]->java.util.ArrayList[0])</code></pre>
<p>I am sure this error will be thrown quiet often as the solution on it is very simple. All I was missing on my <i>Custom DTO</i> class was <strong>Lombok&#8217;s</strong> <code>@Getters</code> annotation for serialization. So fix consisted on adding missing <code>@Getters</code> annotation on the top of my custom class for Lombok generating getter methods at compile time.</p>
<h2 id="interpunct">Interpunct</h2>
<p>I was editing my resume this month and wanted to create a nice date range in positions I held in the past. I got this from my LinkedIn profile, where LinkedIn use dates in the form as <em>Jan 2020 – Feb 2020 · 2 mos</em>. But I could not figure out where to take the dot sign as it was an image. However, the character for such sign as little black dot <strong>·</strong> really exists and its name is <strong>Interpunct</strong>,  or <strong>middle dot</strong>. So every time you would like to create a nice division of text with the help of <strong>·</strong>, think about the <strong>Interpunct</strong>.</p>
<h2 id="how_to_do_curl_in_postman">How To Do <em>curl</em> in Postman</h2>
<p>Is there a way hot to make a <em>curl</em> command in Postman? What if we would like to import the <em>curl</em> command easily into Postman and make a Postman GUI request from it.<br />
Is it even possible to easily translate all the <em>curl</em> command parameters into the Postman request?</p>
<p>Surely it is. Postman request are eventually nothing else than more fancy <em>curl</em> requests and Postman supports the <em>curl</em> import feature. Importing <em>curl</em> is very simple. Here is simple list of steps which will lead you to success:</p>
<ol>
<li>Open Postman.</li>
<li>Go to navigation menu, click File and Import option</li>
<li>In <i>Import</i> window select the raw text tab.</li>
<li>Paste the raw text e.g. <code>curl --location --request GET "https://www.google.com/"</code>, then click continue.</li>
<li>Check the name, format and import as.</li>
<li>If everything is correct, click <i>Import</i> button.</li>
</ol>
<p>Following the steps will automatically import the <em>curl</em> command into the Postman on the new tab.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/developer-notes-001/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Turn Number To String With Padded Space or Zeroes</title>
		<link>https://codepills.com/how-to-turn-number-to-string-with-padded-space-or-zeroes/</link>
					<comments>https://codepills.com/how-to-turn-number-to-string-with-padded-space-or-zeroes/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Fri, 01 Apr 2022 14:59:52 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[Formatter]]></category>
		<category><![CDATA[good practice]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[String]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1293</guid>

					<description><![CDATA[Article about a simple solution to turning numbers into specific length <em>String</em> with padded space. <a href="https://codepills.com/how-to-turn-number-to-string-with-padded-space-or-zeroes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article will show us how to turn numbers into the <em>String</em> with padded space or numbers.</p>
<p><span id="more-1293"></span></p>
<h2>Introduction</h2>
<p>I have been recently doing code review on other developer pull-request when I found the piece of code below:</p>
<pre><code class="language-java">private static final String DOCUMENT_VERSION = "document_version-";

public String getDocumentVersion(int version) {
    String documentVersion = "";
    if (version > 999) {
        throw new IllegalStateException("Version number " + version + " is too large.");
    } else if (version > 99) {
        documentVersion += version;
    } else if (version > 9) {
        documentVersion += "0" + version;
    } else {
        documentVersion += "00" + version;
    }

    return "DOCUMENT_VERSION_" + documentVersion;
}</code></pre>
<p>As you can immediately see, the code is bad and can be surely rewritten to something more simple. Creating a string from a number can not be so declarative, right? There needs to be a simpler way how to do it. And surely it can. Like many other general-purpose programming languages, Java has multiple libraries and functions for processing text. <em>String</em> class itself has a static method <em>format()</em> which can be fully utilized on the text changes like this.</p>
<h2>Java String format()</h2>
<p>The Java <em>String</em> class <em>format()</em> method returns the formatted string. Let&#8217;s look little bit on parameters of <em>format()</em> method.</p>
<h3>String.format() signature</h3>
<p>There are two type of <em>String format()</em> method:</p>
<pre><code class="language-java">public static String format(String format, Object... args)</code></pre>
<p>and</p>
<pre><code class="language-java">public static String format(Locale locale, String format, Object... args)  </code></pre>
<p>Therefore, method parameters are described as:</p>
<ul>
<li><b>locale</b> is specifies the locale to be applied on the format() method.</li>
<li><b>format</b> is format of the string.</li>
<li><b>args</b> represent arguments for the format string. It may be zero or more.</li>
</ul>
<p><em>format()</em> method returns new <em>String</em>. However, it is also good to be prepared for possibility of two unchecked exception:</p>
<ul>
<li><b>NullPointerException</b> is thrown if <b>format</b> is null.</li>
<li><b>IllegalFormatException</b> is thrown if <b>format</b> is illegal or incompatible.</li>
</ul>
<h3>String.format() internal implementation</h3>
<p>In reality, <em>String.format()</em> method allows usage of multiple <em>Object</em> arguments because internal implementation use nothing else than new instance of <em><a href="https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html" title="Java 8 Docs - Formatter Class" target="_blank" rel="nofollow noopener">Formatter</a></em> class.</p>
<pre><code class="language-java">public static String format(String format, Object... args) {
    return new Formatter().format(format, args).toString();
}</code></pre>
<p>Usage of quiet <em>Formatter</em> class explains why we can take multiple arguments depending on the number of elements we want to format inside the string. <em>Formatter</em> class can use several different option of &#8220;%&#8221; character combination in order to define string formatting. In the table below are all options explained:</p>
<table>
<thead>
<tr>
<th>Formatter Argument</th>
<th>Data Type</th>
<th>Output</th>
</tr>
</thead>
<tbody>
<tr>
<td>%a %A</td>
<td>floating point (except BigDecimal)</td>
<td>Returns Hex output of floating point number.</td>
</tr>
<tr>
<td>%b</td>
<td>Any type</td>
<td>&#8220;true&#8221; if non-null, &#8220;false&#8221; if null</td>
</tr>
<tr>
<td>%c</td>
<td>character</td>
<td>Unicode character</td>
</tr>
<tr>
<td>%d</td>
<td>integer (incl. byte, short, int, long, bigint)</td>
<td>Decimal Integer</td>
</tr>
<tr>
<td>%e</td>
<td>floating point</td>
<td>decimal number in scientific notation</td>
</tr>
<tr>
<td>%f</td>
<td>floating point</td>
<td>decimal number</td>
</tr>
<tr>
<td>%g</td>
<td>floating point</td>
<td>decimal number, possibly in scientific notation depending on the precision and value.</td>
</tr>
<tr>
<td>%h</td>
<td>any type</td>
<td>Hex String of value from hashCode() method.</td>
</tr>
<tr>
<td>%n</td>
<td>none</td>
<td>Platform-specific line separator.</td>
</tr>
<tr>
<td>%o</td>
<td>integer (incl. byte, short, int, long, bigint)</td>
<td>Octal number</td>
</tr>
<tr>
<td>%s</td>
<td>any type</td>
<td>String value</td>
</tr>
<tr>
<td>%t</td>
<td>Date/Time (incl. long, Calendar, Date and TemporalAccessor)</td>
<td>%t is the prefix for Date/Time conversions. More formatting flags are needed after this. See Date/Time conversion below.</td>
</tr>
<tr>
<td>%x</td>
<td>integer (incl. byte, short, int, long, bigint)</td>
<td>Hex string.</td>
</tr>
</tbody>
</table>
<h2><em>format()</em> examples</h2>
<p>Let us show you few tricks with <em>format()</em></p>
<pre><code class="language-bash">System.out.println(String.format("%d", 100)); // Integer
System.out.println(String.format("%s", "Anna Smith")); // String
System.out.println(String.format("%f", 42.42)); // Float
System.out.println(String.format("%x", 100)); // Hexadecimal
System.out.println(String.format("%c", 'a')); // Char
System.out.println("-----");
System.out.println(String.format("number with text: %d", 100)); // number with other text
System.out.println(String.format("%f", 42.12345)); // prints floating number
System.out.println(String.format("%10.10f", 42.12345)); // prints 10 digits for fractions padded with 0
System.out.println("-----");
System.out.println(String.format("|<-%10d->|", 222)); // Align right, padding with empty space
System.out.println(String.format("|<-%-10d->|", 555)); // Align left, padding with empty space
System.out.println(String.format("|<-% d->|", 777)); // Single space between % and conversion type is allowed
System.out.println(String.format("|<-%010d->|", 999)); // Filling space with zeros</code></pre>
<pre><code class="language-java">100
Anna Smith
42.420000
64
a
-----
number with text: 100
42.123450
42.1234500000
-----
|<-       222->|
|<-555       ->|
|<- 777->|
|<-0000000999->|</code></pre>
<h2>Using <em>format()</em> to turn number into formatted string</h2>
<p>To take for first exemplary code from code review, all what we needed to do in <code>getDocumentVersion()</code> method was to place custom format of string into the <em>String</em> class <em>format</em> method.</p>
<pre><code class="language-java">private static final String DOCUMENT_VERSION = "document_version-";

public String getDocumentVersion(int version) {
    return String.format(DOCUMENT_VERSION + "%03d", revisionNumber);
}</code></pre>
<p>If we place number 1 into the method <code>getDocumentVersion()</code> we will get the same result as boilerplate code from code review:</p>
<p><b>Output</b></p>
<pre><code class="language-bash">document_version-001</code></pre>
<p>We can still quickly write some custom code to test our beliefs. But be thorough and do not forget edge cases as zero and negative numbers.</p>
<pre><code class="language-java">System.out.println(String.format("%03d", 999));
System.out.println(String.format("%03d", 99));
System.out.println(String.format("%03d", 9));
System.out.println(String.format("%03d", 0));
System.out.println(String.format("%03d", -9));</code></pre>
<pre><code class="language-java">999
099
009
000
-09</code></pre>
<p>As you can notice <em>format()</em> takes negative number into account its length with minus sign.</p>
<p><b>Note</b> : If you have any crazy idea how to use <em>format()</em> method, let us know in comments below.</p>
<h2>Conclusion</h2>
<p>This article showed us how to turn a number into a string with a specific length where additional space is padded.</p>
<p>Did you find the <em>String.format()</em> method useful? Do you have your trick, or do you know another way <u>how to turn a number into a string of specific length</u>? Let us know in the comments below the article. We would like to hear your ideas and stories.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-turn-number-to-string-with-padded-space-or-zeroes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to convert private key DER to PEM file type</title>
		<link>https://codepills.com/how-to-convert-private-key-der-to-pem-file-type/</link>
					<comments>https://codepills.com/how-to-convert-private-key-der-to-pem-file-type/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Wed, 01 Dec 2021 19:00:34 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[KeyStore Explorer]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[windows]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1269</guid>

					<description><![CDATA[In this article I will show you quick work around how to turn <code>.pem</code> file type into the <code>.der</code> file type on Windows. <a href="https://codepills.com/how-to-convert-private-key-der-to-pem-file-type/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>In this article I will show you quick work around how to turn <code>.pem</code> file type into the <code>.der</code> file type on Windows.</p>
<p><span id="more-1269"></span></p>
<p>I had stuck on the problem when I needed to provide private key <code>.pem</code> file type for the OpenSSL command. However, the private key was saved in <code>.der</code> file type, so I needed to convert it.</p>
<p>There is a way to convert <code>.pem</code> file type on the Windows operating system to <code>.der</code> without using command line. Go to the Windows search bar and search for <b>KeyStore Explorer</b>. Open the KeyStore Explorer program. After opening the KeyStore Explorer, you should get the program screen like this:</p>
<div id="attachment_1270" style="width: 650px" class="wp-caption alignnone"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-1270" src="https://codepills.com/wp-content/uploads/2021/12/keystore_opened-1024x640.png" alt="KeyStore opened" width="640" height="400" class="size-large wp-image-1270" srcset="https://codepills.com/wp-content/uploads/2021/12/keystore_opened-1024x640.png 1024w, https://codepills.com/wp-content/uploads/2021/12/keystore_opened-300x187.png 300w, https://codepills.com/wp-content/uploads/2021/12/keystore_opened-768x480.png 768w, https://codepills.com/wp-content/uploads/2021/12/keystore_opened.png 1034w" sizes="(max-width: 640px) 100vw, 640px" /><p id="caption-attachment-1270" class="wp-caption-text">KeyStore opened</p></div>
<p>Click on the icon <i>Examine a Certificate</i>. From a system select your <code>.der</code> file. After selecting the <code>.der</code> you should get the KeyStore image like this:</p>
<div id="attachment_1272" style="width: 1008px" class="wp-caption alignnone"><img decoding="async" aria-describedby="caption-attachment-1272" src="https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_opened.png" alt="KeyStore - .der file opened" width="998" height="615" class="size-full wp-image-1272" srcset="https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_opened.png 998w, https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_opened-300x185.png 300w, https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_opened-768x473.png 768w" sizes="(max-width: 998px) 100vw, 998px" /><p id="caption-attachment-1272" class="wp-caption-text">KeyStore &#8211; .der file opened</p></div>
<p>Now all you need to do is to click on the <b>PEM</b> button. It will open you content of the <code>.der</code> file in <code>.pem</code> format.</p>
<div id="attachment_1270" style="width: 650px" class="wp-caption alignnone"><img decoding="async" aria-describedby="caption-attachment-1270" src="https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_turned_to_pem-1024x532.png" alt="KeyStore - .der file turned to .pem" width="640" height="333" class="size-large wp-image-1271" srcset="https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_turned_to_pem-1024x532.png 1024w, https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_turned_to_pem-300x156.png 300w, https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_turned_to_pem-768x399.png 768w, https://codepills.com/wp-content/uploads/2021/12/keystore_der_file_turned_to_pem.png 1244w" sizes="(max-width: 640px) 100vw, 640px" /><p id="caption-attachment-1270" class="wp-caption-text">KeyStore &#8211; .der file turned to .pem</p></div>
<p>You have now two options:</p>
<ul>
<li>You can either copy <code>.pem</code> file content into the system memory with <i>Copy</i> option.</li>
<li>Or you can export <code>.pem</code> file content on you machine disk with <i>Export</i> option.</li>
</ul>
<p><b>Note</b> : Never show or publish content of your private keys!</p>
<h2>Conclusion</h2>
<p>This article has shown how to turn <code>.pem</code> file type into the <code>.der</code> file type on Windows.</p>
<p>Did you find turning files easy? Do you have your trick or know another way <u>how to turn <code>.pem</code> file type into the <code>.der</code> file type</u>? Let us know in the comments below the article. We would like to hear your ideas and stories.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-convert-private-key-der-to-pem-file-type/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to print current project classpath</title>
		<link>https://codepills.com/how-to-print-current-project-classpath/</link>
					<comments>https://codepills.com/how-to-print-current-project-classpath/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Sun, 03 Oct 2021 13:44:55 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[classpath]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1259</guid>

					<description><![CDATA[This article is a short explanation of a classpath and a single line of Java code that will help you print out your classpath. <a href="https://codepills.com/how-to-print-current-project-classpath/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Imagine you want to figure out what is the path to your Java compiled classes. For that, you will need to print the classpath. This article is a short explanation of what a classpath is and a single line of Java code that will help you print out your classpath.</p>
<p><span id="more-1259"></span></p>
<h2>What is Java classpath?</h2>
<p>If we want to be wordy, <b>classpath</b> is the path where the Java Virtual Machine looks for user-defined classes, packages, and resources in Java programs. However, plain and straightforward, <b>classpath</b> is the route where the Java Virtual Machine will know where to find your compiled class.</p>
<p>Think of classpath as Java&#8217;s version of PATH environment variables &#8211; OSes search for executable files on the system environment PATH, Java searches for classes and packages on the classpath.</p>
<p>It would generally be impractical to have the JVM look through every folder on your machine. So you have to provide the JVM with a list of places where to look. Then, when we place folders and jar files on the classpath, we can automatically look up classes.</p>
<h2>How to print classpath?</h2>
<p>In Java, we can use a single line of code to print out the current project classpath. The only issue is with the system based classpath separator. On Unix based systems (Mac OS, CentOS, etc.), the colon character <code>:</code> is the classpath separator. However, on Windows, the separator is the semicolon <code>;</code>.</p>
<p>To print classpath at Unix based systems use:</p>
<pre><code class="language-java">System.out.println(System.getProperty("java.class.path").replace(':', '\n'));</code></pre>
<p>To print classpath at Windows use:</p>
<pre><code class="language-java">System.out.println(System.getProperty("java.class.path").replace(';', '\n'));</code></pre>
<p><b>Output</b></p>
<p>The code will work like a charm in new versions of Java (8, 11, &#8230;). However, the Java code snippet will also print library dependencies.</p>
<p>On Windows, the output can look something like the following example:</p>
<pre><code class="language-bash">
C:\DEV\programming\interview-preparation\trees\target\test-classes
C:\DEV\programming\interview-preparation\trees\target\classes
C:\Users\computer_user\.m2\repository\junit\junit\4.13.1\junit-4.13.1.jar
C:\Users\computer_user\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar
C:\Users\computer_user\.m2\repository\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar
...
</code></pre>
<p><b>Note</b>: If you have a better idea for printing classpath, let us know in the comments below.</p>
<h2>Conclusion</h2>
<p>Concisely, this article summarized what the classpath is and how to print classpath in your current Java project.</p>
<p>Did you find printing classpath easy? Do you have your trick or know another way how to print classpath? Let us know in the comments below the article. We would like to hear your ideas and stories.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-print-current-project-classpath/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to set custom configuration for your local Git project repository</title>
		<link>https://codepills.com/how-to-set-custom-configuration-for-your-local-git-project-repository/</link>
					<comments>https://codepills.com/how-to-set-custom-configuration-for-your-local-git-project-repository/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Thu, 01 Jul 2021 09:14:05 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[IntelliJ]]></category>
		<category><![CDATA[interactive rebase]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1243</guid>

					<description><![CDATA[Suppose you do not want to have the same configuration for your local repository as you have your global Git settings. Or you need to fix identity information for commits that are already made in Git commit history. In that case, this article will show you a few Git commands on how to set up the custom configuration for your local Git repository or how to fix past mistakes. <a href="https://codepills.com/how-to-set-custom-configuration-for-your-local-git-project-repository/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Suppose you do not want to have the same configuration for your local repository as you have your global Git settings. Or you need to fix identity information for commits that are already made in Git commit history. In that case, this article will show you a few Git commands on how to set up the custom configuration for your local Git repository or how to fix past mistakes.</p>
<p><span id="more-1243"></span></p>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#change_future_commits_author">Change Future Commits Author</a></li>
<ul>
<li><a href="#git_config_check">Git Config Check</a></li>
<li><a href="#git_global_configuration">Git Global Configuration</a></li>
<li><a href="#git_local_configuration">Git Local Configuration</a></li>
<li><a href="#author_identity_for_the_next_commit">Author Identity For the Next Commit</a></li>
</ul>
<li><a href="#change_past_commits_author">Change Past Commits Author</a></li>
<ul>
<li><a href="#git_ammend_with_author_flag">Git Ammend With Author Flag</a></li>
<li><a href="#git_interactive_rebase">Git Interactive Rebase</a></li>
<li><a href="#git_filter-branch">Git filter-branch Command</a></li>
</ul>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
<h2 id="introduction">Introduction</h2>
<p>There are two different needs in the request of changing author for your commits. Let&#8217;s make clear what are you really looking for:</p>
<ul>
<li>a) Either you want to change the author <b>before</b> making commit.</li>
<li>b) Or you want to change the author <b>after</b> you have made commit.</li>
</ul>
<p>In this article, we will look at both ways how to change the commit&#8217;s author identity.</p>
<h2 id="change_future_commits_author">Change Future Commits Author</h2>
<p>There are three different ways how to change identity for your Git committer. All the procedures only affect future commits and not the past commits made in the development line of your repository (commit history).</p>
<h3 id="git_config_check">Git Config Check</h3>
<p>Just a quick tip. To confirm your settings for global and local configuration you can type command:</p>
<pre><code class="language-bash">git config --list</code></pre>
<p><code>git config --list</code> will show global system git settings. If you run it inside a repository, it will also attach and show you the local configuration.</p>
<p>However, using following command might be more clearer:</p>
<pre><code class="language-bash">git config --list --show-origin</code></pre>
<p><code>git config --list --show-origin</code> command does all what <code>git config --list</code> does. Git command also attaches a path to the origin file of each config item in the list. Arguably, the attached path makes the settings look more understandable, and you can better connect items and their values for local and global Git settings.</p>
<h3 id="git_global_configuration">Git Global Configuration</h3>
<p>If you want to change your username and email by default for all project on your machine, edit global configuration settings. You can run the <code>git config</code> command with <code>--global</code> flag that will override your default Git settings and apply for all the future commits in your repositories. Git command for it looks like this:</p>
<pre><code class="language-bash">git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "EMAIL@example.com"</code></pre>
<h3 id="git_local_configuration">Git Local Configuration</h3>
<p>However, if you want to change your username and email only for single project, go to your repository and make git config adjustment like this:</p>
<pre><code class="language-bash">git config --local user.name "FIRST_NAME LAST_NAME"
git config --local user.email "EMAIL@example.com"</code></pre>
<p>Simply omit the <code>--global</code> flag and replace it with <code>--local</code> flag. <code>git config --local</code> makes the custom configuration valid only in the repository you made a change.</p>
<h3 id="author_identity_for_the_next_commit">Author Identity For the Next Commit</h3>
<p>There is at least one last way how to temporary influence the author identity of the commit. Just right before making the commit, add to <code>commit</code> command <code>--author</code> flag. When making the commit, you can override even local settings.</p>
<pre><code class="language-bash">git commit --author="FIRST_NAME LAST_NAME <EMAIL@example.com>"</code></pre>
<h2 id="change_past_commits_author">Change Past Commits Author</h2>
<p>Changing past commit authors in Git repositories is not so straightforward as it is for future ones. The issue lies in the fundamental idea of Git &#8211; its distributed asynchronous nature. You should be aware of one simple fact that you might cause a massive problem with synchronization if you work on the project with many team members.</p>
<p><strong>When you change Git commit author identity, you create an entirely new commit with a new hash; you are rewriting commit history and development branch.</strong> And while for a single individual repository user, this might not be a problem, for big teams, this might be a cause of enormous evil.</p>
<p>Therefore, let me give you a piece of good advice: if you are working in a team, a change in Git commit history should be adequately communicated with the rest of the team. It might happen that other team members already based their work on the existing commits, and additional changes would cause huge synchronization problems. Communicate with your team if you feel that commits might be already used as the base for other people work. Eventually, for good or bad, it might be possible even to avoid changing commit author identity, and either do rollback commit with new commit with correct author commit or, better, leave the commit history as it is. Commit change is much more critical in the long term as a person who made it (empirical experience &#8211; people come and go from teams, code stays forever).</p>
<h3 id="git_ammend_with_author_flag">Git Ammend With Author Flag</h3>
<p><code>git ammend</code> command is used to patch last commit in Git&#8217;s commit history. By attaching <code>--author</code> flag to <code>git ammend</code> command you can effectively rewrite commit author identity for the last commit in commit history.</p>
<h3 id="git_interactive_rebase">Git Interactive Rebase</h3>
<p><strong>Interactive rebase</strong> is a powerful feature of Git that allows you to edit Git commit history very effectively.</p>
<p>However, <strong>be careful with interactive rebase</strong>, it might shoot you in the foot if you will be not careful! Any changes made will affect your Git commit history. I would recommend to study deeper official Git documentation for <strong>interactive rebase</strong> before making any changes with it over console [<a href="https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages" title="" target="_blank" rel="nofollow noopener">7.6 Git Tools &#8211; Rewriting History</a>]. Otherwise I can really recommend using <strong>interactive rebase</strong> with IDE tools such as <strong>IntelliJ</strong>.</p>
<p>First step, you need to find commit you consider as base for your <strong>interactive rebase</strong>. Provide to git command commit&#8217;s hash like this:</p>
<pre><code class="language-bash">$ git rebase -i -p 9be2477a</code></pre>
<p><code>git rebase</code> command will open the interactive editor in which you need to mark all the commits you want to change. Selected commits will be marked with the red keyword &#8220;edit&#8221;.</p>
<pre><code class="language-bash"><span style="color: red">edit</span> 87bee32a Added new tests
<span style="color: red">edit</span> 1be09dcb Merge branch with hotfix for DJ-1041
<span style="color: red">edit</span> 9be2477a Change title tag for homepage
<span style="color: red">edit</span> c427697c Add images support in gallery</code></pre>
<p>Git will now walk you through each commit. You will have a chance to change every commit individually:</p>
<pre><code class="language-bash">Stopped at 1be09dcb... Merge branch with hotfix for DJ-1041
You can amend the commit now, with

    git commit --amend

Once you are satisfied with your changes, run

    git rebase --continue</code></pre>
<p>Now is your chance to rewrite the commit author identity. Either you will use <code>--amend</code> with <code>--author</code> flag. Or you will continue to next commit in edit mode until you have edited all commits which were marked for edit</p>
<pre><code class="language-bash">$ git commit --amend --author="FIRST_NAME LAST_NAME <EMAIL@example.com>" --no-edit
$ git rebase --continue</code></pre>
<h3 id="git_filter-branch">Git filter-branch</h3>
<p>Last option is to use Git <code>filter-branch</code> command. <code>filter-branch</code> will allow you to go through a large chunk of  commits with the help of simple script. Let us show you a simple script:</p>
<pre><code class="language-bash">$ git filter-branch --env-filter '
OLD_COMMITTER_EMAIL="OLD_EMAIL@example.com"
NEW_COMMITTER_NAME="FIRST_NAME LAST_NAME"
NEW_COMMITTER_EMAIL="NEW_EMAIL@example.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_COMMITTER_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$NEW_COMMITTER_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_COMMITTER_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_COMMITTER_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$NEW_COMMITTER_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_COMMITTER_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags</code></pre>
<p>However, same as with <strong>interactive rebase</strong>, it is necessary to be aware that by using <code>filter-branch</code>, you will create entirely new sort of commits and change Git commit history. The new commit history might have severe consequences when synchronizing with your team, so you should do this preferably only on repositories that haven&#8217;t been published or shared.</p>
<h2 id="conclusion">Conclusion</h2>
<p>In summary, we divided the methods of changing the commit author identity into two different approaches based on the commit stage. We showed three different ways to change the author information before making a commit, and we explained another three ways to change the author information after making a commit.</p>
<p>Did you find commands easy? Do you have your trick or know another way <u>how to change global and local Git settings</u>? Let us know in the comments below the article. We would like to hear your ideas and stories.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-set-custom-configuration-for-your-local-git-project-repository/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to remotely debug Java application in IntelliJ</title>
		<link>https://codepills.com/how-to-remotely-debug-java-application-in-intellij/</link>
					<comments>https://codepills.com/how-to-remotely-debug-java-application-in-intellij/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Mon, 01 Feb 2021 20:52:52 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[bytecode]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IntelliJ Idea]]></category>
		<category><![CDATA[JAR]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[maven build]]></category>
		<category><![CDATA[monolith]]></category>
		<category><![CDATA[port exhaustion]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[session exhaustion]]></category>
		<category><![CDATA[Slack]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[war]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1122</guid>

					<description><![CDATA[This article is a simple tutorial on how to debug your JAR or WAR file remotely. <a href="https://codepills.com/how-to-remotely-debug-java-application-in-intellij/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This tutorial will show you how to debug your JAR or WAR file in IntelliJ IDEA remotely and give hints on developing new features through the application stack.</p>
<p><span id="more-1122"></span></p>
<h2>Prerequisites</h2>
<p>Let me give you some essential tips for prerequisites to get successful and smooth remote debugging.</p>
<h3>Debug same version as on the remote server</h3>
<p>To debug a remote server-side application in your IntelliJ IDEA, you need to have the same version of your application or component on your side in IntelliJ IDEA as on the server-side. To do so, you shall first finish all the changes you want to test on the remote server. Then build your application and deploy it to the remote server. Only then you should run remote debug mode against your remote environment.</p>
<p>In reverse, if you can not change what is on the server, rebase your code repository on the commit of the JAR or WAR file set on the server. Then, build the application with the build tool of your choice (Maven/Gradle), and only then can you remotely debug.</p>
<h3>Don&#8217;t make any additional changes before remote debug</h3>
<p>Writing the following note might be unnecessary, yet it is better to say it aloud as a reminder. If you make any changes in your code between deployment on the remote server and running the application in remote debug mode, remote debug will not work. Even on the slightest change, remote debug will not decompile your breakpoint on the desired code line because Java bytecode will be different.</p>
<h3>Build faster without tests</h3>
<p>Just a tip &#8211; for a fast Maven build you can use <code>mvn clean install -DskipTests</code>.</p>
<p>For more information regarding running a Maven build without tests, check the article about <a href="https://codepills.com/how-to-build-with-maven-without-running-tests/" title="How to build with Maven without running tests" target="_blank" rel="noopener">how to build Java application with Maven without running tests</a>.</p>
<h3>Coordination your work with the rest of the team</h3>
<p>If you are working in a team and want to be a good team player (or working on something very sensitive), let your teammates know you want to deploy and remotely debug your application. First, ask your colleagues, e.g. in Slack publicly, if it is OK to occupy test instance for a while. Then, coordinate your debugging according to the response or your organization&#8217;s policy. For example, let&#8217;s say you are clear to go if nobody responds in 15 minutes.</p>
<h3>Adjustment of other parts</h3>
<p>For more complex changes through the stack, changing and adjusting different system parts might be necessary. E.g., if you are working on the monolith, you might need to adjust the front-end client for testing purposes. In other cases, it might be necessary to change the database.</p>
<p>Adjusting other parts of the system might be necessary for the system to work and for you to be able to test changes through the whole stack.</p>
<p>In every case, do not forget to clean after yourself when leaving (check the last point of this tutorial for more info).</p>
<h2>1. In IntelliJ IDEA, create new Run/Debug Configuration for Remote JVM Debug</h2>
<p><img loading="lazy" decoding="async" src="https://codepills.com/wp-content/uploads/2021/02/remote_debug_in_intellij_idea.png" alt="Remote Debug in IntelliJ IDEA" width="752" height="745" class="size-full wp-image-1123" /><br />
<i style="text-align: center;">Example of setup in IntelliJ IDEA</i></p>
<p>You can change host and port configurations based on the remote environment you want to debug.</p>
<p>If using a multi-module project, select a module in <code>Use module classpath</code>.</p>
<h2>2. Run remote debug configuration in debug mode</h2>
<p>Connecting to the host should be nearly instant. So now, all you need to do is place the <strong>breakpoints</strong> in your code.</p>
<p>Then, when the application code executes in a connected environment, the line you set as the breakpoint should be reached, and IntelliJ IDEA will show you the stack trace. That is it, simple as that.</p>
<h2>3. Do not forget to close your debug session</h2>
<p>Do not forget to close your debug session. Unclosed sessions cause port/socket exhaustion and lead to server restart. Also, try not to keep the session open and be stuck on the breakpoint for too long. <i>TimeOutException</i> and other exceptions might occur which will lead to further server resource consumption.</p>
<h2>4. Clean up</h2>
<p>After successful testing, returning the testing environment to its original state might be necessary. For example, build your current master/develop branch and place it back in the test environment. Then, if your colleagues do not notice that the testing environment does not work as it should, you did a good job cleaning after yourself and placing the project back in a stable state.</p>
<p>If you are on your own, I highly recommend cleaning after yourself too. You will never know when you will need to return to your projects again, and you might not remember why the testing environment is in a different state at that time.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-remotely-debug-java-application-in-intellij/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to use IntelliJ Idea as a text editor</title>
		<link>https://codepills.com/how-to-use-intellij-idea-as-a-text-editor/</link>
					<comments>https://codepills.com/how-to-use-intellij-idea-as-a-text-editor/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Fri, 01 Jan 2021 15:25:33 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Grammarly]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IntelliJ Idea]]></category>
		<category><![CDATA[IntelliJ Idea IDE]]></category>
		<category><![CDATA[Microsoft Word]]></category>
		<category><![CDATA[text editor]]></category>
		<category><![CDATA[word processor]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1104</guid>

					<description><![CDATA[This article will give you a few excellent tips on how and why to turn your favourite IDE into your first choice text editor. <a href="https://codepills.com/how-to-use-intellij-idea-as-a-text-editor/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>I have recently started to use IntelliJ Idea as my text editor and integrated it into my creative process.</p>
<p><span id="more-1104"></span></p>
<p>As I am a software developer, IntelliJ IDE is, for me, a must. IDE is in front of me opened all the time. Therefore it is a chance for me to write a lot of content in the IDE.  It is a better choice to use IDE instead of switching to another text editor or using another means of word processing.</p>
<p>Since I am also aiming to work on several articles or documents simultaneously, every decrease in ambiguity and complexity counts towards faster results. The creative process is not possible to automatize. But what it is possible to automatize are redundant tasks during text handling and editing.</p>
<h2>Why turn IntelliJ Idea IDE into your word processor?</h2>
<p>First of all, IntelliJ Idea IDE already comes in its 2020 version with very, very good support for English vocabulary. So writing in English in IDE was never easier than now.</p>
<p>Plus, when implementing the advantage of multiple IntelliJ shortcuts, the word processing is swift. Especially if you write your text in .html, .adoc or .md format.</p>
<p>Overall, IntelliJ IDE comes in all versions with Git support, which is an additional advantage against traditional word processors. You can easily version your articles&#8217; state and keep a history of your edits in one place. Article versioning is a feature that is available only in very advanced mode in cloud SaaS.</p>
<p>However, what I have found very tedious was text formatting in IntelliJ. As expected, I was using IntelliJ Idea IDE for coding, mostly Java, and thus the text was supposed to be wrapped automatically after 120 characters. When I then copied my articles to other word processors in my pipelines, such as Microsoft Word or Grammarly, I always needed painfully deleted every single break line to make a single continuous line of text. That was also one of the most common mistakes I had after publishing articles through WordPress  &#8211; linebreaks were always in places where they should not be.</p>
<p>After enough time spent doing this pointless work, fixing many wrong break lines, I have decided to end it and figure out how to speed up the process. Because every second I spend editing an article is second, I could use it towards another article&#8217;s creative process.</p>
<h2>How to turn IntelliJ Idea into text editor?</h2>
<p>First of all, go to <i>Settings</i> > <i>Editor</i> > <i>General</i> and check all checkboxes in Soft Wraps section.</p>
<p><img loading="lazy" decoding="async" src="https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_checkboxes_in_general_editor_settings.png" alt="IntelliJ soft-wrap checkboxes_in_general editor settings" width="692" height="361" class="size-full wp-image-1106" srcset="https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_checkboxes_in_general_editor_settings.png 692w, https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_checkboxes_in_general_editor_settings-300x157.png 300w" sizes="(max-width: 692px) 100vw, 692px" /></p>
<p>Then go to <i>Settings</i> > <i>Code Style</i> and select Scheme Project. Here unselect the checkbox &#8220;Wrap on typing&#8221;.</p>
<p><img loading="lazy" decoding="async" src="https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_editor_code_style.png" alt="IntelliJ soft-wrap editor code style" width="807" height="422" class="size-full wp-image-1105" srcset="https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_editor_code_style.png 807w, https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_editor_code_style-300x157.png 300w, https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_editor_code_style-768x402.png 768w" sizes="(max-width: 807px) 100vw, 807px" /></p>
<p>I would recommend this change be saved under the current project scheme, not under the IDE scheme. If you are using the same IntelliJ for coding, wrapping will conflict with your code clarity if you save the change under the IDE scheme.</p>
<p>Hit Apply button to apply all the changes.</p>
<h3>Initialize soft-wrap in IntelliJ code editor</h3>
<p>In the active editor tab, on the left side of the text line panel, after the right-click, there is an option <code>soft-wrap</code> to initiate the wrapping. Soft-wrap is not initialized automatically on every new file open. Therefore you will need to initialize soft-wrap on every new file open.</p>
<h3>Tip for shortcut</h3>
<p>When you open a new file, the text is, by default, unwrapped. You can either right-click on the newly opened line meter on the left side and hit <code>Soft-Wrap</code> from the menu option. Or you can set up a special shortcut for soft-wrapping, while the shortcut is not set by default.</p>
<p><img loading="lazy" decoding="async" src="https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_custom_shortcut.png" alt="IntelliJ soft-wrap - custom shortcut" width="645" height="395" class="size-full wp-image-1107" srcset="https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_custom_shortcut.png 645w, https://codepills.com/wp-content/uploads/2021/01/intellij_soft-wrap_custom_shortcut-300x184.png 300w" sizes="(max-width: 645px) 100vw, 645px" /></p>
<p>To set up your shortcut, go to <i>File</i> > <i>Settings</i> > <i>Keymap</i> and search for &#8220;Soft-Wrap&#8221; in <i>Main Menu</i> > <i>View</i> > <i>Active Editor</i>. Add to action key shortcut. I personally use Alt + P key shortcut. That is not a conflicting key shortcut with keys combinations easy to remember.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-use-intellij-idea-as-a-text-editor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to build with Maven without running tests</title>
		<link>https://codepills.com/how-to-build-with-maven-without-running-tests/</link>
					<comments>https://codepills.com/how-to-build-with-maven-without-running-tests/#comments</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Thu, 03 Dec 2020 14:44:49 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[JAR]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[POM]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[SpringBoot]]></category>
		<category><![CDATA[Surefire]]></category>
		<category><![CDATA[tests]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1084</guid>

					<description><![CDATA[This article will show you multiple ways how to skip the test in your Maven build <a href="https://codepills.com/how-to-build-with-maven-without-running-tests/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Do you try to build your app after the slightest change in code, and it takes ages to pass all the tests? What if there would be a workaround to obey all unnecessary tests and significantly shorten the Maven build time. And all that just but simple maven flag.</p>
<p><span id="more-1084"></span></p>
<p>Whether you want to build your SpringBoot app into the executable JAR file or build classes for a package, remember to use the single Maven flag parameter <code>mvn install -DskipTests</code>, and in the most cases, you will be fine.</p>
<p>However, the rabbit might run deeper, so it will be better to write a bit more info.</p>
<p><code>-DskipTests</code> option only works from Surefire 2.4. Unfortunately, there are no error messages if you do try to use it with Surefire 2.3 or lower. Therefore, your first task is to check your version of Surefire. For this, run <code>mvn -X test</code> and look for a line that mentions surefire. It should look like this: <code>maven-surefire-plugin: resolved to version 2.3 from repository central</code>. If you use pre-Surefire-2.4 start using <code>-Dmaven.test.skip=true</code>.</p>
<p>Fortunately beyond 2020 older version usage shrinks and you should remember to always favor a <code>-DskipTests </code> above <code>-Dmaven.test.skip=true</code>.</p>
<p>Surefire itself is the intermediate plugin between Maven and JUnit/TestNG for which while <code>-DskipTests </code> works and <code>-Dmaven.test.skip=true</code> works for compiler.</p>
<p>You can find (not really much more) additional info about shortening the build time trough skipping the project tests at <a href="https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html" target="_blank" rel="nofollow noopener">maven skipping tests</a> site.</p>
<p>You can add this plugin configuration to your pom if you do not want to set command line arguments:</p>
<pre><code class="language-xml">&lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
        &lt;skipTests&gt;true&lt;/skipTests&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;</code></pre>
<p>Or you can also set skipping tests in you POM file over property:</p>
<pre><code class="language-xml">&lt;properties&gt;
    &lt;maven.test.skip&gt;true&lt;/maven.test.skip&gt;
&lt;/properties&gt;</code></pre>
<p><b>Bonus</b></p>
<p>You can also skip tests in IntelliJ Idea. Just go to Maven tool tab and hit <b>&#8216;Skip Test&#8217;</b> mode.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-1085 aligncenter" src="https://codepills.com/wp-content/uploads/2020/12/skip_test_maven_in_intellij_idea.png" alt="Skip test Maven in IntelliJ Idea" width="369" height="109" srcset="https://codepills.com/wp-content/uploads/2020/12/skip_test_maven_in_intellij_idea.png 369w, https://codepills.com/wp-content/uploads/2020/12/skip_test_maven_in_intellij_idea-300x89.png 300w" sizes="(max-width: 369px) 100vw, 369px" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-build-with-maven-without-running-tests/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>How to convert int to long in Java?</title>
		<link>https://codepills.com/how-to-convert-int-to-long-in-java/</link>
					<comments>https://codepills.com/how-to-convert-int-to-long-in-java/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Tue, 11 Feb 2020 14:38:44 +0000</pubDate>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[effectiveness]]></category>
		<category><![CDATA[primitive data types]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1054</guid>

					<description><![CDATA[This article is a simple hint on the question of converting int to long or Long in Java. <a href="https://codepills.com/how-to-convert-int-to-long-in-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article is a simple hint on the often asked question of converting int to long or Long in Java.</p>
<p><span id="more-1054"></span></p>
<h2>How to convert int to long in Java?</h2>
<p>When we want to convert primitive <code>int</code> datatype to primitive <code>long</code> data type, all we need to do is just assign primitive <code>int</code> to primitive <code>long</code> variable. Nothing else is necessary. Converting primitive data type from higher to lower data type is implicit.</p>
<p>Let&#8217;s look on the example how to convert int to long in Java:</p>
<pre><code class="language-java">public class Main {
    public static void main(String args[]) {
        int primitiveInt = 1000;
        long primitiveLong = primitiveInt;
        System.out.println(primitiveLong);
    }
}</code></pre>
<p><b>Output</b></p>
<pre><code class="language-bash">1000</code></pre>
<h2>How to convert int to Long in Java?</h2>
<p>When we want to convert primitive <code>int</code> datatype to a Long object, there are two different ways to do it.</p>
<p>We can:</p>
<ul>
<li>instantiate new Long class over int constructor.</li>
<li>use a static method to extract primitive int and create a new Long object (calling Long.valueOf() method).</li>
</ul>
<p>Let&#8217;s look on the example how to convert int to long in Java:</p>
<pre><code class="language-java">public class Main {
    public static void main(String args[]) {
        int primitiveInt = 1000;

        // Option #1 - constructor initiation
        final Long objectLong = new Long(primitiveInt);
        // Option #2 - use static method
        final Long objectLongOther = Long.valueOf(primitiveInt);

        System.out.println(objectLong);
        System.out.println(objectLongOther);
    }
}</code></pre>
<p><b>Output</b></p>
<pre><code class="language-bash">1000
1000</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-convert-int-to-long-in-java/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
