Question:
How can I writing this without using package names or import statements?
billy t
2011-04-22 19:08:27 UTC
I'm writing a program and I'm not aloud to use "import statements or package names"

the things that are giving me errors are Stringtokenizer and IOException..

without using import statements I changed these to

java.util.Stringtokenizer and java.io.IOException

are these package names? if so.. how do I write these without package names or import statements
or is there no way?
Four answers:
Vaibhav
2011-04-23 02:36:49 UTC
if you do not import packages you would not be able to use these classes
modulo_function
2011-04-22 20:09:11 UTC
I disagree with the statements about StringTokenizer, it's much more versatile than split(..). It has a nextToken() method that returns boolean and can be used in a while(..) to read each token without knowing how many there are.



Anyways,



Your error is in spelling: it's StringTokenizer.



I don't see what's wrong with the IOException.



I've given links for further research.



To use a class without the imports you just have to use the complete name

instead of

StringTokenizer st = new StringTokenizer();



instead use complete name:

java.util.StringTokenizer st = new java.util.StringTokenizer();



Any import statement can be eliminated by using the complete names as I've shown above.



That's all that's require to obviate the need for import statements.
Silent
2011-04-22 19:29:50 UTC
Yes, those are package names. java.util and java.io are packages.



You can't use either of those classes without using either a package name or an import statement.



However, in modern Java you should never need to use StringTokenizer. The String class now has a split() method that will do pretty much the same thing. String is in the java.lang package, which is a special package that does not need to be imported or referred to explicitly with a package name.
2016-11-19 10:11:38 UTC
right it relatively is an occasion... import java.till*; The asterik (*) skill that's consisting of all classes in this kit. even even though it does not make sub-applications attainable. in case you needed a sub kit you will possibly could in my view upload those you prefer to apply.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...