Results 1 to 9 of 9
  1. #1
    javanb is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Red face Why would a String class need a wait() method?

    I now understand that every class has Object as a base class. This is great but I noticed that Object has several wait() methods, which means every class have these methods?

    If so, why would a String class need a wait() method?

    If this is part of an entire concept or design philosophy in which even a basic type needs to control program/thread execution, where do I learn more about this?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    Quote Originally Posted by javanb View Post
    I now understand that every class has Object as a base class. This is great but I noticed that Object has several wait() methods, which means every class have these methods?

    If so, why would a String class need a wait() method?
    Because you can wait() on any Object.

    Quote Originally Posted by javanb View Post
    If this is part of an entire concept or design philosophy in which even a basic type needs to control program/thread execution, where do I learn more about this?
    String does not need to "control program/thread execution", but you can write a program that uses a String as a lock, for example.

    Lesson: Concurrency (The Java™ Tutorials > Essential Classes)

  3. #3
    javanb is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Question

    Quote Originally Posted by KevinWorkman View Post
    Because you can wait() on any Object
    I understand what it means to wait on a process, thread, or task. But what does it mean to wait on an object?

    Wait on object creation? Wait on object deletion? Other?

    Thanks.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    ...what? If you understand waiting, I'm not sure what you don't understand about the wait function.

    What happened when you wrote a test program to play with what wait does?
    Last edited by KevinWorkman; 12-03-2010 at 08:44 PM.

  5. #5
    javanb is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    what you don't understand about the wait function.
    What does it mean to wait on a String, for example? Wait on its creation? Wait on its deletion? Other?

    I understand waiting on a synchronization object such a mutex, a spinlock or semaphore. But treat every class (including strings) as a synchronization object? I need to understand this concept. This is totally new to me.

    Thanks.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    Quote Originally Posted by javanb View Post
    What does it mean to wait on a String, for example? Wait on its creation? Wait on its deletion? Other?
    What does it mean to wait on any Object? Perhaps you should consult the API: Object (Java Platform SE 6)

  7. #7
    javanb is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    What does it mean to wait on any Object? Perhaps you should consult the API: Object (Java Platform SE 6)
    This means that any class can block the current thread? This is definitely a radical change from what I know in C++ class libraries.

    I wonder why the Java designers decided to give so much power to every object. There must be a good reason for this. Any idea where I can find reading material about this new concept?

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    Quote Originally Posted by javanb View Post
    This means that any class can block the current thread? This is definitely a radical change from what I know in C++ class libraries.
    I don't know how it works in c++. But it's not that any class can block the current Thread: it's that you, the programmer, can use any Object to block the current Thread.

    Quote Originally Posted by javanb View Post
    I wonder why the Java designers decided to give so much power to every object. There must be a good reason for this. Any idea where I can find reading material about this new concept?
    I'm confused by what you're confused about. Why do you see this as a bad thing? The power is not given to "every Object", the power is given to the programmer. I don't know how it works in c++, but I don't see anything "wrong" or complicated with how it works in Java.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,010
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by KevinWorkman View Post
    I'm confused by what you're confused about. Why do you see this as a bad thing? The power is not given to "every Object", the power is given to the programmer. I don't know how it works in c++, but I don't see anything "wrong" or complicated with how it works in Java.
    C++ (nor C) have multi threading, locking and synchronization built in the language. You have to use a special library (e.g. pthread) for that purpose so obviously not every class object can serve as a lock or synchronization point. Java is much easier when it comes to that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 2
    Last Post: 05-01-2010, 08:59 AM
  2. Pass String[] into method in different class
    By Swankee in forum New To Java
    Replies: 19
    Last Post: 09-28-2009, 05:30 PM
  3. Replies: 4
    Last Post: 03-03-2009, 09:39 AM
  4. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  5. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •