淺談JAVA內(nèi)存分配與參數(shù)傳遞
JAVA中方法的參數(shù)傳遞方式只有一種:值傳遞。
JAVA內(nèi)存分配:
1.棧:存放 基本類型的數(shù)據(jù)、對(duì)象的引用(類似于C語(yǔ)言中的指針)
2.堆:存放用new產(chǎn)生的數(shù)據(jù)
3.靜態(tài)域:存放在對(duì)象中用static定義的靜態(tài)成員
4.常量池:存放常量
5.寄存器
6.非RAM存儲(chǔ)
class BirthDate{ private int day; private int month; private int year; public BirthDate(int d,int m,int y){ day=d; month=m; year=y; } }
public class Test{ public static void main(String[] args){ int date=9; Test test=new Test(); test.change(date); BirthDate d1=new BirthDate(7,7,1970); } public void change(int i){ i=1234; } }
public class TestTransfer{ public static void main(String[] args){ int a=6; int b=9; swap(a,b); System.out.println("交換結(jié)束后,a的值是"+a+";b的值是"+b); //a=9,b=6 } public static void swap(int a,int b){ int tmp=a; a=b; b=tmp; System.out.println("swap方法里,a的值是"+a+";b的值是"+b); //a=6,b=9 } }
前
public class TestTransfer{ public static void main(String[] args){ DataSwap ds=new DataSwap(); ds.a=6; ds.b=9; swap(ds); System.out.println("交換結(jié)束后,ds.a的值是"+ds.a+";ds.b的值是"+ds.b); //a=9,b=6 } public static void swap(DataSwap ds){ int tmp=ds.a; ds.a=ds.b; ds.b=tmp; System.out.println("swap方法里,ds.a的值是"+ds.a+";ds.b的值是"+ds.b); //a=9,b=6 } } class DataSwap{ public int a; public int b; }
以上所述是小編給大家介紹的JAVA內(nèi)存分配與參數(shù)傳遞詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
SpringBoot利用隨機(jī)鹽值實(shí)現(xiàn)密碼的加密與驗(yàn)證
這篇文章主要為大家詳細(xì)介紹了SpringBoot如何利用隨機(jī)鹽值實(shí)現(xiàn)密碼的加密與驗(yàn)證,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考下2024-02-02Spring中BeanFactoryPostProcessors是如何執(zhí)行的
BeanFactoryPostProcessor是Spring容器提供的一個(gè)擴(kuò)展機(jī)制,它允許開發(fā)者在Bean的實(shí)例化和初始化之前對(duì)BeanDefinition進(jìn)行修改和處理,這篇文章主要介紹了你知道Spring中BeanFactoryPostProcessors是如何執(zhí)行的嗎,需要的朋友可以參考下2023-11-11Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(59)
下面小編就為大家?guī)?lái)一篇Java基礎(chǔ)的幾道練習(xí)題(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,希望可以幫到你2021-08-08java報(bào)錯(cuò):“錯(cuò)誤:編碼GBK?的不可映射字符”解決辦法
當(dāng)Java源代碼中包含中文字符時(shí),我們?cè)谟胘avac編譯時(shí)會(huì)出現(xiàn)“錯(cuò)誤:編碼GBK的不可映射字符”,這篇文章主要給大家介紹了關(guān)于java報(bào)錯(cuò):“錯(cuò)誤:編碼GBK?的不可映射字符”的解決辦法,需要的朋友可以參考下2024-08-08Jaxb2實(shí)現(xiàn)JavaBean與xml互轉(zhuǎn)的方法詳解
這篇文章主要介紹了Jaxb2實(shí)現(xiàn)JavaBean與xml互轉(zhuǎn)的方法,簡(jiǎn)單介紹了JAXB的概念、功能及實(shí)現(xiàn)JavaBean與xml互轉(zhuǎn)的具體操作技巧,需要的朋友可以參考下2017-04-04