Binary Tree

Reading Time: 6 minutes Binary Tree Definition Binary tree is a non-linear data structure that is composed of two nodes at most. This is where its name comes from. However, it is not necessarily for a Binary Tree to have maximum two nodes. However, it can be even zero. Furthermore, there is also an implementation of Binary Tree called

Creating a Java keystore

Reading Time: 1 minute create a keystore file $JAVA_HOME/bin/keytool -genkey -alias tugrulaslan.net -keyalg RSA -keystore keystore.jks -keysize 2048 Generate a certificate signing request (CSR) for an existing Java keystore $JAVA_HOME/bin/keytool -certreq -alias tugrulaslan.net -keysto re keystore.jks -file tugrulaslan.net.csr Import a root or intermediate CA certificate to an existing Java keystore $JAVA_HOME/bin/keytool -import -trustcacerts -alias root -file intermediate.crt -keystore keystore.jks

Bubble Sort

Reading Time: 1 minute Description Bubble sort will repeatedly compare and swap adjacent items. If the item on the left is greater, it swaps it with the right item. Basically the greater items are shifted towards the right direction. Furthermore, the second iteration is stopped because the last items are sorted already we wont go though them again. Furthermore,

Java Object equals, hashCode, Hashing Collections and Hash Code Collision

Reading Time: 7 minutes Introduction In this blog post I’ll be focusing on something very fundamental and assumed as easy in the concept, but fairly the subject requires more focus and better apprehending. Besides that I am quite sure you’ll learn many interesting related to this topic. Object equals and hashCode Methods equals and hashCode methods are shipped with

Builder Pattern in Java

Reading Time: 6 minutes The Builder pattern eliminates building the complexity of the target object as well as eases the construction by providing such methods that will assemble the object same as building a set of blocks. By implementing the Builder pattern, there won’t be any need of larger constructors, parameter objects or custom types. Furthermore, the Builder pattern

Immutable Objects in Java

Reading Time: 3 minutes Immutability of an object indicates that once an object is constructed with given values, its state and values cannot be altered. In case of any value change must result in new object creation. Out of box Java offers some Immutable objects for instance java.lang.String, java.lang.Integer, java.lang.Float, java.math.BigDecimal. Immutable objects make generally a good use in

JSF Input text placeholder

Reading Time: 1 minute In the Tag description add the pt entry and its corresponding web address <html xmlns=”http://www.w3.org/1999/xhtml” xmlns:h=”http://java.sun.com/jsf/html” xmlns:pt=”http://xmlns.jcp.org/jsf/passthrough”> in the input text declaration <h:inputText styleClass=”form-control” pt:placeholder=”Enter Search Value” required=”true” requiredMessage=”Please enter search value” value=”#{orderController.keyword}” id=”keywordSearch”/>

Java XML Parser

Reading Time: 2 minutes Using Dom4J <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> XMLParser.java import org.apache.commons.lang.StringUtils; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.StringReader; import java.io.StringWriter; import java.io.StringWriter; public class XMLFormatter { private static Logger

JSF File Download

Reading Time: 1 minute <h:commandLink action=”#{logController.downloadMessage}”> <h:outputText styleClass=”fa fa-fw fa-download”/> <f:setPropertyActionListener value=”#{log}” target=”#{logController.selectedLog}”/> </h:commandLink> public void downloadMessage() throws IOException { logger.info(“downloading the log file”); File file = new File(searchKeyword + “_log.txt”); FileUtils.writeStringToFile(file, selectedLog.getMessageContent(), Charset.defaultCharset()); FacesContext facesContext = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.setHeader(“Content-Disposition”, “attachment;filename=” + file.getName()); response.setContentLength((int) file.length()); FileInputStream input = null; try { int i = 0;