Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Java ... guage/Stream-Tokeniser-or-String-TOkenizer.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Stream Tokeniser or String TOkenizer

Posted by sree (sree), 29 January 2004
Hi,
I need to write a program that caculates the logical lines of code in  any program that is written using Java langauge. I have jus started  learning Java. I think I can use String Tokenizer for my program.

Basically, I have to look for the keywords in java language, ;, to count the number of lines in the program. Is String Tokenizer is alone sufficient for this program or I have to use some other function to do  this. My friends told I can try with split() and ReplaceAll()
function. But I don't know the usage of these 2 functions. So can you help by giving me small sample program. Later I can work on it and develope it on my own. What is stream tokenizer? How can I use in my project?


Thanks


Posted by admin (Graham Ellis), 29 January 2004
For a short utility program to analyse a text file that's written to a particular format (e.g. to analyse a program source file), I would probably not recommend you use Java;  Java is ideal for larger applications and systems but on shorter tasks you'll find a language such as Perl or Python is much more productive, even though you might feel that you're being unfaithful to Java by using another language  

Python solution:

Code:
import sys
info = open(sys.argv[1]).read()
sofar = 0
for char in info:
   if char == ";": sofar += 1
print "There were "+str(sofar)+" semicolons"


For comparison, I would expect the code to be 4 to 5 times longer than this in Java ....

Posted by sree (sree), 29 January 2004
Hi,
Thanks for that piece of information. But I have to do this using Java only. So, I like to know which one is more suitable Stream or String Tokenizer?

Thanks
Sree

Posted by admin (Graham Ellis), 29 January 2004
If you have to do this job (inappropriately) in Java, then I would suggest you open a stream and read byte by byte, checking for the ";" character.   There seems little point in you reading (for example) each line into a string for you to then have to start breaking that string down with a tokenizer.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho