HowToDoInJava https://howtodoinjava.com Sat, 18 Aug 2018 18:53:06 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 https://howtodoinjava.com/wp-content/uploads/2015/05/howtodoinjava_logo-55696c1cv1_site_icon-32x32.png HowToDoInJava https://howtodoinjava.com 32 32 Reverse string in Java using recursion https://howtodoinjava.com/java/string/reverse-string-using-recursion/ https://howtodoinjava.com/java/string/reverse-string-using-recursion/#respond Fri, 17 Aug 2018 12:52:50 +0000 https://howtodoinjava.com/?p=11197 In this post, we will see a Java program to reverse a string using recursion. Also learn to reverse string without recursion as well. Read More: Reverse words in a string in Java 1. Reverse a sentence in Java using recursion To reverse a string by characters, we can write a recursive function which will […]

The post Reverse string in Java using recursion appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/java/string/reverse-string-using-recursion/feed/ 0
Reverse words in a string in Java https://howtodoinjava.com/java/string/reverse-words-in-string/ https://howtodoinjava.com/java/string/reverse-words-in-string/#respond Fri, 17 Aug 2018 11:35:24 +0000 https://howtodoinjava.com/?p=11195 Learn to reverse each word in a sentence in Java with example. We will reverse the words in string using StringBuilder and StringUtils classes. Original String – how to do in java Reverse words – woh ot od ni avaj 1. Java program to reverse each word in a sentence 1.1. Using StringBuilder class Tokenize […]

The post Reverse words in a string in Java appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/java/string/reverse-words-in-string/feed/ 0
Java array contains – arraylist contains example https://howtodoinjava.com/array/array-arraylist-contains-example/ https://howtodoinjava.com/array/array-arraylist-contains-example/#respond Fri, 17 Aug 2018 09:11:59 +0000 https://howtodoinjava.com/?p=11190 Learn how to check if an arraylist contains a value in Java with example. Also, learn to check if array contains an element, along with index of element in array. 1. Java ArrayList Contains Example To check if an ArrayList contains an element, use ArrayList.contains(element) method. contains(element) method does not take null argument, and will […]

The post Java array contains – arraylist contains example appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/array/array-arraylist-contains-example/feed/ 0
Convert long to String in Java https://howtodoinjava.com/java/string/convert-long-to-string/ https://howtodoinjava.com/java/string/convert-long-to-string/#respond Thu, 16 Aug 2018 13:01:19 +0000 https://howtodoinjava.com/?p=11177 Java example to convert long to String in two different ways using String.valueOf(long l) and Long.toString(long l) methods. Both are static methods.

The post Convert long to String in Java appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/java/string/convert-long-to-string/feed/ 0
Convert String to Long in Java https://howtodoinjava.com/java/string/convert-string-to-long/ https://howtodoinjava.com/java/string/convert-string-to-long/#respond Thu, 16 Aug 2018 11:48:53 +0000 https://howtodoinjava.com/?p=11176 3 Java examples to convert String to long value using Long.parseLong(String), Long.valueOf(String) and new Long(String) constructor.

The post Convert String to Long in Java appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/java/string/convert-string-to-long/feed/ 0
Convert int to String in Java https://howtodoinjava.com/java/string/convert-int-to-string/ https://howtodoinjava.com/java/string/convert-int-to-string/#respond Thu, 16 Aug 2018 10:09:12 +0000 https://howtodoinjava.com/?p=11175 To convert int to String, use either String.valueOf() or Integer.toString() method. 1. String.valueOf() String.valueOf(int i) method returns the string representation of the int argument. The representation is exactly the one returned by the Integer.toString() method of one argument. 1.1. Syntax 1.2. int to String Example 2. Integer.toString() Integer.toString(int i) method Returns a string object representing […]

The post Convert int to String in Java appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/java/string/convert-int-to-string/feed/ 0
Java Wrapper Classes https://howtodoinjava.com/java/basics/java-wrapper-classes/ https://howtodoinjava.com/java/basics/java-wrapper-classes/#respond Tue, 14 Aug 2018 19:25:30 +0000 https://howtodoinjava.com/?p=11149 Learn about Java wrapper classes, their usage, conversion between primitive and object; and autoboxing and unboxing with examples. 1. Wrapper Classes Java provides type wrappers, which are classes that encapsulate a primitive type within an object. In Java, we have 8 primitive data types. A wrapper class wraps (encloses) around a data type and gives […]

The post Java Wrapper Classes appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/java/basics/java-wrapper-classes/feed/ 0
Convert String to Title Case in Java https://howtodoinjava.com/java/string/convert-string-to-titlecase/ https://howtodoinjava.com/java/string/convert-string-to-titlecase/#respond Tue, 07 Aug 2018 13:46:40 +0000 https://howtodoinjava.com/?p=11066 Java examples to convert a string to title case using Apache commons WordUtils class, String.split() method and Java 8 stream of character array. 1. Using WordUtils from Apache Commons Text Apache commons-text provides WordUtils to perform operations on String that contains words. 1.1. Maven dependency 1.2. WordUtils example to convert string to title case Program […]

The post Convert String to Title Case in Java appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/java/string/convert-string-to-titlecase/feed/ 0
Java group by sort with multiple comparators https://howtodoinjava.com/sort/groupby-sort-multiple-comparators/ https://howtodoinjava.com/sort/groupby-sort-multiple-comparators/#respond Tue, 07 Aug 2018 07:23:29 +0000 https://howtodoinjava.com/?p=11042 Java examples to do SQL-style group by sort on list of objects. It involves using multiple comparators, each of which is capable of sorting on different field in model object. Table of Contents 1. Model class and multiple comparators 2. Comparator.thenComparing() 3. CompareToBuilder 4. ComparisonChain 5. Chained comparators 1. Model class and multiple comparators Our […]

The post Java group by sort with multiple comparators appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/sort/groupby-sort-multiple-comparators/feed/ 0
Hibernate Validator CDI – @HibernateValidator Example https://howtodoinjava.com/hibernate/hibernate-validator-cdi/ https://howtodoinjava.com/hibernate/hibernate-validator-cdi/#respond Mon, 06 Aug 2018 07:23:51 +0000 https://howtodoinjava.com/?p=11028 Java example of hibernate validator CDI to inject default Java bean validation classes implementations e.g. javax.validation.ValidatorFactory and javax.validation.Validator with hibernate-validator-cdi dependency. Also learn to inject specialized validator if application has multiple validator implementations like org.hibernate.validator.cdi.HibernateValidator. Please note that if your application runs in an environment which provides this integration out of the box, then you […]

The post Hibernate Validator CDI – @HibernateValidator Example appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/hibernate/hibernate-validator-cdi/feed/ 0
[Solved] – UnexpectedTypeException- No validator could be found for constraint https://howtodoinjava.com/hibernate/unexpectedtypeexception-error/ https://howtodoinjava.com/hibernate/unexpectedtypeexception-error/#respond Fri, 03 Aug 2018 12:00:53 +0000 https://howtodoinjava.com/?p=11012 Learn to solve java exception UnexpectedTypeException while using hibernate validator for java bean validations. 1) Problem UnexpectedTypeException error you will get when you are trying to use incorrect hibernate validator annotation on any bean property. The error stack trace looks like this. For example above error is received you you try to put @NotBlank annotation […]

The post [Solved] – UnexpectedTypeException- No validator could be found for constraint appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/hibernate/unexpectedtypeexception-error/feed/ 0
Hibernate Validator – Java Bean Validation Example https://howtodoinjava.com/hibernate/hibernate-validator-java-bean-validation/ https://howtodoinjava.com/hibernate/hibernate-validator-java-bean-validation/#respond Fri, 03 Aug 2018 11:50:00 +0000 https://howtodoinjava.com/?p=11010 Java example to use hibernate validator to validate Java bean fields. Bean validation API 2 (JSR-380) offers some popular annotations that can be attached to each bean property for the purpose of maintaining data integrity. 1) Maven dependencies Below are required hibernate validator maven dependencies. Bean validation allows expressions inside the error messages. To parse […]

The post Hibernate Validator – Java Bean Validation Example appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/hibernate/hibernate-validator-java-bean-validation/feed/ 0
Spring Security 5 – Login Form Example https://howtodoinjava.com/spring5/security5/login-form-example/ https://howtodoinjava.com/spring5/security5/login-form-example/#respond Thu, 02 Aug 2018 10:13:53 +0000 https://howtodoinjava.com/?p=10999 Learn to add custom login form based security to your Spring WebMVC application. I am using Spring security 5 to build this example. This tutorial additionally discusses logout from the session. 1) Include spring security dependencies Include spring security jars. I am using maven so added respective dependencies for spring security version 5.0.7.RELEASE. 2) Create […]

The post Spring Security 5 – Login Form Example appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/spring5/security5/login-form-example/feed/ 0
Spring Security 5 Java Config – @EnableWebSecurity Example https://howtodoinjava.com/spring5/security5/security-java-config-enablewebsecurity-example/ https://howtodoinjava.com/spring5/security5/security-java-config-enablewebsecurity-example/#respond Wed, 01 Aug 2018 13:41:30 +0000 https://howtodoinjava.com/?p=10994 Java example to enable spring security java configuration with the help of @EnableWebSecurity annotation and WebSecurityConfigurerAdapter class. 1) Include spring security dependencies Include spring security jars. I am using maven so added respective dependencies for spring security 5. 2) Create Security Configuration I have created this simple security configuration and added two demo users ‘user‘ […]

The post Spring Security 5 Java Config – @EnableWebSecurity Example appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/spring5/security5/security-java-config-enablewebsecurity-example/feed/ 0
Java Evaluate XPath on DOM Document Object https://howtodoinjava.com/xml/evaluate-xpath-on-dom/ https://howtodoinjava.com/xml/evaluate-xpath-on-dom/#respond Tue, 31 Jul 2018 15:11:07 +0000 https://howtodoinjava.com/?p=10992 Java example to evaluate xpath of an DOM org.w3c.dom.Document object and get results in form of String or NodeList. Evaluate XPath on DOM Create Document DOM object javax.xml.parsers.DocumentBuilder object. Create XPath from XPathFactory. Use xpath.evaluate('expression', dom, resultType) to get result HTML. Program output: Where input xml file is: Happy Learning !!

The post Java Evaluate XPath on DOM Document Object appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/xml/evaluate-xpath-on-dom/feed/ 0
Java Evaluate XPath on a XML String https://howtodoinjava.com/xml/evaluate-xpath-on-xml-string/ https://howtodoinjava.com/xml/evaluate-xpath-on-xml-string/#respond Tue, 31 Jul 2018 14:39:58 +0000 https://howtodoinjava.com/?p=10989 Java example to evaluate xpath of an XML String and return result XML in string itself. Evaluate XPath on XML String Create org.xml.sax.InputSource containing with StringReader referencing to XML string. Create XPath from XPathFactory. Use xpath.evaluate('expression', inputSource) to get result HTML. Program output: Happy Learning !!

The post Java Evaluate XPath on a XML String appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/xml/evaluate-xpath-on-xml-string/feed/ 0
Java XPath – Check if XML tag or attribute exists? https://howtodoinjava.com/xml/xpath-check-if-xml-tag-exists/ https://howtodoinjava.com/xml/xpath-check-if-xml-tag-exists/#respond Tue, 31 Jul 2018 10:27:18 +0000 https://howtodoinjava.com/?p=10987 Java example to check if a tag exists in given XML content or if any attribute is present in XML using XPath. How to check if xml tag exists? To verify if node or tag exists in XML content, you can execute an xpath expression against DOM document for that XML and count the matching […]

The post Java XPath – Check if XML tag or attribute exists? appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/xml/xpath-check-if-xml-tag-exists/feed/ 0
Java XPath Expression Examples https://howtodoinjava.com/xml/java-xpath-expression-examples/ https://howtodoinjava.com/xml/java-xpath-expression-examples/#respond Mon, 30 Jul 2018 13:12:11 +0000 https://howtodoinjava.com/?p=10985 Java examples to extract information from an XML document by evaluate XPath expressions. We will learn to fetch information for matching attribute values, matching fields values, contains() expressions etc. 1) XPath Query Examples 1.1) Input XML file First look at the XML file which we will read and then fetch information from it, using xpath […]

The post Java XPath Expression Examples appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/xml/java-xpath-expression-examples/feed/ 0
Java XPath Attribute Evaluate Examples https://howtodoinjava.com/xml/xpath-attribute-evaluate/ https://howtodoinjava.com/xml/xpath-attribute-evaluate/#respond Mon, 30 Jul 2018 12:50:34 +0000 https://howtodoinjava.com/?p=10982 Java examples to extract information from an XML document using XPath evaluational. We will learn to fetch information for matching attribute values, attribute values in range, xpath attribute contains() and so on. 1) XPath Attribute Expression Examples 1.1) Input XML file First look at the XML file which we will read and then fetch information […]

The post Java XPath Attribute Evaluate Examples appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/xml/xpath-attribute-evaluate/feed/ 0
JAXB Unmarshal without @XmlRootElement https://howtodoinjava.com/jaxb/unmarshal-without-xmlrootelement/ https://howtodoinjava.com/jaxb/unmarshal-without-xmlrootelement/#respond Mon, 30 Jul 2018 07:34:45 +0000 https://howtodoinjava.com/?p=10979 Many times, you will need to unmarshal Java objects which does not have JAXB annotations and you are not permitted to make any changes in sourcecode. This situation may occur when you are working with legacy code or some client jar for which you do not have source code. 1) Problem In such case, if […]

The post JAXB Unmarshal without @XmlRootElement appeared first on HowToDoInJava.

]]>
https://howtodoinjava.com/jaxb/unmarshal-without-xmlrootelement/feed/ 0