+ Follow
since Nov 20, 2000
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Govinda

Originally posted by Shubhangi A. Patkar:
Vidya, Gautam,
This is what the documentation says:
That means that even if there is nothing to trim, a new string is created and returned.
Correct me if I got this wrong...

[This message has been edited by Shubhangi A. Patkar (edited November 28, 2000).]

Ranchers ,
listen to me ,
i have not read this post but on surfing i have met through a statement originally posted by Shubhangi .
i want to give my openion in this concern ( if helpfull to anyone of you collect it) according to above statement following code should print false , but i am sorry to say it is "not" .
class contradiction {
public static void main(String arg[]) {
String s = new String("govinda");
String a = s.trim();
i want to say something here , beside of clearing out your doubt on this type of question here better all of you open the java api source code available free with jdk and try to find out there how a particular method performing its work. don't try to make analogies because they won't work here .
- take care
enable your mail-id , i will tell you .

Originally posted by shree vijay:
It worked! thanks. How should i improve my coding style?
Would you clarify?

Originally posted by lucy hu:
If s=null, Float.valueOf(s) will throw NullPointerException
If s=null, Integer.parseInt(s) will throw NumberFormatException

i want to add something to this for infomation only.
If s=null, Integer.valueOf(s) will throw NumberFormatException
If s=null, Integer.decode(s) will throw NullPointerException
Integer , Byte , Short , Long classes throws above mentioned exception on calling correspondingly available methods.
i think for explaination for these better you look
inside the source code of these classes available with JDK.
you can better understand by that and some more things also.

nothing is problum.
you have commited a very general mistake and that is
the getDateInstance Method is static and the call to that
method is not it as
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG,Locale.US);//1
and definately every thing will be fine.
one suuggestion (if you accept)
" change your coding style . this style almost suffering from
this kind of problums. "

Originally posted by shree vijay:
Consider the following program:
/* Creating a purchase order screen */
import java.awt.*;
import javax.swing.*;
import java.text.*;
import java.util.*;
class POFrame extends JFrame

// constructor
public POFrame()
super("Purchase Order");

Panel leftPanel;
Panel rightPanel;
Panel topPanel;
Panel paymentPanel;
Panel submitCancelPanel;

getContentPane().setLayout(new GridLayout(3,0));

leftPanel=new Panel();
rightPanel=new Panel();
topPanel=new Panel();
paymentPanel=new Panel();
submitCancelPanel=new Panel();

// Filling the TopPanel

leftPanel.setLayout(new GridLayout(4,1));
leftPanel.add(new Label("Date"));
Date today = new Date();
DateFormat df = getDateInstanceDateFormat.LONG,Locale.US);//1
String prntDate = df.format(today);
TextField dateText = new TextField();
leftPanel.add(new Label("ITEM CATEGORY"));
Choice item_category = new Choice();

rightPanel.setLayout(new GridLayout(4,1));
rightPanel.add(new Label("ITEM DESCRIPTION"));
rightPanel.add(new TextArea());
rightPanel.add(new Label("ITEM COMPONENT"));
java.awt.List compList = new java.awt.List(3,false);

topPanel.setLayout(new GridLayout(1,2));

paymentPanel.setLayout(new GridLayout(4,1));
paymentPanel.add(new Label("PAYMENT METHOD"));

CheckboxGroup cbg=new CheckboxGroup();
Checkbox cbx1=new Checkbox("Visa",false,cbg);
Checkbox cbx2=new Checkbox("MasterCard",false,cbg);
Checkbox cbx3=new Checkbox("American Express",false,cbg);


// Filling the submitCancelPanel

// add Buttons

Button CancelButton = new Button("Cancel");
Button SubmitButton = new Button("Submit");





In the getDateInstance() call in line marked // 1
i am getting a cannot resolve symbol error. I checked the syntax and the import statements , but couldn't find the bug
... Any help?

in the case of missing any right chice you will definately get a 0

Originally posted by Mamta Jha:
I have a doubt regarding marking in real exam.If a ques has more than 1 correct answer and I miss one of the answers or 1 of the ans is wrong ,do I get 0 for that ques.
Plz clear my doubt.

1) this code definately going to throw nullpointerexception
you prediction is absolutely right.
2) when ever you are going to declare any local or automatic variable create a separate scope there if it could be happened a number of times.
for(int i=0;i<10;i++)
String s = "govinda";

the above will definately going to give compilation error stating invalid declaration. do inspite of above as this,
for(int i=0;i<10;i++)
{String s = "govinda";}
putting curley braces will not cause thi error because by this every time program execution flow leave that curley braces String s goes out of scope and hence cease and in the next time
it again get created and after completing that block again ceases. this cycle will goes on up to iteration continues by your for loop.

Originally posted by Mamta Jha:
hi everybody,
My doubt is
1.String s=null;
should throw nullpointer exception,but it shows 0.why?
2.for(int i=0; i<N; i++)>
String tmp = "test"; //why this shows compilation error as variable redeclaration
I'll be thankful,if anybody could answer these ques

here is the way with which you can convert any number
fall in to int range of java primitive . here is a class named
parseInteger inside that a static method is available there
so you can use that static method in your requird place or
i also give a main method in this class which accept a
command line parameter and shows the word value according to it.
i convert the number in indiam number system. means
1432456 = fourteen lacs thirty two thousand fifty six.
and i used Arab and Kharab in place of million and billion and trillion .
i think better you run it and see how it convert number from digits to words.
in the case of any modification required either do yourself or write on javaranch in the same thread. i will do that for you. probabely when you see the logic behind this , you can easily made your required modifications.
for run this program simple compile by javac and then
run as java ParseInteger 123456
you see the output
One Lacs Twenty Three Thousand Four hundread fifty six.
one more thing i didn't use exception handling mechanism. so if you required do it to made your code more robust. and although the only mistakes that can happened will be at the time of giving input via command line or to static method, so if you take care in both of these concerns , i don't think any exception may occurd ever.
copy this code by cut & paste from the bottom version. i am writing code here in two places one below another. first is formatted that may cause some irritation at the time of
paste but the second one didn't . so if you copy , do it from bottom version.
public class ParseInteger {
static String parseDigitToWords(int number1) {
String number = new Integer(number1).toString();
String token[] = new String[(number.length()%2 == 0)?number.length()/2+1 int)(number.length()/2.0)+1];
int i=0;
for (int j=0;number.length()>j ;)
{ String a;
if ((j==3)| |(number.length()==j))
{ token[i++]=a; continue;}
number = "";
for (int j=0;j<token.length;j++){<br /> String d2c="";<br /> switch(((token[j].length()==2))?token[j].charAt(0):98)<br /> { case '0' : break;<br /> case '1' : switch(token[j].charAt(1))<br /> { case '0': d2c+=" Ten";break;<br /> case '1': d2c+=" Eleven";break;<br /> case '2': d2c+=" Twelve";break;<br /> case '3': d2c+=" Thirteen";break;<br /> case '4': d2c+=" Fourteen";break;<br /> case '5': d2c+=" Fifteen";break;<br /> case '6': d2c+=" Sixteen";break;<br /> case '7': d2c+=" Seventeen";break;<br /> case '8': d2c+=" Eighteen";break;<br /> case '9': d2c+=" Nineteen";break;<br /> } break;<br /> case '2': d2c+=" Twenty";break;<br /> case '3': d2c+=" Thirty";break;<br /> case '4': d2c+=" Fourty";break;<br /> case '5': d2c+=" Fifty";break;<br /> case '6': d2c+=" Sixty";break;<br /> case '7': d2c+=" Seventy";break;<br /> case '8': d2c+=" Eighty";break;<br /> case '9': d2c+=" Ninety";break;<br /> } <br /> switch(((token[j].length()==2)&&(token[j].charAt(0)!='1'))?token[j].charAt(1):token[j].charAt(0)) <br /> {<br /> case '0' : break;<br /> case '1' : if (token[j].length()==1| |((token[j].length()==2)&&!(token[j].charAt(0)=='1'))) d2c += " One";break;<br /> case '2' : d2c += " Two";break;<br /> case '3' : d2c += " Three";break;<br /> case '4' : d2c += " Four";break;<br /> case '5' : d2c += " Five";break;<br /> case '6' : d2c += " Six";break;<br /> case '7' : d2c += " Seven";break;<br /> case '8' : d2c += " Eight";break;<br /> case '9' : d2c += " Nine";break;<br /> <br /> }<br /> switch(j)<br /> {<br /> case 0 : break;<br /> case 1 : if (d2c.trim().length()!=0) d2c+=" Hundread";break;<br /> case 2 : if (d2c.trim().length()!=0) d2c+=" Thousand";break;<br /> case 3 : if (d2c.trim().length()!=0) d2c+=" Lacs";break;<br /> case 4 : if (d2c.trim().length()!=0) d2c+=" Crore";break;<br /> case 5 : if (d2c.trim().length()!=0) d2c+=" Arab";break;<br /> case 6 : if (d2c.trim().length()!=0) d2c+=" Kharab";break;<br /> }<br /> number = d2c+number;<br /> }<br /> return number;<br /> }<br /> public static void main(String arg[]) {<br /> System.out.println(parseDigitToWords(new Integer(arg[0]).intValue()));<br /> } }<br /> <br /> </pre><br /> <br /> bottom version --> not formatted , use copy & paste from here will be free of rest of some irritation.
public class ParseInteger {
static String parseDigitToWords(int number1) {
String number = new Integer(number1).toString();
String token[] = new String[(number.length()%2 == 0)?number.length()/2+1 int)(number.length()/2.0)+1];
int i=0;
for (int j=0;number.length()>j ;)
{ String a;
if ((j==3)| |(number.length()==j))
{ token[i++]=a; continue;}
number = "";
for (int j=0;j<token.length;j++){>
String d2c="";
{ case '0' : break;
case '1' : switch(token[j].charAt(1))
{ case '0': d2c+=" Ten";break;
case '1': d2c+=" Eleven";break;
case '2': d2c+=" Twelve";break;
case '3': d2c+=" Thirteen";break;
case '4': d2c+=" Fourteen";break;
case '5': d2c+=" Fifteen";break;
case '6': d2c+=" Sixteen";break;
case '7': d2c+=" Seventeen";break;
case '8': d2c+=" Eighteen";break;
case '9': d2c+=" Nineteen";break;
} break;
case '2': d2c+=" Twenty";break;
case '3': d2c+=" Thirty";break;
case '4': d2c+=" Fourty";break;
case '5': d2c+=" Fifty";break;
case '6': d2c+=" Sixty";break;
case '7': d2c+=" Seventy";break;
case '8': d2c+=" Eighty";break;
case '9': d2c+=" Ninety";break;
case '0' : break;
case '1' : if (token[j].length()==1| |((token[j].length()==2)&&!(token[j].charAt(0)=='1'))) d2c += " One";break;
case '2' : d2c += " Two";break;
case '3' : d2c += " Three";break;
case '4' : d2c += " Four";break;
case '5' : d2c += " Five";break;
case '6' : d2c += " Six";break;
case '7' : d2c += " Seven";break;
case '8' : d2c += " Eight";break;
case '9' : d2c += " Nine";break;

case 0 : break;
case 1 : if (d2c.trim().length()!=0) d2c+=" Hundread";break;
case 2 : if (d2c.trim().length()!=0) d2c+=" Thousand";break;
case 3 : if (d2c.trim().length()!=0) d2c+=" Lacs";break;
case 4 : if (d2c.trim().length()!=0) d2c+=" Crore";break;
case 5 : if (d2c.trim().length()!=0) d2c+=" Arab";break;
case 6 : if (d2c.trim().length()!=0) d2c+=" Kharab";break;
number = d2c+number;
return number;
public static void main(String arg[]) {
System.out.println(parseDigitToWords(new Integer(arg[0]).intValue()));
} }

[This message has been edited by Govinda (edited November 28, 2000).]
you are absolutely right John.
actully i was typing a detail explaination in this regard
but now you say the same thing which i want to provide.
this is true. inner class variable initialization is absolutely meaningless if explicitly that inner object is not created. what people want to do with that initialization ? i didn't understand. because learning and thinking track is not proper so i expect that in future i might see a question from a "learner" that why java interface can't have constructor ? and when i ans to that question in my way i would definately get the reply that, we are learner and this is our right to stuff this site with these kind of questions.
but because of your very accurate reply is there so i think that i should not post my reply which is same as you but have some more detail explaination.
-Good Day John

Originally posted by John Wetherbie:
No, don't think this.A1.i will work. (At least it doesn't for my version of the JDK. :-))
When you instantiate A you don't automatically get an A1. You need to explicitly create an A1. If A had a ctor then that might be a goob place to do it.
Given the example code, here is a way to set the i var of A1:
// inside class B
B(int i,
int j)
A.A1 a1 = new A.A1(); // can also use A1 a1 = new A1
this.j = j;
The next question that arises is how to access this A1 instance. It would seem that without A or B having a member variable of class A1 it would go out of scope.
Help, anyone!?

I am surprised that a person like me awarded by status ranch hand . thanks to Javaranch
why not !!!
even you can use a computer too.
-take care

Originally posted by Santhosh Kumar:
Hi All,
Can we use calculator in the exam? Is its allowed, it will be very easy for binary and other conversions.

samir ,
as your question states and you are expecting that ii=2
should be included in the output. this is absolutely correct.
and by this i expecting that you are familiar with Object creation process. and as you all ready know that variable declared inside interfaces are implicitly static final. when whether class or interface declares static final member then there initialization process contain a little twist . and that twist is in the case of interfaces if they are having direct literal value associated at the time of declaration then in the loading procedure another variables need not to be initialized at that moment. it doesn't matter whether they are static or not. so because of your class Sam1 prints the value of J.i & K.j then in the case of J.i because variable in the I and referred from J then only variables of interface I get Initialized and because variabe i in interface I has direct literal associated with it so not any other variable initialization take place and thats why you have only 1 as output.
and second your Sam1 class going to print value K.j , this variable is defined in J and initializes via a method of another class . so when this get Loaded according to procedure of init if any of code has to execute then every variable get forcefully init. so your K.j variable init and get executed or (init) every variable available in that declaring interface. if you want to print ii=2 also then made code executing at time of init of Interface I . in the following way. now this code prints or works according to your expectation.

if you enabled commented line then and commented out previous line "System.out.println(J.i);" then also your required line
ii=2 printed. because of init of .
still not replied ...
typing reply....

Originally posted by Samir Parikh:
Pl. see following code..
interface I {
int i = 1;
int ii = Sam1.out("ii",2);
interface J extends I {
int j = Sam1.out("j",3);
int jj = Sam1.out("jj",4);
interface K extends J {
int k = Sam1.out("k",5);
public class Sam1{
public static void main(String args[]){
static int out(String s,int i){
System.out.println(s + " = " + i);
return i;
Now the output of this code is ..
Why it does not display ii=2 ?

1) defiately.
2) nothing can be said. (i didn't found any one)
3) definately not.

Originally posted by Shubhangi A. Patkar:
Could any one please shed a light on this?
Are there any questions on the following topics or are these to be studied as a pre requisite for other topics:
1. awt components: do questions on these come(as in constructor or methods or questions are more on the events that these generate?)
2. applets: esp about the parameters taken, tags to be put in html files etc.
3. jar/ javadoc utilities
I can't find a refernce to these in any of the objectives(awt obejctive is does say component and container but i am slightly confused), but mocks seem to carry questions on these. I need to know if a general idea is enough or do i need to cram about this also?

Originally posted by Bin Zhao:
Only Frames can contain menu bars or pull-down menus.
I think it is true.
But a mock exam's anwser is false.
Can anyone clear this?

Bin Zhao,
as your question states "Only frames can contain menubar or pull-down menus"
my ans for that question is false.
explaination ---->
mind a "or" is involved in the question. and this is not logical or which we generally used in programming languages . this means here that both of the segment "menubar" & "pulldown menu" should be considered separately and then ans.
the first part of this question about menu bar is true that only frames can contain menubar but for "pull-down menu"
i want to give some args in that favour.
generally people think that pull down menu is a menu which is attatched to frame directly (0 level). but this is not true in this concrens. because a pull down menu is a menu which get down on pull ( or selecting) and probabely you have seen all ready that a popup menu can contain pull down menu's. and no doubt
popup menus can be attached to a lot of awt components. so by this way a lot of awt components can contain pull down menus.
so second segment is false here that's why entire question returns false here.
(this is only my openion in the favour of that ans given by the author of that question containing mock exam.)

Originally posted by lakshmi nair:
Just wondering, is Void a wrapper class? Its not specified explicitly as for all other wrapper classes in the API.

probabely you have not studied Java API Lakshmi Nair
here is what given in api (update your knowledge...)
(and void is primitive data type as int , long, double , float , char, boolean , byte
probabely you will face the utility of primitive void and "Wrapper" Void in Beans.)
Class Void
public final class Void
extends Object
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.


[This message has been edited by Govinda (edited November 26, 2000).]