当前位置:网站首页>In-depth analysis of the initialization of member variables and local variables
In-depth analysis of the initialization of member variables and local variables
2022-08-02 06:58:00 【work hard and work hard c.】
1. Member variables
Member variables can be initialized without explicit initialization, because the virtual machine assigns a default value to it.
Because the member variables are part of the instance object, and all the instance objects are allocated in the heap memory, when the storage space is allocated in the virtual machine, the member variables of the memory space of the instance object are all allocated.Default initialization, so member variables have value even if you don't explicitly initialize them (the default value for primitive data types is 0, and the default value for reference data types is Null).
2. Local variables
Local variables must be initialized, otherwise they cannot be used.
First of all, local variables are located in the method, and each method is placed in the stack of the runtime data area during the execution of the JVM, and each stack stores the local variable table, operand stack, method exit, dynamic links, etc.Because the memory space required by the local variable table is fixedly allocated during compilation, before the method is called (that is, before the method is pushed onto the stack), it is necessary to determine how much variable space the method stack needs to allocate.It will not change the size of the local variable table, so it means that local variables must be initialized when they are created to determine the size of the allocated memory.
边栏推荐
猜你喜欢

Ant three sides: MQ message loss, duplication, backlog problem, what are the solutions?

DNS的解析流程

How the Internet of Things is changing the efficiency of city operations

Tips for programmers to write PPT

MySQL高级学习笔记

Important concepts of target detection - IOU, receptive field, hole convolution, mAP

MarkDown公式指导手册

BGP+MPLS综合实验

Leading the demand and justifying the HR value - the successful launch of the "Human Resource Leading Model HRLM"

MySQL Advanced Statements (1)
随机推荐
Nacos数据库配置
MySQL high-level statements (1)
pl/sql之神奇的嵌套与变量生命周期
Technology empowers Lhasa's "lungs", Huawei helps Lalu Wetland Smart Management to protect lucid waters and lush mountains
Nacos客户端启动出现9848端口错误分析(非版本升级问题)
zabbix email alarm and WeChat alarm
pytorch basic operations: classification tasks using neural networks
MySQL高级语句(一)
leetcode-338.比特位计数
MySQL classic 50 practice questions and the most detailed analysis of the whole network
MySQL Advanced Study Notes
MySQL 23道经典面试吊打面试官
selenium + robotframework的运行原理
love
人工神经网络
Ant three sides: MQ message loss, duplication, backlog problem, what are the solutions?
MySQL高级SQL语句
[Cartoon] 2021 full score programmer behavior comparison table (latest version)
MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
Common functions of pytorch