Charset defaultCharset() method in Java with Examples Last Updated : 29 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The defaultCharset() method is a built-in method of the java.nio.charset which returns the charset object for the default charset. The default charset is basically determined by the Java virtual machine and it basically depends on the charset which is in the underlying operating system of the machine. In short, the result will vary from machine to machine. Syntax: public static Charset defaultCharset() Parameters: The function does not accepts any parameter. Return Value: The function returns a charset object for the default charset. Below is the implementation of the above function: Program 1: Java // Java program to demonstrate // the above function import java.nio.charset.Charset; import java.util.Iterator; import java.util.Map; public class GFG { public static void main(String[] args) { // Get the default charset of the machine Charset cs = Charset.defaultCharset(); System.out.println("The default charset of the machine is :" + cs.displayName()); } } Output: The default charset of the machine is :US-ASCII Reference: https://docs.oracle.com/javase/10/docs/api/java/nio/charset/Charset.html#defaultCharset() Comment More infoAdvertise with us Next Article Charset defaultCharset() method in Java with Examples G gopaldave Follow Improve Article Tags : Java Java-Functions Java-NIO package Java-Charset Practice Tags : Java Similar Reads Charset compareTo() method in Java with Examples The compareTo() method is a built-in method of the java.nio.charset compares two charsets with each other. A comparison is done by their canonical names, without regard to case. Syntax: public final int compareTo?(Charset second) Parameters: The function accepts a single mandatory parameter second w 1 min read CharsetEncoder charset() method in Java with Examples The charset() method is a built-in method of the java.nio.charset.CharsetEncoder returns the charset that created this encoder. Syntax: public final Charset charset() Parameters: The function does not accepts any parameter. Return Value: The function returns this encoder's charset. Below is the impl 1 min read CharsetDecoder detectedCharset() method in Java with Examples The detectedCharset() method is a built-in method of the java.nio.charset.CharsetDecoder class which retrieves the charset that has been detected by this decoder. The default implementation of this method always throws an UnsupportedOperationException. It should be overridden by auto-detecting decod 2 min read Charset canEncode() method in Java with Examples The canEncode() method is a built-in method of the java.nio.charset checks whether a particular charset supports encoding or not. Almost every charset can encode, except a few. Syntax: public boolean canEncode() Parameters: The function does not accepts any parameter. Return Value: The function retu 3 min read Charset availableCharsets() method in Java with Examples The availableCharsets() method is a built-in method of the java.nio.charset constructs a sorted map from the canonical charset names to charset objects. The map thus returned will have one entry for every charset. In case there are multiple entries by the same name, it only stores one of them which 2 min read Like