Java Basics
Java program to write into a text file
Writing to a file in Java is known as writing content from a java variable value or object to a text or binary file using stream classes like FileWrite, FileOutputStream, PrintWriter, NIO and so on. The FileWriter class is used to write in a text file using java. BufferWriter is
Java Bean Standard, Specification, Properties, Requirements
A Java Bean is a java class that should follow the java bean standards and requirements. If a java class meets the java bean specification, the java class is called as java bean. The java bean has some properties and characteristics. A JavaBean is a java class which should follow
String index out of range
In Java, “String index out of range” exception is thrown in java substring() & charAt() method. Here, we see the exception “java.lang.StringIndexOutOfBoundsException: String index out of range: 0“. If a invalid value is passed in begin and end index value, “java.lang.StringIndexOutOfBoundsException: String index out of range” will be thrown. The
java.lang.StringIndexOutOfBoundsException: String index out of range
The java.lang.StringIndexOutOfBoundsException: String index out of range arises when the string index is either negative, or larger than the length of the string, i.e. out of range The java string index range should be in between 0 and the size of the string. The java String.charAt() method returns the character
java.io.UnsupportedEncodingException example
The java.io.UnsupportedEncodingException occurs when an unsupported character encoding scheme is used in java strings or bytes. The java String getBytes method converts the requested string to bytes in the specified encoding format. If the java does not support the encoding format, the method String getBytes throws java.io.UnsupportedEncodingException with the encoding
How to resolve java.util.regex.PatternSyntaxException at String.matches, String.split, String.replaceAll
The java.util.regex.PatternSyntaxException is thrown when the regular expression – regex pattern is not correct. The java String matches method checks the given string with the specified regular expression. If the java string matches the regular expression, it will return true, otherwise it will return false. The java exception java.util.regex.PatternSyntaxException is
java.util.regex.PatternSyntaxException: Dangling meta character ‘*’ near index 0
The java exception java.util.regex.PatternSyntaxException: Dangling meta character ‘*’ near index 0 happens when the string is matched by the regular expression meta character such as “*”, “+”, “?”. In a search string, the regular expression meta characters (“*”, “+”, “?”) must escape. The regular expression contains meta characters such as
java.util.regex.PatternSyntaxException: Unclosed character class near index 0
The java exception java.util.regex.PatternSyntaxException: Unclosed character class near index 0 happens when the string is matched by the regular expression special character ‘[’ open square bracket. In a search string, the special character (open square bracket) must escape. The regular expression uses the “[ ]” square bracket to match one
java.util.regex.PatternSyntaxException: Unclosed group near index 1
The regular expression uses the “( )” round bracket to identify the matching groups in a string. The matched character in the round bracket identified as a match group in a string. The exception “java.util.regex.PatternSyntaxException: Unclosed group near index” will be thrown if the open round bracket is available without
java.util.regex.PatternSyntaxException: Unmatched closing ‘)’
The java exception java.util.regex.PatternSyntaxException: Unmatched closing ‘)’ happens when the string is matched by the regular expression special character ‘)’ closing parentheses. In a search string, the character “(” and “)” and “{” and “}” are special characters in regular expression. these dialect characters have to be escaped. You need to escape ‘(‘ and ‘)’ with ‘\\(‘ and ‘\\)’ The