Ulrika Tingle

Ranch Hand
+ Follow
since Nov 24, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ulrika Tingle

Richard Lung wrote:I'm confuse with how to approach the recursion.



Who said you needed to use recursion?

Try something else first. Then maybe recursion will seem more like a natural choise and then you'll know how to do it.
8 years ago

Christophe Verré wrote:

Why don't you just do this?


Looks like he wants to call only the methods whose name is stored in a map.



You never know until they tell you.
8 years ago
To my previous post.

You can find anything on the internet, including that OO sucks. The fact that some people on the internet think that Singleton sucks is in itself not a proof that Singleton is bad.

The fact that it's hard to perfectly implement a Singelton is in itself not a proof that Singleton sucks. Lots of very useful things are hard to implement, many of them even harder than a Singelton.

The fact that people misuses Singelton is not a proof that Singelton sucks. People misuses all sorts of language elements in every programming paradigm all the time.

So the only real test of the usefulness of Singleton is to apply Occam's razor as I explained in my previous reply.
8 years ago

Janeice DelVecchio wrote:I never said singletons were good or bad. I just don't know. Actually, my very first post said I made no assertions whether or not they should be used or not. I said I understood the basic concept of why someone would use it over a static variable. Rather, I think I just compared the two, not even made an assertion of why it should be used over a static variable.

What I said was that no one could tell me (on a foundational level) what the heck is wrong with using them. Everyone here has said "they're bad," "don't use them," et cetera.

I got links to blog posts from several years ago. Are these people respected in the field? I have no idea. No one said, "please see Joe Shmoe's blog, he's a such and such person in the blah blah industry for x years. He did studies for blah company."

When I questioned the sources, on an academic level, no one could defend the fact that the sources were blogs. No one could find a reputable source (or at least define what makes the blogs reputable).

If someone could tell me, in normal person language:
1: Why doesn't the JDK5 "volatile label fix" work to fix the singleton problem?
2: What, if any, are the problems with the Singleton pattern, exclusive of the issue of threadsafety (which is supposedly fixed by the "volatile" labeling)

I am really through with feeling like I have to defend myself. Just because I ask questions doesn't mean I'm questioning anyone's judgement, it just means I'm not going to take advice on face value no matter how long you've been following it.



Well, to cut all the crap why don't you just ask people to come up with a better solution to my postoffice Singleton?

What I'm using here is a variation of the Occam's razor, or the simplest solution is the correct one. Show a simpler solution to the postoffice Singleton and Singleton itself is in question. But until then, Singleton rules.
8 years ago

Amrita Chaurasia wrote:
After line 6, how many objects are eligible for garbage collection?



It's a trick question.

You don't know because you don't know how many eligible objects have already been GCed.

pandeyalok kumar wrote:Can anyone please suggest any way to do that.



Why don't you just do this?


8 years ago

Harshana Dias wrote:
Primitives and Object reference are store in stack right.



Do really need to know that now? Who cares "where" things are stored. What's important is that you know what happens, that the i variable gets assigned a 6.

If you're just learning Java you can do perfectly fine without things like stack and heap. They're not part of the language. They're supposed to help you understand stuff but if you feel they're not helping just forget about them. Above all, don't let them be a hindrance.
8 years ago

Mike Bates wrote:
Twiddling bits has not been easy for me so I am learning as I go. I am Googling references on this type of approach to better understand what is going on.



Bit fiddling is described in The Java Programming Language by Gossling and others. You're not a real Java programmer until you have this book.
8 years ago

karthik manick wrote:As far as my perception, without abstract classes also we can use the concept of polymorphism...then why to create a abstract class and extending it?



It's for design flexibility and control.

Say you have a fully concrete class. Now you don't want people to make objects of it, you want to force people to extend it. What do you do? That's right, you declare the class abstract.

Or say you have a class which is designed to be extended and you want to make absolutely sure every subclass provides an implementation for specific methods. What do you do? That's right, you declare those methods abstract (and because you do that the class must be abstract).

So abstract classes really aren't necessary but they're helping you decide how your class is to be used.
8 years ago

Nidhi Sar wrote:
That is very interesting.



The automatic conversion between primitives and their corresponding wrapper classes is called autoboxing (which was introduced in version 5).

8 years ago

gudim gudi wrote:
Any ideas, suggestions, resources, links, sample code highly appreciated.



A marker interface is an empty interface (has no methods). It's used as a tag to identify objects at runtime using for example the instanceof keyword, like


Note that using marker interfaces is a quite questionable practice and you should avoid introducing your own.
8 years ago

Mike Bates wrote:Any thoughts?



Sometimes it's easier and faster to do some old-fasioned parsing.

8 years ago

James Clarks wrote:The infamous Simpleton design pattern is a non-object-oriented way to write "structured" procedural code. It is typically used by programmers that either do not significantly understand object-oriented design principles or are lazy buffoons that don't care about the code they write.

This pattern should never have been included in the GOF book, and was simply a bone to get individuals to start to think about patterns period.

Just me two cents



Apart from misuse, don't you think there are any valid uses of Singletons at all? If your answer is no I challenge you to come up with a replacement for the "postoffice Singleton" I presented in a previous post.

Assuming that you don't belong to the group of programmers who "do not significantly understand object-oriented design principles or are lazy buffoons" it should present no problem for you.
8 years ago

Sbt Bhatta wrote:In both Q1 and Q2, isn't the reference type is Animal ?
SO I am guessing somewhere I understood it wrong. It seems to me as if the JVM looks at the instance type during runtime/compile time. please please pretty please



It's probably just a question of terminology.

Animal a = new Animal();
Animal b = new Horse(); //Animal ref, but a Horse object
a.eat(); // Q1
b.eat(); // Q2

In this example it's the type of the actual object that's important, not the formal type of the variables. So which overridden method that's being called is determined by the actual object type, not the formal variable type. And this selection is made at runtime. (It must be that way because objects don't exist at compile time).

This more clearly demonstrates that it's the actual object type that's involved in the method selection,

new Animal().eat();
new Horse().eat();

A formal variable isn't even involved, still the correct eat method is selected.

Note that when methods are overloaded it's the other way around. Which method to call is determined by the formal variable type and this is decided at compile time.
8 years ago

Pat Farrell wrote:
While nobody should force you to use a Singleton pattern in Java, if you work for me, I'll force you to not use it, as its bad engineering.



Well Pat Farrel, I don't work for you so I'm using Singetons when I feel they're appropriate.

Please explain why my postoffice Singleton is bad engineering and what you would do instead. I know the answer already of course. You don't have the faintest idea. As is so often the case, faced with a practical dilemma the loud speaker of dogmatic views suddenly is very silent.

And that's why I'm pragmatic on this issue. Although global data should be avoided, there will always be a need to handle them and Singletons are the best alternative (so far).
8 years ago