We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

close java class

Kennywen
Kennywen asked
on
Medium Priority
259 Views
Last Modified: 2010-03-31
i want to know how to close a java class?

e.g.
MyClass newClass = new MyClass();

how to close the above class?

When the class will be close if java cannot close it?

thanks
Comment
Watch Question

CERTIFIED EXPERT

Commented:
public class Main {
    public static void main(String[] args) {

new Main();
         
    }
}


This is the simplest class you can have almost. It will just be loaded and end.

If its a thread,. it will end when run() is finished.

Author

Commented:
that mean i will end by itself?? is there any way for us to end the new operator?
CERTIFIED EXPERT

Commented:
Not quite sure I follow what you mean by end the new operator. Objects in Java - and that means just about everything, cease to exist when they are not referenced by anythin else, so when they go out of  scope, they die.
Sr. Software engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
In languages such as C++ there aer *de*structors, which are the opposite of constructors. In Java, you dont need that, because when an object is no longer pointed to (referenced) by any other object, then it is removed from memory by the garbage collector - System.gc() - automatically.
Mayank SPrincipal Technologist
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
Now, *you* are "repeating" *me*. Aren't you? ;)
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Just added the extra line of code ;-)
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
>> Just added the extra line of code ;-)

mayankeagle, in fact I was talking to krakatoa :)
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Oh.... I thought the "candidate for garbage-collection ". Anyways ;-)
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Why a B :-(
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
Yeah, I also wonder...
Sometimes people think that the grades relate for the difficulty of the question.
But that isn't the case. If the answer is good an to the point it deserves an A.

Anyway, thanks for accepting.
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Yeah, it also makes no difference to the questioner as they only spend as many question-points as they allocated to the question. Some closing help here:

https://www.experts-exchange.com/help/closing.jsp
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.