由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - java 的内存分布?
相关主题
Java练习题 3菜鸟问个简单的问题
Java练习题 9leetcode请教: time complexy
Java StringBuilder myth debunkedJava 问题
why doesn't replaceAll work?Java大侠们:Hashtable help please!
一道 JAVA Stack vs Heap 题expression in unicode
初级问题[转载] Java 1.5 Generic 问题
出个简单题,看你Java APi熟悉到什么程度TIJ上写错了?
Integer in heap问一个Java题
相关话题的讨论汇总
话题: string话题: abc话题: str1话题: str2话题: integer
进入Java版参与讨论
1 (共1页)
x***i
发帖数: 585
1
class被load到memory里。所以有一块是code segment
stack 和 heap 分别是低到高,高到低 分享以大块。
请问 string 字符串 常量 会放在哪里?
String str1 = "abcd";
String str2 = new String("abcd");
按我的理解str1 是放在一块特殊的data segment。
而str2 是放在heap里面,不知这样是否理解准确?
g**e
发帖数: 6127
2
string literal is saved in perm generation.
str2 is in heap like any regular class until str2.intern() is called.

【在 x***i 的大作中提到】
: class被load到memory里。所以有一块是code segment
: stack 和 heap 分别是低到高,高到低 分享以大块。
: 请问 string 字符串 常量 会放在哪里?
: String str1 = "abcd";
: String str2 = new String("abcd");
: 按我的理解str1 是放在一块特殊的data segment。
: 而str2 是放在heap里面,不知这样是否理解准确?

x***i
发帖数: 585
3
那static变量是不是也在perm generation里?
g**e
发帖数: 6127
4
yes

【在 x***i 的大作中提到】
: 那static变量是不是也在perm generation里?
x***i
发帖数: 585
5
k******p
发帖数: 21
6
str1: string pool at perm
str2: heap
str1 != str2

【在 x***i 的大作中提到】
: class被load到memory里。所以有一块是code segment
: stack 和 heap 分别是低到高,高到低 分享以大块。
: 请问 string 字符串 常量 会放在哪里?
: String str1 = "abcd";
: String str2 = new String("abcd");
: 按我的理解str1 是放在一块特殊的data segment。
: 而str2 是放在heap里面,不知这样是否理解准确?

m*****k
发帖数: 731
7
was asked this question:
String a = "abc";
String b = "ab";
how many strings are created, the answer from the interviewer is only 1 "abc
" is created, can u guys confirm?
g*****g
发帖数: 34805
8
He's wrong.

abc

【在 m*****k 的大作中提到】
: was asked this question:
: String a = "abc";
: String b = "ab";
: how many strings are created, the answer from the interviewer is only 1 "abc
: " is created, can u guys confirm?

s******e
发帖数: 493
9
I think it should be like this:
two string objects in heap (str1 and str 2).
one string literal in string pool (I do not think that spec ahs ever stated
it must be in perm gen, but highly possible. And for hotspot, i think it is)
.
g***s
发帖数: 3811
10
i think the question was:
String a = "abc";
String b = "abc";
how many strings are created, the answer from the interviewer is only 1 "
abc" is created.

abc

【在 m*****k 的大作中提到】
: was asked this question:
: String a = "abc";
: String b = "ab";
: how many strings are created, the answer from the interviewer is only 1 "abc
: " is created, can u guys confirm?

相关主题
初级问题菜鸟问个简单的问题
出个简单题,看你Java APi熟悉到什么程度leetcode请教: time complexy
Integer in heapJava 问题
进入Java版参与讨论
r*****l
发帖数: 2859
11
String b = "ab", not "abc".

【在 g***s 的大作中提到】
: i think the question was:
: String a = "abc";
: String b = "abc";
: how many strings are created, the answer from the interviewer is only 1 "
: abc" is created.
:
: abc

g***s
发帖数: 3811
12
Either madmonk remembered wrong, or the interviewer gave a wrong question.
I think the orignial question should be b="abc". Intervewer wanted to know
if the intervewee knows the "abc" is generated in perm.

【在 r*****l 的大作中提到】
: String b = "ab", not "abc".
g***s
发帖数: 3811
13
Let's come out another interview question:
boolean f(int x){
Integer a = x;
Integer b = x;
return a==b;
}
1. f(1) should return true or false?
2. f(1000) should return true or false?

【在 g***s 的大作中提到】
: Either madmonk remembered wrong, or the interviewer gave a wrong question.
: I think the orignial question should be b="abc". Intervewer wanted to know
: if the intervewee knows the "abc" is generated in perm.

g*****g
发帖数: 34805
14
f(1) should be true, f(1000) not so sure, I know if
the number is big enough, it will be false.
Sync on Integer may lock the system in unexpected way,
that's all it's about.

【在 g***s 的大作中提到】
: Let's come out another interview question:
: boolean f(int x){
: Integer a = x;
: Integer b = x;
: return a==b;
: }
: 1. f(1) should return true or false?
: 2. f(1000) should return true or false?

g***s
发帖数: 3811
15
for -128 to 127(or bool true/false), when autobox, JVM will reuse the same
object, just like pick a object from a pool.

【在 g*****g 的大作中提到】
: f(1) should be true, f(1000) not so sure, I know if
: the number is big enough, it will be false.
: Sync on Integer may lock the system in unexpected way,
: that's all it's about.

g**e
发帖数: 6127
16
还好这个我看过,不然又挂了

【在 g***s 的大作中提到】
: Let's come out another interview question:
: boolean f(int x){
: Integer a = x;
: Integer b = x;
: return a==b;
: }
: 1. f(1) should return true or false?
: 2. f(1000) should return true or false?

q*****9
发帖数: 85
17
re

【在 g***s 的大作中提到】
: i think the question was:
: String a = "abc";
: String b = "abc";
: how many strings are created, the answer from the interviewer is only 1 "
: abc" is created.
:
: abc

1 (共1页)
进入Java版参与讨论
相关主题
问一个Java题一道 JAVA Stack vs Heap 题
问个hashtable实现问题初级问题
how to read registry key value using java (64-bit system)出个简单题,看你Java APi熟悉到什么程度
一个简单的关于java Map的问题Integer in heap
Java练习题 3菜鸟问个简单的问题
Java练习题 9leetcode请教: time complexy
Java StringBuilder myth debunkedJava 问题
why doesn't replaceAll work?Java大侠们:Hashtable help please!
相关话题的讨论汇总
话题: string话题: abc话题: str1话题: str2话题: integer