Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: What is the function of the string in this statement?

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Posts
    26
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default What is the function of the string in this statement?

    This is actually two questions in one.

    #1 The string "thread1" at the end of line 1 of the following code - is this the name of the new MyClass created?

    #2 If the string is the name being given to the new MyClass (as I believe it is), then, which object is calling the method in line 2? The Thread, or the object of MyClass? ..........and....... does it matter?

    Thread thread1 = new Thread(new MyClass(), "thread1"); 
    thread1.start();

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What is the function of the string in this statement?

    The string "thread1" at the end of line 1
    What does the API doc for the Thread class say?

    The second statement uses the reference to the Thread object to call one of the Thread class's methods.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    FightingIrishman (January 15th, 2022)

  4. #3
    Junior Member
    Join Date
    Dec 2021
    Posts
    26
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: What is the function of the string in this statement?

    I'm learning from a book of example programs with very little explanation so I don't always have the technical language to know what I'm looking for.

    I'll bare in mind this API doc though, but for now I have this book and another to get through afterwards called "Efficient Java".

    I guess if I look at it and consider everything inside the parentheses to be arguments that are being send to a constructor of the Thread class, then I could look at the available constructors of the thread class and try and find a match.

    It's not always immediately obvious but it's getting moreso - thanks for your help Norm.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What is the function of the string in this statement?

    I'll bare in mind this API doc
    Having a shortcut to the API doc in a browser is very important. I look at it many times a day when doing any programming.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    FightingIrishman (January 15th, 2022)

  7. #5
    Junior Member
    Join Date
    Dec 2021
    Posts
    26
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: What is the function of the string in this statement?

    Ok. I'm sold. Cheers!

Similar Threads

  1. Function that will add the contents of a String array
    By parveshraju92 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 19th, 2014, 04:20 AM
  2. Delimiter function and number of words in string
    By Java girl in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 22nd, 2014, 05:08 PM
  3. How to assign a string to a math function
    By chramori176 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 31st, 2013, 06:57 PM
  4. Help with splitting string in PDF Generator Function
    By efluvio in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 21st, 2012, 05:43 PM
  5. If Statement in SQL String
    By Steffi1013 in forum Loops & Control Statements
    Replies: 0
    Last Post: March 30th, 2010, 03:25 PM