当前位置:网站首页>String & heap & method area
String & heap & method area
2022-06-28 11:02:00 【Hello_ xzy_ Word】
character string & Pile up & Method area
1. Problem introduction
package com.learn.java;
/** * @author xzy * @date 2020-09-17 22:33 * explain : character string & Pile up & Method area */
public class Main {
public static String s = "HELLO WORLD!";
public static void main(String[] args) {
String s1 = "HELLO WORLD!";
String s2 = "HELLO WORLD!";
String s3 = new String("HELLO WORLD!");
System.out.println(s1 == s); // true
System.out.println(s2 == s); // true
System.out.println(s1 == s2);// true
System.out.println(s3 == s); // false
System.out.println(s3 == s1);// false
System.out.println(s3 == s2);// false
}
}
2. Problem analysis

2.1 character string & Method area
class There is a piece in the file called “ Constant pool ” Region , A constant pool can be thought of as class A repository of documents , There are two main types of constants in the constant pool :
- Literal : character string 、final Constant ……
- Symbol reference : class / Fully qualified name of the interface 、 Field / Method name 、 Field / Method descriptor
In the method area, there is a block called “ Runtime constant pool ” Region , When a class is loaded into java Memory space of virtual machine ,class The contents of the file constant pool are loaded into the runtime constant pool .

Use javap -v Main.class Command to view the bytecode generated by the compiled program :

2.2 character string & Pile up
Pile up yes java The largest chunk of memory managed by a virtual machine , The only function of this memory area is to store Object instances And an array .
2.3 summary

s、s1、s2 The value in the pointing method area is “Hello WORLD!” Of String example ( Class is created when it is loaded );s3 Point to a heap with a value of “Hello WORLD!” Of String example ( Program runtime creates ).
边栏推荐
- vsftpd服务的部署及优化
- AQS understanding
- 拼接String集合中的字符串_基于Stream
- GCC introduction
- An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
- 元宇宙系统的发展与原理介绍
- Redis数据库
- Graduation season, some suggestions for you who are new to the society
- [Agora] get an Agora_ Example usage of refptr object
- 科研丨Web of Science检索技巧
猜你喜欢

【实操】Appium Settings app is not running after 5000ms

树莓派无需显示屏的VNC Viewer方式的远程连接

JS基础8

Katalon全局变量在TestObject引用

Yann LeCun新论文:构建自动智能体之路

Move command

Metersphere实现UI自动化元素不可点击(部分遮挡)

Remote connection of raspberry pie in VNC viewer mode without display

Katalon framework tests web (XX) custom keywords and upload pop-up operations

科研丨Web of Science检索技巧
随机推荐
Making and using of static library
[QT] connect syntax reference implementation
Word、PDF、TXT文件实现全文内容检索需要用什么方法?
Basic 02: variable, remember the mobile number of the object
JS基础5
Mongo数据库
Mongo database
vsftpd服务的部署及优化
JS基础6
Convert the file URL in the browser to a file stream
Hystrix deployment
How to distinguish and define DQL, DML, DDL and DCL in SQL
Yann LeCun新论文:构建自动智能体之路
MySQL (I)
Katalon global variable is referenced in testobject
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
DlhSoft Kanban Library for WPF
Graduation season, some suggestions for you who are new to the society
[practice] appium settings app is not running after 5000ms
DataEase安装升级