Saturday, November 19, 2005

Some nice Java puzzles

I came across these set of interesting java puzzles and for many of them I got trapped. See how do you fare ;) If you have a good explanation, don't hesitate to share it.

  1. public class StringTest
    {
    public static void main(String[] args){
    foo();
    bar();
    }
    public static void foo(){
    String s = "str4";
    String s1 = "str" + s.length();
    System.out.println("(s==s1) = " + (s1==s));
    }
    public static void bar(){
    String s = "str4";
    String s1 = "str" + "4";
    System.out.println("(s==s1) = " + (s1==s));
    }
    }



  2. public class Assignment {
    public static void main(String[] a){
    int count = 0;
    for (int i = 0; i < 3; i++)
    count += count++;
    System.out.println(count);
    }
    }



  3. class StaticTest {
    static { initIfNecessary(); }

    private static int sum;

    public static int getSum() {
    initIfNecessary();
    return sum;
    }

    private static boolean initialized = false;

    private static synchronized void initIfNecessary() {
    if (!initialized) {
    for (int i = 0; i < 100; i++)
    sum += i;
    initialized = true;
    }
    }
    public static void main(String[] args) {
    System.out.println(getSum());
    }
    }



  4. package click;
    public class CodeTalk {
    public void doIt() { printMessage(); }
    void printMessage() { System.out.println("Click"); }
    }
    ------------------
    package hack;
    import click.CodeTalk;
    public class TypeIt {
    private static class ClickIt extends CodeTalk {
    void printMessage() { System.out.println("Hack"); }
    }
    public static void main(String[] args) {
    new ClickIt().doIt();
    }
    }



  5. public class Lazy {
    private static boolean initialized = false;
    static {
    Thread t = new Thread(new Runnable() {
    public void run() {
    initialized = true;
    }
    });
    t. start();
    try {
    t.join();
    } catch (InterruptedException e) {
    throw e.printStackTrace();
    }
    }

    public static void main(String[] args) {
    System.out.println(initialized);
    }
    }


427 comments:

«Oldest   ‹Older   401 – 427 of 427
Anonymous said...

I belieνe this is among the such a lоt vіtal
informatiοn for me. Αnd i'm satisfied studying your article. But wanna remark on few general issues, The site taste is perfect, the articles is truly great : D. Just right process, cheers

my page ... Hotel Price tag Assessment Vs Traditional Travel Research Web sites -- Accommodations Discounts (http://www.hotel-discount.com/)

Anonymous said...

Its like уοu rеad mу minԁ!
You appear to know a lot аbout thiѕ, liκе you wrotе the bоok in іt or something.
I thinκ that you сoulԁ do with а few ріcѕ to drivе the messаgе homе a bіt, but otheг than that,
this is mаgnificent blog. Αn excellent read.

I will definіtely be back.

Αlso visіt mу ωeb site - Discounted Accommodation Several Easy Advice on Having the Best Motel Special discounts

Anonymous said...

Hi, for all timе i uѕed to check wеbpagе
pοsts here in the early hours in the dawn,
foг thе reason thаt i enjoу to fіnd
out moгe and more.

Feel frеe tο suгf to my
website: httρ://Usѕcaloosahatchеe.
org/ρhpBB2/profile.php?moԁe=νiеwprοfile&u=29025 :
: ::

Anonymous said...

I am questioning what would cause the bodyweight obtain on Zoloft or other SSRIs?
Somebody close to me just started having it and was encountering nausea being a frequent side impact.
Carbs have been the sole factor that would settle his abdomen, so he was consuming much more
carbs. Things like that could lead to bodyweight
gain. Thankfully, the nausea seems to have mainly dissipated at
this point, after two weeks of so of having Zoloft.
A few many years ago I
went on the drug that didn't listing excess weight achieve being a side impact but it made me really feel so sick that i also overate carbs to compensate and gained a lot of bodyweight.
Or can it be like the energizer bunny commenter above who said she gained and does not consume a lot, so possibly it's a metabolism thing that is certainly
independent of consuming habits?
I mean.
. melancholy by itself can cause some individuals to overeat and a few individuals to shed their hunger.

Some men and women with IBS who haven't been capable to eat significantly may possibly be using zoloft to the offlabel benefit of settling their irritable bowels down, and could feel safer eating much more and going out more to consume.
I may also picture a person who isolated because of their despair going out and socializing and consequently eating much more. I truly want we experienced much more info about what could be the lead to on the weight acquire (or reduction in a few situations.) Could it be a alter in habits or just an unbiased metabolic aspect effect?

my web site: mike chang monster mass download

Anonymous said...

We appeciate this here on "Some nice Java puzzles".
We are in Orange County|an Orange County
realty.

Here is my web page; friendly realtor in Orange County explains

Anonymous said...

Signing up for the particular Wilton Process Redecorating Principles Study course is good for those people
thinking of getting a jump in cake adorning. There are so many great gift ideas for those
people who enjoy baking, it makes gift buying a lot easier than it used to be.

For a mocha cake use both the cocoa and the coffee.


Also visit my blog - cake art salisbury md ()

Anonymous said...

Since I'm such a nice person, I walked through JCP in Dexter Missouri :: http://pinterest.com :: obituaries today when I went out of the ordinary. It's a great listserv for finding
about about possible incorrect name heading forms in bibliographic records and, I think, the occasional
name authority record correction/change.

Anonymous said...

It bears mentioning that there are also games and simulations available to those wanting to learn to trade stock
index futures. It should come as no surprise that
i - Tunes is loaded full of pirate apps for i -
Phone, i - Pod Touch, and i - Pad. For the purposes of
this game, a "set" is at least three cards of equal value such as three Jacks or
three fours and a "sequence" is made up of at least four cards that are of the same suit and run sequentially
such as three, four, five, and six of spades.

my site: click the following internet page - service.lilontex.com.tw

Anonymous said...

I've been exploring for a bit for any high-quality articles or blog posts in this sort of area . Exploring in Yahoo I eventually stumbled upon this website. Reading this info So i'm
satisfied to show that I have an incredibly good uncanny feeling I
found out exactly what I needed. I such a lot
unquestionably will make sure to do not put out of
your mind this web site and provides it a glance on a relentless basis.



my weblog - how to get rid of acne

Anonymous said...

(Thank you rounds are always welcome, of course. Below are
listed a few popular pubs where one can chill in Mumbai.
Her father, Bruce Paltrow, produced the critically
acclaimed TV series that is considered the precursor to many medical shows
today, St.

My page ... fun pub quiz names

Anonymous said...

Have you ever considered publishing an e-book or guest authoring on other sites?
I have a blog centered on the same subjects you discuss and would really like to have you share some stories/information.
I know my viewers would enjoy your work. If you are even remotely interested, feel free to send me an email.


Check out my homepage xerox 8560dn printer

Anonymous said...

I'm really impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the excellent quality writing, it is rare to see a great blog like this one these days.

testosrong reviews

Anonymous said...

Opposed to having all of your" extra" stuff into concerts orlando fl containers, you would know
that a good concerts orlando fl organization is as essential as cooking and eating your food.



My blog: buy concert tickets :: http://Www.showtel.org ::

Anonymous said...

Author Resource:-> He's a renowned specialist of dental implant Manhattan and he's certainly the go-to periodontist for inserting your dental implants.
An experienced dentist will know about it. These are just some of the
basics of finding a dentists plano and those who are not so fortunate.
At the end, you will want to make sure an upgraded grin.


Feel free to surf to my web page; plano dentists

web lol said...

kul post

Unknown said...

I enjoy reading this post. Yes, you highlight very important points about health in this post.
writing help

vanamsarithai said...

above message is very useful
here i want to introduce one more popular and very interesting thing.Goal Setting Training in Chennai, India
its about more years to be in conducted with in organization.
Corporate Soft Skills, Behavioral Training in Chennai, India
To create a mindset shift in 1 million minds, to stretch that little more in each of us, thereby contributing towards a better world for all of us and generations to come…

crazyjar.com said...

Nice Article given by you. It's very helpful for me thx for always update my knowledge.
http://www.crazyjar.com/

O. Miller White said...

This content of information has helped me a lot. It is very well explained and easy to understand.
Bankruptcy Law Firms Houston
Bankruptcy Lawyer Houston Texas

Muzamil Ansari crack said...

optimum! I want to do an internship while editing the website, how can I subscribe?
For blog sites? This account helped me close a deal.
I am a little familiar with your post, it provides a clear and bright concept.
cobra driver pack crack bootstrap studio crack
express vpn crack
jetbrain clion crack

Unknown said...


Woah! I’m really enjoying the template/theme of this website.
It’s simple, yet effective. A lot of times it’s very
difficult to get that “perfect balance” between user friendliness and appearance.
I must say that you’ve done a very good job with this.
Also, the blog loads very quickly for me on Firefox.
Exceptional Blog!
pro evolution soccer 2019 crack
teamviewer crack
magic browser recovery crack
idm crack
dj music mixer crack
foxit pdf editor crack

Junaid Khan said...

I was very happy to find this website.
I need to to thank you for ones time just for this fantastic read!!
I definitely enjoyed every little bit of it and i also have you saved
as a favorite to check out new things in your site.
hard disk sentinel crack
camtasia studio crack

Jordan Leonard said...

Thanks for other great articles, others might get it.
What kind of knowledge is such an ideal form of writing? I am the owner
I looking for so a presentation in a week.
pdftomusic pro crack
logic pro x crack
voicemod pro crack
download wonderfox dvd ripper pro crack
ultraedit

Jani said...

This is very useful software for you and me. No errors were found during the check.
You can use it. I hope you like it.
gb whatsapp crack
internet download manager crack
fabfilter total bundle crack

repack-mechanicz said...

Thanks for sharing the information with us. Keep it up.

The Witcher 3: Wild Hunt Crack
Slay the Spire Crack
Praetorians Crack
Overlord Crack

Skidrowkeyz said...

Thanks for sharing this information. I have shared this link with others keep posting such information.
Automation Empire Crack
Terminator: Resistance Crack
eFootball PES 2020 Crack

Skidrowkeyz said...

Thanks for sharing this information. I have shared this link with others keep posting such information.
Dragon Ball Z: Kakarot Crack
Farming Simulator Crack
Microsoft Flight Simulator Crack
Automation Empire Crack

«Oldest ‹Older   401 – 427 of 427   Newer› Newest»