Author: saqibkhan

  • Locale Class

    A Locale class object represents a specific geographical/political/cultural region. Any operation requiring a Locale to perform its task is called locale-sensitive operation and uses the Locale to master information relative to the user. For example, displaying a number is a locale-sensitive operation. The number should be formatted as per the customs and conventions of the user’s native country, region, or culture.

    Locale Contents

    A Locale object contains the following −

    Language

    ISO 639 alpha-2 or alpha-3 language code, or registered language subtags up to 8 alpha letters. alpha-2 code must be used if both alpha-2 and alpha-3 code are present. The language field is case insensitive, but Locale always canonicalizes to lower case.

    Script

    ISO 15924 alpha-4 script code. The script field is case insensitive, but Locale always canonicalizes to title case.

    Country (Region)

    ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code. The country field is case insensitive, but Locale always canonicalizes to upper case.

    Variant

    Any arbitrary value used to indicate a variation of a Locale. Where there are two or more variant values each indicating its own semantics, these values should be ordered by importance, with most important first, separated by underscore(‘_’). The variant field is case sensitive.

    Extensions

    A map from single character keys to string values, indicating extensions apart from language identification. The extensions in Locale implement the semantics and syntax of BCP 47 extension subtags and private use subtags. The extensions are case insensitive, but Locale canonicalizes all extension keys and values to lower case.

  • Environment Setup

    Local Environment Setup

    If you are still willing to set up your environment for Java programming language, then this section guides you on how to download and set up Java on your machine. Following are the steps to set up the environment.

    Java SE is freely available from the link Download Java. You can download a version based on your operating system.

    Follow the instructions to download Java and run the .exe to install Java on your machine. Once you installed Java on your machine, you will need to set environment variables to point to correct installation directories −

    Setting Up the Path for Windows

    Assuming you have installed Java in c:\Program Files\java\jdk directory −

    • Right-click on ‘My Computer’ and select ‘Properties’.
    • Click the ‘Environment variables’ button under the ‘Advanced’ tab.
    • Now, alter the ‘Path’ variable so that it also contains the path to the Java executable. Example, if the path is currently set to ‘C:\WINDOWS\SYSTEM32’, then change your path to read ‘C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin’.

    Setting Up the Path for Linux, UNIX, Solaris, FreeBSD

    Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation, if you have trouble doing this.

    Example, if you use bash as your shell, then you would add the following line to the end of your ‘.bashrc: export PATH = /path/to/java:$PATH’

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Popular Java Editors

    To write your Java programs, you will need a text editor. There are even more sophisticated IDEs available in the market. But for now, you can consider one of the following −

    • Notepad − On Windows machine, you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad.
    • Netbeans − A Java IDE that is open-source and free which can be downloaded from https://www.netbeans.org/index.html.
    • Eclipse − A Java IDE developed by the eclipse open-source community and can be downloaded from https://www.eclipse.org/.
  • Overview

    Internationalization

    Internationalization or I18N refers to the capability of an Application to be able to serve users in multiple and different languages. Java has in-built support for Internationalization. Java also provides formatting of numbers, currencies and adjustment of date and time accordingly.

    Java Internationalization helps to make a java application handle different languages, number formats, currencies, region specific time formatting.

    Localization

    Localization or L10N is the adaptability of an application that is how an application adapts itself with a specific language, number formats, date and time settings etc.

    A java application should be internationalized in order to be able to localize itself.

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Culturally Dependent Information

    Following information items often varies with different time zones or cultures.

    • Messages
    • Date
    • Time
    • Number
    • Currency
    • Measurements
    • Phone Numbers
    • Postal Addresses
    • GUI labels

    Internationalization Classes

    Java has a set of built-in classes which help in internationalization of an application. These classes are following −

    Sr.No.Class & Description
    1LocaleRepresents a language along with country/region.
    2ResourceBundleContains localized text or objects.
    3NumberFormatUse to format numbers/currencies as per the locale.
    4DecimalFormatUse to format numbers as per customized format and as per locale.
    5DateFormatUse to format dates as per locale.
    6SimpleDateFormatUse to format dates as per customized format and as per locale.
  • Writer 

    Introduction

    The Java.io.Writer class is a abstract class for writing to character streams.

    Class declaration

    Following is the declaration for Java.io.Writer class −

    public abstract class Writer
       extends Object
    
      implements Appendable, Closeable, Flushable

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.Writer class −

    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1protected Writer()This creates a new character-stream writer whose critical sections will synchronize on the writer itself.
    2protected Writer(Object lock)This creates a new character-stream writer whose critical sections will synchronize on the given object.

    Class methods

    Sr.No.Method & Description
    1Writer append(char c)This method appends the specified character to this writer.
    2Writer append(CharSequence csq)This method appends the specified character sequence to this writer.
    3Writer append(CharSequence csq, int start, int end)This method appends a subsequence of the specified character sequence to this writer.
    4abstract void close()This method loses the stream, flushing it first.
    5abstract void flush()This method flushes the stream.
    6void write(char[] cbuf)This method writes an array of characters.
    7abstract void write(char[] cbuf, int off, int len)This method writes a portion of an array of characters.
    8void write(int c)This method writes a single character.
    9void write(String str)This method writes a string.
    10void write(String str, int off, int len)This method writes a portion of a string.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • StringWriter

    Introduction

    The Java.io.StringWriter class is a character stream that collects its output in a string buffer, which can then be used to construct a string.Closing a StringWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

    Class declaration

    Following is the declaration for Java.io.StringWriter class −

    public class StringWriter
      extends Writer
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.StringWriter class −

    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1StringWriter()This creates a new string writer using the default initial string-buffer size.
    2StringWriter(int initialSize)This creates a new string writer using the specified initial string-buffer size.

    Class methods

    Sr.No.Method & Description
    1StringWriter append(char c)This method appends the specified character to this writer.
    2StringWriter append(CharSequence csq)This method appends the specified character sequence to this writer.
    3StringWriter append(CharSequence csq, int start, int end)This method appends a subsequence of the specified character sequence to this writer.
    4void close()Closing a StringWriter has no effect.
    5void flush()This method flush the stream.
    6StringBuffer getBuffer()This method return the string buffer itself.
    7String toString()This method return the buffer’s current value as a string.
    8void write(char[] cbuf, int off, int len)This method write a portion of an array of characters.
    9void write(int c)This method write a single character.
    10void write(String str)This method writes a string.
    11void write(String str, int off, int len)This method writes a portion of a string.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Writer
    • Java.io.Object
  • StringReader

    Introduction

    The Java.io.StringReader class is a character stream whose source is a string.

    Class declaration

    Following is the declaration for Java.io.StringReader class −

    public class StringReader
       extends Reader
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.StringReader class −

    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1StringReader(String s)This creates a new string reader.

    Class methods

    Sr.No.Method & Description
    1void close()This method closes the stream and releases any system resources associated with it.
    2void mark(int readAheadLimit)This method marks the present position in the stream.
    3boolean markSupported()This method tells whether this stream supports the mark() operation, which it does.
    4int read()This method reads a single character.
    5int read(char[] cbuf, int off, int len)This method reads characters into a portion of an array.
    6boolean ready()This method tells whether this stream is ready to be read.
    7void reset()This method resets the stream to the most recent mark, or to the beginning of the string if it has never been marked.
    8long skip(long ns)This method skips the specified number of characters in the stream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Reader
    • Java.io.Object
  • StringBufferInputStream 

    Introduction

    The Java.io.StringBufferInputStream class allows an application to create an input stream in which the bytes read are supplied by the contents of a string. Applications can also read bytes from a byte array by using a ByteArrayInputStream.Only the low eight bits of each character in the string are used by this class.

    This class has been deprecated by Oracle and should not be used any more.

    Class declaration

    Following is the declaration for Java.io.StringBufferInputStream class −

    public class StringBufferInputStream
       extends InputStream
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.StringBufferInputStream class −

    • protected String buffer − This is the string from which bytes are read.
    • protected int count − This is the number of valid characters in the input stream buffer.
    • protected int pos − This is the index of the next character to read from the input stream buffer.

    Class constructors

    Sr.No.Constructor & Description
    1StringBufferInputStream(String s)This creates a string input stream to read data from the specified string.

    Class methods

    Sr.No.Method & Description
    1int available()This method returns the number of bytes that can be read from the input stream without blocking.
    2int read()This method reads the next byte of data from this input stream.
    3int read(byte[] b, int off, int len)This method reads up to len bytes of data from this input stream into an array of bytes.
    4void reset()This method resets the input stream to begin reading from the first character of this input stream’s underlying buffer.
    5long skip(long n)This method skips n bytes of input from this input stream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.InputStreams
    • Java.io.Object
  • StreamTokenizer 

    Introduction

    The Java.io.StreamTokenizer class takes an input stream and parses it into “tokens”, allowing the tokens to be read one at a time. The stream tokenizer can recognize identifiers, numbers, quoted strings, and various comment styles.

    Class declaration

    Following is the declaration for Java.io.StreamTokenizer class −

    public class StreamTokenizer
       extends Object
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.StreamTokenizer class −

    • double nval − If the current token is a number, this field contains the value of that number.
    • String sval − If the current token is a word token, this field contains a string giving the characters of the word token.
    • static int TT_EOF − A constant indicating that the end of the stream has been read.
    • static int TT_EOL − A constant indicating that the end of the line has been read.
    • static int TT_NUMBER − A constant indicating that a number token has been read.
    • static int TT_WORD − A constant indicating that a word token has been read.
    • int ttype − After a call to the nextToken method, this field contains the type of the token just read.

    Class constructors

    Sr.No.Constructor & Description
    1StreamTokenizer(Reader r)This creates a tokenizer that parses the given character stream.

    Class methods

    Sr.No.Method & Description
    1void commentChar(int ch)Specified that the character argument starts a single-line comment.
    2void eolIsSignificant(boolean flag)This method determines whether or not ends of line are treated as tokens.
    3int lineno()This method returns the current line number.
    4void lowerCaseMode(boolean fl)This method determines whether or not word token are automatically lowercased.
    5int nextToken()This method parses the next token from the input stream of this tokenizer.
    6void ordinaryChar(int ch)This method specifies that the character argument is “ordinary” in this tokenizer.
    7void ordinaryChars(int low, int hi)This method specifies that all characters c in the range low <= c <= high are “ordinary” in this tokenizer.
    8void parseNumbers()This method specifies that numbers should be parsed by this tokenizer.
    9void pushBack()This method causes the next call to the nextToken method of this tokenizer to return the current value in the ttype field, and not to modify the value in the nval or sval field.
    10void quoteChar(int ch)This method specifies that matching pairs of this character delimit string constants in this tokenizer.
    11void resetSyntax()This method resets this tokenizer’s syntax table so that all characters are “ordinary.” See the ordinaryChar method for more information on a character being ordinary.
    12void slashSlashComments(boolean flag)This method determines whether or not the tokenizer recognizes C++ style comments.
    13void slashStarComments(boolean flag)This method determines whether or not the tokenizer recognizes C style comments.
    14String toString()This method returns the string representation of the current stream token and the line number it occurs on.
    15void whitespaceChars(int low, int hi)This method specifies that all characters c in the range low <= c <= high are white space characters.
    16void wordChars(int low, int hi)This method specifies that all characters c in the range low <= c >= high are word constituents.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • SerializablePermission 

    Introduction

    The Java.io.SerializablePermission class is for Serializable permissions. A SerializablePermission contains a name (also referred to as a “target name”) but no actions list; you either have the named permission or you don’t.The target name is the name of the Serializable permission.

    Class declaration

    Following is the declaration for Java.io.SerializablePermission class −

    public final class SerializablePermission
       extends BasicPermission
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1SerializablePermission(String name)This creates a new SerializablePermission with the specified name.
    2SerializablePermission(String name, String actions)This creates a new SerializablePermission object with the specified name.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.BasicPermission
    • Java.io.Permission
    • Java.io.Object
  • SequenceInputStream 

    Introduction

    The Java.io.SequenceInputStream class represents the logical concatenation of other input streams. It starts out with an ordered collection of input streams and reads from the first one until end of file is reached, whereupon it reads from the second one, and so on, until end of file is reached on the last of the contained input streams.

    Class declaration

    Following is the declaration for Java.io.SequenceInputStream class −

    public class SequenceInputStream
       extends InputStream
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1SequenceInputStream(Enumeration<? extends InputStream> e)This initializes a newly created SequenceInputStream by remembering the argument, which must be an Enumeration that produces objects whose run-time type is InputStream.
    2SequenceInputStream(InputStream s1, InputStream s2)This initializes a newly created SequenceInputStream by remembering the two arguments, which will be read in order, first s1 and then s2, to provide the bytes to be read from this SequenceInputStream.

    Class methods

    Sr.No.Method & Description
    1int available()This method returns an estimate of the number of bytes that can be read (or skipped over) from the current underlying input stream without blocking by the next invocation of a method for the current underlying input stream.
    2void close()This method closes this input stream and releases any system resources associated with the stream.
    3int read()This method reads the next byte of data from this input stream.
    4int read(byte[] b, int off, int len)This method reads up to len bytes of data from this input stream into an array of bytes.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.InputStream
    • Java.io.Object