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 4 of 4

Thread: How to use session handler created in one class in another class?

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to use session handler created in one class in another class?

    Hi FOlks,

    I am new to Java and you can say beginner and learning java.

    I have created a session handler in one class as below:
    Session session = null;

    Now, I want to use the same session handler in different class for creating channels. I don't want to create new session handler. How to do that?

    Please revert if need further information.

    Awaiting response !!!

    Thanks,
    Asif


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,292
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: How to use session handler created in one class in another class?

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    You can:

    1. Pass the session object to the constructor of the 2nd class,
    2. Use a setter method (mutator) in the second class to pass the session object from the first class, OR
    3. Use a getter method (accessor) in the second class to retrieve the object from the first class.

    And maybe some other ways I haven't thought of.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    7
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to use session handler created in one class in another class?

    thanks a lot Greg.
    Apologize for the inconvenience caused.
    Will take dare from next time. And thanks for your suggestion. It worked out !!!

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,292
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: How to use session handler created in one class in another class?

    Glad to help. No inconvenience encountered.

Similar Threads

  1. Need some help testing created class.
    By fpritt24 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 15th, 2013, 04:05 PM
  2. Button event handler from another class
    By Scorliss in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 6th, 2013, 07:41 PM
  3. Separate Event Handler Class
    By beer-in-box in forum AWT / Java Swing
    Replies: 2
    Last Post: April 1st, 2013, 10:19 AM
  4. scope of a class created as local variable
    By Samaras in forum Java Theory & Questions
    Replies: 6
    Last Post: August 25th, 2012, 07:01 PM
  5. Running methods of a class that created you...
    By joestr in forum Java Theory & Questions
    Replies: 2
    Last Post: April 3rd, 2011, 02:59 PM