<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; StreamTokenizer</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/java-interview-questions/streamtokenizer/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 30 Jul 2010 06:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Explain Stream Tokenizer</title>
		<link>http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/</link>
		<comments>http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 08:27:33 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[StreamTokenizer]]></category>
		<category><![CDATA[define StreamTokenizer]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=499</guid>
		<description><![CDATA[Stream Tokenizer : StreamTokenizer is a direct subclass of Object class. StreamTokenizer is included in java.io. Package. The StreamTokenizer class takes an input stream and parses it into &#8220;tokens&#8221; , allowing the tokens to be read one at a time. The parsing process is controlled by a table and a number of flags ( like [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Stream Tokenizer :</strong></p>
<p>StreamTokenizer is a direct subclass of Object class. <em>StreamTokenizer is included in</em> <strong>java.io. Package</strong>.<em> The StreamTokenizer class takes an input stream and parses it into  &#8220;tokens&#8221; , allowing the tokens to be read one at a time. The parsing process is controlled by a table and a number of flags ( like TT_WORD, TT-EOF,TT-EOL etc., all representing some integer value) that can be set to various states. The StreamTokenizer can recongnize identifiers, numbers, quoted strings and various comment styles. Tokenizing is a feature of compilers, interpreters and parsers.</em></p>
<p>A stream can contain three types of tokens.</p>
<ul>
<li><em>Words ( that is, multiple character tokens )</em></li>
<li><em>Single-character tokens</em></li>
<li><em>Whitespace( including C/C++/Java-style comments )</em></li>
</ul>
<p>Some constants, defined in StreamTokenizer, used as  flags to identity the tokens :</p>
<p><em>int TT-EOL            : A constant indicating that the end of the line has been read.<br />
</em></p>
<p><em>Int TT-EOF            : A constant indicating that the end of the stream has been read.<br />
</em></p>
<p><em>int TT-WORD        : A constant indicating that a word token has been read.</em></p>
<p><em>Int ttype                :  After a call to the nextToken method, this field contains the type of the token just read</em></p>
<p><strong>Aim : </strong>To count the number of words in a file using StreamTokenizer and whitespace as delimiter File name is passes as command-line argument.</p>
<p><em><strong>Sample program of StreamTokenizer as follows</strong></em> :</p>
<p><em>import java.io.*<br />
public class StreamTokenizerDemo  {<br />
static int words = 0;<br />
public static void wordCount(Reader r)throws IOException<br />
{<br />
StreamTokenizer st = new StreamTokenizer(r);<br />
st.wordChars(33,255);</em></p>
<p><em>// if token in not EOF<br />
while(st.nextToken()!=st.TT_EOF)<br />
{<br />
//if token is word<br />
if(st.ttype == st.TT_WORD)<br />
words++;<br />
}</em></p>
<p><em>}<br />
public static void main(String args[])throws IOException<br />
{<br />
// pass file name as command-line<br />
FileReader fr = new FileReader(args[0]);<br />
wordCount(fr);<br />
System.out.pritnln(&#8221; Total words in file :&#8221;+words);<br />
}<br />
}</em></p>
<p><em><strong>Method signature of wordChars();</strong></em></p>
<p><em>public void wordChars(int low, int high);</em></p>
<p>Specifies that all characters between thew range low and high are word constituents. A word token consists of a word constituent followed by zero or more word constituents or number constituents</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/explain-executeupdate-method/" title="Explain executeUpdate Method"><img src="Array" alt="Explain executeUpdate Method" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/what-is-event-delegation-model/" title="What is Event Delegation Model"><img src="Array" alt="What is Event Delegation Model" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/difference-between-sessionupdate-and-sessionlock/" title="Difference between session.update() and session.lock()"><img src="Array" alt="Difference between session.update() and session.lock()" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/springs-interview-questions-3/" title="Springs Interview Questions"><img src="Array" alt="Springs Interview Questions" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/difference-between-sessionsave-and-sessionsaveorupdate-2/" title="Difference between session.save() and session.saveOrUpdate()"><img src="Array" alt="Difference between session.save() and session.saveOrUpdate()" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/explain-stream-tokenizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
