Memory Analysis in Java

Source: Internet
Author: User

Memory is divided into heap memory and stack memory, test test=new test () is displayed in memory, the first part in the stack memory is allocated an address new Test () in the heap memory allocation allocation equivalent address room number

 Packagestudy1; Public classTest { Public Static voidMain (String args[]) {test test1=Newtest (); intDate=9; Birthday B1=NewBirthday (7,7,1970); Birthday B2=NewBirthday (7,7,1990);        Test1.change1 (date);        Test1.change2 (B1);        Test1.change3 (B2); System.out.println ("Date:" +date);        B1.display ();    B2.display (); }     Public voidChange1 (inti) {i= 1234;//the date value is not modified here, and the date value copy to I    }    //Once the method is executed, the allocated object memory disappears     Public voidChange2 (Birthday b) {//b same address as B1b=NewBirthday (1,1,2010);//b pointing to the new object will not be the original B1 address, assigning a new address, nor modifying the B1//cannot modify the value in B1    }     Public voidChange3 (Birthday b) {B.setday (22); }}classBirthday () {Private intDay ;Private intmonth;Private intYear ; Public voidSetday (intDay ) {     This. Day =Day ;} Public voidSetmonth (intmonth) {     This. Month =month;} Public voidSetyear (intYear ) {     This. Year =Year ;} PublicBirthday (intDintMinty) { Day=d;month=m;year=y;} Public intGetDay () {returnDay ;} Public intGetMonth () {returnmonth;} Public intgetYear () {returnYear ;} Public voiddisplay () {System.out.println ( day+ "--" + month + "--" +year+ "--");}}

Memory Analysis in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.