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…

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…

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,…

Error: Could not find or load main class

Error: Could not find or load main class is a common error encountered in Java programming. This error occurs when the Java Virtual Machine (JVM) is unable to locate the…

Initialize an Arraylist in one line

In Java, you can initialize an array list in one line by using array literals and stream literals. Use the Arrays.asList(), List.of(), and Stream.of() APIs to create an array list in a single…

How to split a String in Java with Delimiter

Java String split using delimiter – In Java, the split() method splits a string with delimiter provided in a given regular expression and returns a string array. The split method divides…

Synchronization in Java with simple example

Synchronization is a process that does not allow more than one thread for a resource at any time. In the java multi-threaded environment, multiple threads attempt to access the same…

Continue Statement with example in Java

Continue statements in java is used to terminate the rest of the code in the loop and execute the next iteration. Java Continue statement is used for any type of…

Break Statement in Java

Break statements are used to terminate the loop immediately, based on the condition and continues to executes the following code to the loop.Break statements are used in the switch statements…

Ternary Operator Vs If Else

The java ternary operator or conditional operator is supported in languages such as java, javascript, python, c / c++, c# etc. The java ternary operator or conditional operator takes three…

Switch Case Java

The switch case in java matches the given value from multiple values and executes the corresponding switch statement. Java Switch contains multiple cases. In each switch case, there is a…

How to use Bitwise Operator in Java

Bitwise operators in Java manipulate individual bits of a number. Bitwise Operator in Java is used on integral types, byte, short, int and long. Java Bitwise Operators includes AND, OR,…