Virendrasinh Gohil

Ranch Hand
+ Follow
since Jun 09, 2004
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 Virendrasinh Gohil

Of course. See your class B itself. It is not even reaching clone method.
in main itself is causing stack overflow. (Object inside object problem)
13 years ago

André Asantos wrote: Does anybody get to interpret this following code: ->

This says, the sort method accept list of Ts where T must implement comparable interface. Later part actually defined the type of Comparable interface. It says, the comparable interface should be of type of it's base class of current class.

Please see the code below for better understanding.
13 years ago
Did you check whether you application is executing properly when defining listener? It might happen that the application is failed to initialized. Please check logs post error if any.
13 years ago

leroy tsruya wrote:

Many problems with this sample.

1. SampleChild1State1 is interface? If so, it must extend State interface if not, must defined as class
2. SampleChild1 must extend BaseClass (as State interface can only accept <T extends BaseClass>)

3. The setState method is expected to accept object of StateMachine of type T which extends BaseClass only. Whereas, you are trying to pass SampleChild1State1 which is (if a class) implementation of State itself.
13 years ago
well, the weirdest code that anyone would write (of, I just did)

Well, this is just for fun and has nothing to do with developing complex app using this sample.
13 years ago

Christopher Daly wrote:.... It says it doesnt recognise the JAVAC command...

Looks like you are facing problem with PATH variable. You must have your 'JAVA_HOME' defined and your path '%JAVA_HOME%/bin' added.
13 years ago
Hi Chan,

It is always recommended to check logs for any issues while running web apps. You would have errors in log file for such issue.
13 years ago
hmm.. right. So I think, to generalize, saying "encapsulation should be used" is better instead of saying Object-Orientated. (though encapsulation is one of the concept of OO).
13 years ago

Ravi Kiran V wrote:Are you not handling Guest users ??
Your coding is as such that :
If a User opens a Web page you cant create a Session for him , until he logs into the web site .(He may open the web page just to browse , without logging in )

I think that depends on the business scenario whether Yekkala Krishna wants to know number of concurrent users or number of concurrent active request? If it's active users, sriram's reply is sufficient but if it's number of active request, you may choose ServletRequestListener instead.

One more modification, I would prefer to use AtomicInteger instead.
13 years ago

David Newton wrote:

Virendrasinh Gohil wrote:OBJECT-ORIENTATION is the only answer.

Hardly, but it's appropriate in some cases.

I intended only for current implementation (specially when many arrays are tracked/mapped using single 'i'). I should have said, Object orientation is the only answer to make above problem simple. Happy to know if any better approach/paradigm is suitable on such situation.
13 years ago

Ween Li wrote:Hi

How do i get the list of name[i] from the loops?

From the code, it seems like, you are suffering from C-style-coding-syndrome. These detail can instead be wrapped into single clss and can make it easy to track. (May be array of objects of that class having details like, name, scholarship (boolean), gpa, programme, gender, etc...)

However, if I have to just answer your question, create another array of strings and copy the name from original array as and when your condition is satisfied. (for instance)
So, by end of the loop you will have all names of the people with qualifying criteria.

Or may be if I am understanding your business requirement right, you are interested in those i'th values of satisfying criteria so that you can get detail of that ith person using that 'i' (and that's where you should use more object oriented paradiam instead of tracking information of a person using 'i'th value in each arrays), you better define int array to store the ith position which matches the criteria. By end of the 'for' loop, you will have all 'i'th value stored in array. You can utilize that later to retrive whatever information you want from those arrays.

But believe me that is real real bad practice. (tracking using 'i'th value of an array) That makes your code vulnerable. What if one of the value in one of the array is rearranged? or one of the value is missing for one of the person? you will have complete mismatch.

OBJECT-ORIENTATION is the only answer.
13 years ago

Megs Maquito wrote:
Virendrasinh Gohil = javaGenius(int x);
public int javaGenius (int n){int intelligence = n * infinity; return intelligence};

Good code. I am delighted. I am happy it helped
13 years ago

Megs Maquito wrote:Hmmm. that seemed to do the trick here's the result:

L is 20 i is 0
L is 140 i is 13
outside the for loop

Question is: why would i need to put something outside the for loop? is the i % == 2 somehow telling the class to repaint itself or is it the sequence after the JFrame declaration in main() method? I have other classes that have a for loop that does not have a statement outside the for loop and works perfectly. Here's an example:

No, putting print statement outside of for loop will not prevent executing the paintComponent() method multiple times. I just mentioned that to show you that it's not the "for" loop which is creating problem but it is the event of request to repaint the JPanel. And that is what exactly happened when you re-executed the application. Whenever there is a repaint (either manual or system generated) event, your paintComponent() will get executed.

I could put the for loop in the main method but I want the drawing to be repainted if i resize the JFrame, thus I put the for loop in the paintComponent() method.

Now, if you want to recalculate the length of line on every paintComponent() method, you need to calculate using actual numbers (and not just keep increasing the line using for loop). That means, if the frame/panel is reduced in size, the line size should use new width/heigth values to decrease the line length. This way, let it be multiple repaint event to occur for same window, it will always calculate the lineLength correctly.
13 years ago
Seems like your paintComponent() getting called multiple times. (Try to put one more sysout outside of for loop to prove).

This is event based and whenever there is a need of painting the component, this method will be called. Now depending upon what do you want to do, you can add appropriate logic there in paintComponent method. If you want to recalculate (or something else) on every paint event, you can do it in paintComponent() method. (Not sure from your code what are you trying to do with lineLength in paintComponent method.) If it is a one time activity you may want to reconsider refactoring your code.
13 years ago

Lester Burnham wrote:It is quite bad practice since it..........

I agree. Thanks for reminding.
13 years ago