Question

In: Computer Science

Garbage collector works in following condition: 1. Employee john = new Employee() john=null; 2. Employee c1...

Garbage collector works in following condition:

1.
Employee john = new Employee()
john=null;

2.
Employee c1 =new Employee()
Employee c2 = new Employee()
c1=c2;

3.
new Employee(); //anonymous object

Please create a class /classes in java which contains examples related to above 3 conditons.

Solutions

Expert Solution

In java, when object has no reference or unreferenced (means it is no longer usable) the memory given to these objects can be made avilable or free. and all this is done automatically by Garbage collector in java.

Here is screenshot of Java code:

Here is the Output:

Here is the code:

public class Employee {
    // finalize method is used to perform cleanup activities
    // we can make finalize public also
     protected void finalize()
    {
        System.out.println("Garbage collector collected the object");
    }
    public static void main(String[] args) {
        Employee john = new Employee();
        john=null; //object john has no vlaue so space allocated to it can be freeup
                 
      
        Employee c1 =new Employee();
        Employee c2 = new Employee();
        c1=c2; //now c1 has value of c2 so previous allocated space can be freeup
             
      
        new Employee(); // this anonymous object is of no use so it can also freeup
                      
        System.gc(); //this method is used to invoke the Garbage Collector
    }
}


Related Solutions

Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-id, company-id, salary)             company(company-name, company-id, c-city)             manages(employee-id, manager-id) Specify the following queries on this database schema using the relational operators we discussed in class. Write your answers on a separate sheet of paper in the order that they are specified below. Retrieve the name and address of employees who work for First Bank Corporation. Retrieve the name, street address, and city of residence of all employees...
“Imagine John works for a company in New York that sells widgets. As part of his...
“Imagine John works for a company in New York that sells widgets. As part of his job, John has access to a one-page document belonging to the company that contains its secret method for manufacturing high-quality widgets at low cost. John decides to leave his company and to start a competing widget company in New Jersey. John concludes that he needs to bring a copy of the document to New Jersey to start his business. Consider the following ways that...
ABC Company is considering the purchase of a new garbage truck ON 1/1/20. The truck will...
ABC Company is considering the purchase of a new garbage truck ON 1/1/20. The truck will cost $40,000 and have useful life of 5 years with a salvage value of $0. The new truck is much more efficient than the old delivery truck and should increase the company’s annual cash operating income by $12,000. Straight-line depreciation will be used.  The income tax rate is 25% and ABC Company’s hurdle rate is 10%. PRESENT VALUE TABLES ON THE EXAM’S LAST PAGE. Payback...
Situation #1 – For questions 1 through 5 John works in a factory as a Quality...
Situation #1 – For questions 1 through 5 John works in a factory as a Quality Expert and is responsible for doing quality product testing before the finished products are sent to the customers. John takes a sample of 10 from a batch of 1000 items and begins quality testing the products. Question 1: If the products fail the test, what should happen next? Do not indicate accept or reject either hypotheses. Instead, indicate what should happen to the product....
Compute the related samples t on the following data set. Condition 1 Condition 2 15 14...
Compute the related samples t on the following data set. Condition 1 Condition 2 15 14 11 9 13 7 7 12 What can we conclude about our findings?
QUESTION #2 John works at a financial institution in the United States and his job profile...
QUESTION #2 John works at a financial institution in the United States and his job profile makes him interact with the various components of the nation’s financial system. He is of the view that a nation’s citizenry is better-off when everyone is self-sufficient and no one needs to borrow from or lend to someone to succeed in their respective ventures. In fact, he comes from a family background that considers borrowing to be an embarrassment. To be debt-free is what...
You cross the following two individuals: Individual 1: A/a;B/b;C1/C2 Individual 2: a/a;B/b;C1/C2 A is fully dominant,...
You cross the following two individuals: Individual 1: A/a;B/b;C1/C2 Individual 2: a/a;B/b;C1/C2 A is fully dominant, B is dominant lethal, whereas C1 and C2 are incompletely dominant The proportion of offspring that are expected to have the same phenotype as individual 1 is _________
True or False: 1. An employee works under the control of an employer, so an employment...
True or False: 1. An employee works under the control of an employer, so an employment contract is not necessary to define the relationship of the employee to the employer. 2. A federal statue provides members of a labor union the right to collective bargaining. 3. The FMLA entitles an eligible employee to 12 weeks of unpaid leave, but an employment contract may provide that the employer will pay the employee during 12 weeks of paid leave. 4. Both the...
Given the following pre-condition and program segment, what is the post-condition for y? // Pre-condition: -2...
Given the following pre-condition and program segment, what is the post-condition for y? // Pre-condition: -2 <= x < 4 y = 2*x*x - x +3
Goup Number: 14 Group Project 2 - Financial Condition Analysis John Green, a recent graduate with...
Goup Number: 14 Group Project 2 - Financial Condition Analysis John Green, a recent graduate with four years of for-profit health management experience, was recently brought in as assistant to the chairman of the board of Digital Diagnostics, a manufacturer of clinical diagnostic equipment. The company had doubled its plant capacity, opened new sales offices outside its home territory, and launched an expensive advertising campaign. Digital's results were not satisfactory, to put it mildly. Its board of directors, which consisted...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT